Compatible with the webclient again. Full audit REQUIRED.

This commit is contained in:
Karchnu 2024-04-27 18:30:49 +02:00
parent 40fcc9c66e
commit a888551bbc
3 changed files with 9 additions and 8 deletions

View File

@ -69,7 +69,8 @@ class DNSManager::Request
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
user = dnsmanagerd.get_logged_user event
return Response::ErrorUserNotLogged.new unless user
Response::DomainList.new dnsmanagerd.storage.user_domains user.uid
user_domain_names = dnsmanagerd.storage.user_domains(user.uid).map &.name
Response::DomainList.new user_domain_names
end
end
DNSManager.requests << UserDomains

View File

@ -1,4 +1,3 @@
class DNSManager::Response
IPC::JSON.message DomainDeleted, 9 do
property domain : String
@ -52,7 +51,7 @@ class DNSManager::Response
IPC::JSON.message Logged, 16 do
property admin : Bool
property accepted_domains : Array(String)
property my_domains : Array(String)
property my_domains : Array(DNSManager::Storage::Domain)
def initialize(@admin, @accepted_domains, @my_domains)
end
end
@ -119,4 +118,3 @@ class DNSManager::Response
end
DNSManager.responses << OrphanDomainList
end

View File

@ -145,7 +145,9 @@ class DNSManager::Storage
#
# Add the new domain.
@domains << Domain.new domain, owners: [user_id]
the_new_domain = Domain.new domain
the_new_domain.owners = [user_id]
@domains << the_new_domain
# Add the new zone in the database.
zones_by_domain.update_or_create domain, default_zone
@ -324,9 +326,9 @@ class DNSManager::Storage
Response::Success.new
end
def user_domains(user_id : UserDataID) : Array(String)
def user_domains(user_id : UserDataID) : Array(Domain)
user_must_exist! user_id
domains_by_owners.get(user_id.to_s).map &.name
domains_by_owners.get(user_id.to_s)
end
# TODO: is the user known from authd?
@ -346,7 +348,7 @@ class DNSManager::Storage
# Owning a domain means to be in the owners' list of the domain.
# TODO: accept admin users to override this test.
def user_should_own!(user_id : UserDataID, domain : String)
def user_should_own!(user_id : UserDataID, domain : String) : Nil
d = domains_by_name.get domain
unless d.owners.includes? user_id
raise NoOwnershipException.new