Permissions: code simplification.

This commit is contained in:
Philippe Pittoli 2023-06-11 21:27:52 +02:00
parent 52ee731921
commit 5f3f208798

View File

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