@@ -265,22 +265,22 @@ pub(crate) async fn get_group(
265265 _admin : AdminRole ,
266266 _session : SessionInfo ,
267267 State ( appstate) : State < AppState > ,
268- Path ( name ) : Path < String > ,
268+ Path ( id ) : Path < Id > ,
269269) -> ApiResult {
270- debug ! ( "Retrieving group {name }" ) ;
271- if let Some ( group) = Group :: find_by_name ( & appstate. pool , & name ) . await ? {
270+ debug ! ( "Retrieving group {id }" ) ;
271+ if let Some ( group) = Group :: find_by_id ( & appstate. pool , id ) . await ? {
272272 let members = group. member_usernames ( & appstate. pool ) . await ?;
273273 let vpn_locations = group. allowed_vpn_locations ( & appstate. pool ) . await ?;
274274 let is_admin = group
275275 . has_permission ( & appstate. pool , Permission :: IsAdmin )
276276 . await ?;
277- info ! ( "Retrieved group {name }" ) ;
277+ info ! ( "Retrieved group {id }" ) ;
278278 Ok ( ApiResponse :: json (
279- GroupInfo :: new ( group. id , name, members, vpn_locations, is_admin) ,
279+ GroupInfo :: new ( group. id , group . name , members, vpn_locations, is_admin) ,
280280 StatusCode :: OK ,
281281 ) )
282282 } else {
283- let msg = format ! ( "Group {name } not found" ) ;
283+ let msg = format ! ( "Group {id } not found" ) ;
284284 error ! ( msg) ;
285285 Err ( WebError :: ObjectNotFound ( msg) )
286286 }
@@ -406,12 +406,12 @@ pub(crate) async fn modify_group(
406406 _role : AdminRole ,
407407 State ( appstate) : State < AppState > ,
408408 context : ApiRequestContext ,
409- Path ( name ) : Path < String > ,
409+ Path ( id ) : Path < Id > ,
410410 Json ( group_info) : Json < EditGroupInfo > ,
411411) -> ApiResult {
412- debug ! ( "Modifying group {}" , group_info . name ) ;
413- let Some ( mut group) = Group :: find_by_name ( & appstate. pool , & name ) . await ? else {
414- let msg = format ! ( "Group {name } not found" ) ;
412+ debug ! ( "Modifying group {id}" ) ;
413+ let Some ( mut group) = Group :: find_by_id ( & appstate. pool , id ) . await ? else {
414+ let msg = format ! ( "Group {id } not found" ) ;
415415 error ! ( msg) ;
416416 return Err ( WebError :: ObjectNotFound ( msg) ) ;
417417 } ;
@@ -437,7 +437,7 @@ pub(crate) async fn modify_group(
437437 if admin_groups_count == 1 {
438438 error ! (
439439 "Can't remove admin permissions from the last admin group: {}" ,
440- name
440+ group . name
441441 ) ;
442442 return Ok ( ApiResponse :: with_status ( StatusCode :: BAD_REQUEST ) ) ;
443443 }
@@ -490,8 +490,8 @@ pub(crate) async fn modify_group(
490490
491491 ldap_add_users_to_groups ( add_to_ldap_groups, & appstate. pool ) . await ;
492492 ldap_remove_users_from_groups ( remove_from_ldap_groups, & appstate. pool ) . await ;
493- if name != group_info . name {
494- ldap_modify_group ( & name, & group, & appstate. pool ) . await ;
493+ if before . name != group . name {
494+ ldap_modify_group ( & before . name , & group, & appstate. pool ) . await ;
495495 }
496496
497497 let affected_users = members
@@ -562,35 +562,38 @@ pub(crate) async fn delete_group(
562562 session : SessionInfo ,
563563 State ( appstate) : State < AppState > ,
564564 context : ApiRequestContext ,
565- Path ( name ) : Path < String > ,
565+ Path ( id ) : Path < Id > ,
566566) -> ApiResult {
567- debug ! ( "User {} deletes group {name }" , & session. user. username) ;
568- if let Some ( group) = Group :: find_by_name ( & appstate. pool , & name ) . await ? {
567+ debug ! ( "User {} deletes group {id }" , & session. user. username) ;
568+ if let Some ( group) = Group :: find_by_id ( & appstate. pool , id ) . await ? {
569569 // Prevent removing the last admin group
570570 if group. is_admin {
571571 let admin_group_count = Group :: find_by_permission ( & appstate. pool , Permission :: IsAdmin )
572572 . await ?
573573 . len ( ) ;
574574 if admin_group_count == 1 {
575- error ! ( "Cannot delete the last admin group: {name}" ) ;
575+ error ! ( "Cannot delete the last admin group: {}" , group . name ) ;
576576 return Ok ( ApiResponse :: with_status ( StatusCode :: BAD_REQUEST ) ) ;
577577 }
578578 }
579579 group. clone ( ) . delete ( & appstate. pool ) . await ?;
580- ldap_delete_group ( & name, & appstate. pool ) . await ;
580+ ldap_delete_group ( & group . name , & appstate. pool ) . await ;
581581
582582 // sync allowed devices for all locations
583583 let mut conn = appstate. pool . acquire ( ) . await ?;
584584 sync_all_networks ( & mut conn, & appstate. wireguard_tx ) . await ?;
585585
586- info ! ( "User {} deleted group {name}" , & session. user. username) ;
586+ info ! (
587+ "User {} deleted group {}" ,
588+ & session. user. username, group. name
589+ ) ;
587590 appstate. emit_event ( ApiEvent {
588591 context,
589592 event : Box :: new ( ApiEventType :: GroupRemoved { group } ) ,
590593 } ) ?;
591594 Ok ( ApiResponse :: default ( ) )
592595 } else {
593- let msg = format ! ( "Failed to find group {name }" ) ;
596+ let msg = format ! ( "Failed to find group {id }" ) ;
594597 error ! ( msg) ;
595598 Err ( WebError :: ObjectNotFound ( msg) )
596599 }
@@ -625,10 +628,10 @@ pub(crate) async fn add_group_member(
625628 _role : AdminRole ,
626629 State ( appstate) : State < AppState > ,
627630 context : ApiRequestContext ,
628- Path ( name ) : Path < String > ,
631+ Path ( id ) : Path < Id > ,
629632 Json ( data) : Json < Username > ,
630633) -> ApiResult {
631- if let Some ( group) = Group :: find_by_name ( & appstate. pool , & name ) . await ? {
634+ if let Some ( group) = Group :: find_by_id ( & appstate. pool , id ) . await ? {
632635 if let Some ( mut user) = User :: find_by_username ( & appstate. pool , & data. username ) . await ? {
633636 debug ! ( "Adding user: {} to group: {}" , user. username, group. name) ;
634637 user. add_to_group ( & appstate. pool , & group) . await ?;
@@ -650,7 +653,7 @@ pub(crate) async fn add_group_member(
650653 ) ) )
651654 }
652655 } else {
653- let msg = format ! ( "Group {name } not found" ) ;
656+ let msg = format ! ( "Group {id } not found" ) ;
654657 error ! ( msg) ;
655658 Err ( WebError :: ObjectNotFound ( msg) )
656659 }
@@ -685,9 +688,9 @@ pub(crate) async fn remove_group_member(
685688 _role : AdminRole ,
686689 State ( appstate) : State < AppState > ,
687690 context : ApiRequestContext ,
688- Path ( ( name , username) ) : Path < ( String , String ) > ,
691+ Path ( ( id , username) ) : Path < ( i64 , String ) > ,
689692) -> ApiResult {
690- if let Some ( group) = Group :: find_by_name ( & appstate. pool , & name ) . await ? {
693+ if let Some ( group) = Group :: find_by_id ( & appstate. pool , id ) . await ? {
691694 if let Some ( user) = User :: find_by_username ( & appstate. pool , & username) . await ? {
692695 debug ! (
693696 "Removing user: {} from group: {}" ,
@@ -711,7 +714,7 @@ pub(crate) async fn remove_group_member(
711714 Err ( WebError :: ObjectNotFound ( msg) )
712715 }
713716 } else {
714- error ! ( "Group {name } not found" ) ;
715- Err ( WebError :: ObjectNotFound ( format ! ( "Group {name } not found" , ) ) )
717+ error ! ( "Group {id } not found" ) ;
718+ Err ( WebError :: ObjectNotFound ( format ! ( "Group {id } not found" ) ) )
716719 }
717720}
0 commit comments