Check if the user is admin with is_admin?
function in dnsmanagerd
.
This commit is contained in:
parent
4923fb34f9
commit
234259a9d0
@ -84,6 +84,11 @@ class DNSManager::Service < IPC
|
||||
@authd.decode_token token
|
||||
end
|
||||
|
||||
def is_admin?(uid : UInt32) : Bool
|
||||
perms = check_permissions uid, "*"
|
||||
(perms == AuthD::User::PermissionLevel::Admin)
|
||||
end
|
||||
|
||||
def check_permissions(uid : UInt32, resource : String) : AuthD::User::PermissionLevel
|
||||
response = @authd.check_permission uid, "dnsmanager", resource
|
||||
case response
|
||||
|
@ -21,9 +21,12 @@ class DNSManager::Request
|
||||
# Limit the number of domains in this message.
|
||||
# Pagination will be required beyond a hundred domains.
|
||||
user_domains = dnsmanagerd.storage.user_domains(user_id).[0..100]
|
||||
perms = dnsmanagerd.check_permissions user_id, "*"
|
||||
is_admin = dnsmanagerd.is_admin? user_id
|
||||
|
||||
Response::Logged.new (perms == AuthD::User::PermissionLevel::Admin), accepted_domains, user_domains
|
||||
Response::Logged.new is_admin, accepted_domains, user_domains
|
||||
when AuthD::Response::ErrorUserNotFound
|
||||
Baguette::Log.error "Trying to authenticate an unknown user."
|
||||
Response::ErrorInvalidToken.new
|
||||
else
|
||||
Response::ErrorInvalidToken.new
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user