From a888551bbc3ab3f7b25ada0a57103ea054f5dec4 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Sat, 27 Apr 2024 18:30:49 +0200 Subject: [PATCH] Compatible with the webclient again. Full audit REQUIRED. --- src/requests/zone.cr | 3 ++- src/responses/zone.cr | 4 +--- src/storage.cr | 10 ++++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/requests/zone.cr b/src/requests/zone.cr index 004898e..004b7db 100644 --- a/src/requests/zone.cr +++ b/src/requests/zone.cr @@ -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 diff --git a/src/responses/zone.cr b/src/responses/zone.cr index 02b2d19..0caaec5 100644 --- a/src/responses/zone.cr +++ b/src/responses/zone.cr @@ -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 - diff --git a/src/storage.cr b/src/storage.cr index 97b46d1..913a2b4 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -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