Ownership is now managed.

dev
Philippe PITTOLI 2024-04-27 23:10:01 +02:00
parent 8cafca13be
commit a188d28f1d
2 changed files with 71 additions and 4 deletions

View File

@ -9,7 +9,7 @@ class DNSManager::Request
user = dnsmanagerd.get_logged_user event
return Response::ErrorUserNotLogged.new unless user
Response::Error.new "Not implemented."
dnsmanagerd.storage.ask_share_token user.uid, @domain
end
end
DNSManager.requests << AskShareToken
@ -24,7 +24,7 @@ class DNSManager::Request
user = dnsmanagerd.get_logged_user event
return Response::ErrorUserNotLogged.new unless user
Response::Error.new "Not implemented."
dnsmanagerd.storage.ask_transfer_token user.uid, @domain
end
end
DNSManager.requests << AskTransferToken
@ -39,7 +39,7 @@ class DNSManager::Request
user = dnsmanagerd.get_logged_user event
return Response::ErrorUserNotLogged.new unless user
Response::Error.new "Not implemented."
dnsmanagerd.storage.ask_unshare_domain user.uid, @domain
end
end
DNSManager.requests << AskUnShareDomain
@ -54,7 +54,7 @@ class DNSManager::Request
user = dnsmanagerd.get_logged_user event
return Response::ErrorUserNotLogged.new unless user
Response::Error.new "Not implemented."
dnsmanagerd.storage.gain_ownership user.uid, @uuid
end
end
DNSManager.requests << GainOwnership

View File

@ -155,6 +155,73 @@ class DNSManager::Storage
Response::DomainAdded.new domain
end
def ask_share_token(user_id : UserDataID, domain_name : String)
user_must_exist! user_id
user_should_own! user_id, domain_name
domain = @domains_by_name.get domain_name
if domain.share_key.nil?
domain.share_key = UUID.random.to_s
@domains_by_name.update_or_create domain_name, domain
Response::DomainChanged.new domain
else
Response::Error.new "The domain already have a share key."
end
end
def ask_transfer_token(user_id : UserDataID, domain_name : String)
user_must_exist! user_id
user_should_own! user_id, domain_name
domain = @domains_by_name.get domain_name
if domain.transfer_key.nil?
domain.transfer_key = UUID.random.to_s
@domains_by_name.update_or_create domain_name, domain
Response::DomainChanged.new domain
else
Response::Error.new "The domain already have a transfer key."
end
end
# Check the domain owners.
# In case there's only the requesting user, allow him to gain full control.
def ask_unshare_domain(user_id : UserDataID, domain_name : String)
user_must_exist! user_id
user_should_own! user_id, domain_name
domain = @domains_by_name.get domain_name
if domain.owners.size == 1 && domain.owners[0] == user_id
domain.share_key = nil
@domains_by_name.update_or_create domain_name, domain
Response::DomainChanged.new domain
else
Response::Error.new "You are't the only owner."
end
end
def gain_ownership(user_id : UserDataID, uuid : String)
user_must_exist! user_id
if domain = @domains_by_share_key.get uuid
if domain.owners.includes? user_id
return Response::Error.new "You already own this domain."
end
domain.owners << user_id
@domains_by_name.update_or_create domain.name, domain
Response::DomainChanged.new domain
elsif domain = @domains_by_transfer_key.get uuid
if domain.owners.includes? user_id
return Response::Error.new "You already own this domain."
end
domain.transfer_key = nil
domain.owners = [user_id]
@domains_by_name.update_or_create domain.name, domain
Response::DomainChanged.new domain
else
Response::Error.new "There is no key with this UUID."
end
end
def add_or_update_zone(user_id : UserDataID, zone : Zone) : IPC::JSON
user_must_exist! user_id