Permissions: code simplification.

master
Philippe Pittoli 2023-06-11 21:27:52 +02:00
parent 52ee731921
commit 5f3f208798
1 changed files with 11 additions and 16 deletions

View File

@ -16,20 +16,16 @@ class AuthD::Request
user = authd.user? @user user = authd.user? @user
return Response::Error.new "no such user" if user.nil? return Response::Error.new "no such user" if user.nil?
service = @service service_permissions = user.permissions[@service]?
service_permissions = user.permissions[service]? resource_permissions = if service_permissions.nil?
User::PermissionLevel::None
if service_permissions.nil? elsif p = service_permissions[@resource]?
return Response::PermissionCheck.new service, @resource, user.uid, User::PermissionLevel::None p
else
User::PermissionLevel::None
end end
resource_permissions = service_permissions[@resource]? return Response::PermissionCheck.new @service, @resource, user.uid, resource_permissions
if resource_permissions.nil?
return Response::PermissionCheck.new service, @resource, user.uid, User::PermissionLevel::None
end
return Response::PermissionCheck.new service, @resource, user.uid, resource_permissions
end end
end end
AuthD.requests << CheckPermission AuthD.requests << CheckPermission
@ -52,12 +48,11 @@ class AuthD::Request
user = authd.user? @user user = authd.user? @user
return Response::Error.new "no such user" if user.nil? return Response::Error.new "no such user" if user.nil?
service = @service service_permissions = user.permissions[@service]?
service_permissions = user.permissions[service]?
if service_permissions.nil? if service_permissions.nil?
service_permissions = Hash(String, User::PermissionLevel).new service_permissions = Hash(String, User::PermissionLevel).new
user.permissions[service] = service_permissions user.permissions[@service] = service_permissions
end end
if @permission.none? if @permission.none?
@ -68,7 +63,7 @@ class AuthD::Request
authd.users_per_uid.update user.uid.to_s, user authd.users_per_uid.update user.uid.to_s, user
Response::PermissionSet.new user.uid, service, @resource, @permission Response::PermissionSet.new user.uid, @service, @resource, @permission
end end
end end
AuthD.requests << SetPermission AuthD.requests << SetPermission