Only delete the domain when the user is the last owner.
This commit is contained in:
parent
a188d28f1d
commit
1f69839333
@ -202,14 +202,14 @@ class DNSManager::Storage
|
||||
def gain_ownership(user_id : UserDataID, uuid : String)
|
||||
user_must_exist! user_id
|
||||
|
||||
if domain = @domains_by_share_key.get uuid
|
||||
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
|
||||
elsif domain = @domains_by_transfer_key.get? uuid
|
||||
if domain.owners.includes? user_id
|
||||
return Response::Error.new "You already own this domain."
|
||||
end
|
||||
@ -312,19 +312,29 @@ class DNSManager::Storage
|
||||
Response::RRDeleted.new rrid
|
||||
end
|
||||
|
||||
def delete_domain(user_id : UserDataID, domain : String) : IPC::JSON
|
||||
def delete_domain(user_id : UserDataID, domain_name : String) : IPC::JSON
|
||||
user_must_exist! user_id
|
||||
zone_must_exist! domain
|
||||
user_should_own! user_id, domain
|
||||
zone_must_exist! domain_name
|
||||
user_should_own! user_id, domain_name
|
||||
|
||||
# Remove this domain from the list of user's domains.
|
||||
domains_by_name.delete domain
|
||||
domain = @domains_by_name.get domain_name
|
||||
# The user isn't the only owner, just remove him from the list of owners.
|
||||
if domain.owners.size > 1
|
||||
domain.owners.select! { |o| o != user_id }
|
||||
@domains_by_name.update_or_create domain_name, domain
|
||||
|
||||
# Not really a domain deletion, but that'll do the trick.
|
||||
return Response::DomainDeleted.new domain_name
|
||||
end
|
||||
|
||||
# Remove this domain_name from the list of user's domains.
|
||||
domains_by_name.delete domain_name
|
||||
|
||||
# Remove the related zone and their registered tokens.
|
||||
zones_by_domain.delete domain
|
||||
tokens_by_domain.delete domain
|
||||
zones_by_domain.delete domain_name
|
||||
tokens_by_domain.delete domain_name
|
||||
|
||||
Response::DomainDeleted.new domain
|
||||
Response::DomainDeleted.new domain_name
|
||||
end
|
||||
|
||||
# Get all removed users from `authd`, list all their domains and remove their data from `dnsmanagerd`.
|
||||
|
Loading…
Reference in New Issue
Block a user