@@ -6,14 +6,16 @@ use aruna_core::structs::{
66 Actor , AuthContext , Group , GroupAuthorizationDocument , Permission , Role ,
77} ;
88use aruna_core:: types:: RoleId ;
9- use aruna_operations:: add_group_role:: { AddGroupRoleConfig , AddGroupRoleOperation } ;
9+ use aruna_operations:: add_group_role:: {
10+ AddGroupRoleConfig , AddGroupRoleError , AddGroupRoleOperation ,
11+ } ;
1012use aruna_operations:: add_user_to_group:: {
1113 AddUserToGroupError , AddUserToGroupInput , AddUserToGroupOperation ,
1214} ;
1315use aruna_operations:: check_permissions:: { CheckPermissionsConfig , CheckPermissionsOperation } ;
1416use aruna_operations:: create_group:: { CreateGroupConfig , CreateGroupOperation } ;
1517use aruna_operations:: driver:: drive;
16- use aruna_operations:: get_group:: { GetGroupConfig , GetGroupOperation } ;
18+ use aruna_operations:: get_group:: { GetGroupConfig , GetGroupError , GetGroupOperation } ;
1719use aruna_operations:: list_groups:: ListGroupOperation ;
1820use aruna_operations:: remove_group_role:: {
1921 RemoveGroupRoleConfig , RemoveGroupRoleError , RemoveGroupRoleOperation ,
@@ -269,7 +271,14 @@ async fn load_group(
269271 & state. get_ctx ( ) ,
270272 )
271273 . await
272- . map_err ( |err| ServerError :: InternalError ( err. to_string ( ) ) )
274+ . map_err ( map_get_group_error)
275+ }
276+
277+ fn map_get_group_error ( error : GetGroupError ) -> ServerError {
278+ match error {
279+ GetGroupError :: GroupNotFound | GetGroupError :: AuthDocNotFound => ServerError :: NotFound ,
280+ other => ServerError :: InternalError ( other. to_string ( ) ) ,
281+ }
273282}
274283
275284impl From < ( Group , GroupAuthorizationDocument ) > for CreateGroupResponse {
@@ -514,6 +523,17 @@ fn map_add_member_error(error: AddUserToGroupError) -> ServerError {
514523 }
515524}
516525
526+ fn map_add_role_error ( error : AddGroupRoleError ) -> ServerError {
527+ match error {
528+ AddGroupRoleError :: Unauthorized => ServerError :: Forbidden ,
529+ AddGroupRoleError :: GroupNotFound => ServerError :: NotFound ,
530+ AddGroupRoleError :: CheckPermissionsError (
531+ AuthorizationError :: GroupNotFound | AuthorizationError :: AuthDocNotFound ,
532+ ) => ServerError :: NotFound ,
533+ other => ServerError :: InternalError ( other. to_string ( ) ) ,
534+ }
535+ }
536+
517537fn map_remove_member_error ( error : RemoveUserFromGroupError ) -> ServerError {
518538 match error {
519539 RemoveUserFromGroupError :: Unauthorized => ServerError :: Forbidden ,
@@ -731,7 +751,8 @@ pub async fn leave_group(
731751 ( status = 201 , description = "Role created" , body = RoleResponse ) ,
732752 ( status = 400 , description = "Invalid request or foreign permission path" , body = ErrorResponse ) ,
733753 ( status = 401 , description = "Unauthorized" , body = ErrorResponse ) ,
734- ( status = 403 , description = "Forbidden" , body = ErrorResponse )
754+ ( status = 403 , description = "Forbidden" , body = ErrorResponse ) ,
755+ ( status = 404 , description = "Group not found" , body = ErrorResponse )
735756 ) ,
736757 security( ( "bearer_auth" = [ ] ) )
737758) ]
@@ -790,7 +811,7 @@ pub async fn create_group_role(
790811 & state. get_ctx ( ) ,
791812 )
792813 . await
793- . map_err ( |err| ServerError :: InternalError ( err . to_string ( ) ) ) ?;
814+ . map_err ( map_add_role_error ) ?;
794815
795816 let role = map_roles ( auth_doc)
796817 . into_iter ( )
0 commit comments