@@ -32,8 +32,8 @@ use crate::{
32
32
} ,
33
33
rbac:: {
34
34
Users ,
35
- map:: { roles, write_user_groups} ,
36
- user,
35
+ map:: { roles, users , write_user_groups} ,
36
+ user:: { self , UserType } ,
37
37
} ,
38
38
validator,
39
39
} ;
@@ -74,7 +74,7 @@ pub async fn post_user(
74
74
return Err ( RBACError :: RolesDoNotExist ( non_existant_roles) ) ;
75
75
}
76
76
}
77
- let _ = UPDATE_LOCK . lock ( ) . await ;
77
+ let _guard = UPDATE_LOCK . lock ( ) . await ;
78
78
if Users . contains ( & username)
79
79
|| metadata
80
80
. users
@@ -106,7 +106,7 @@ pub async fn post_user(
106
106
// Handler for DELETE /api/v1/user/{username}
107
107
pub async fn delete_user ( username : web:: Path < String > ) -> Result < impl Responder , RBACError > {
108
108
let username = username. into_inner ( ) ;
109
- let _ = UPDATE_LOCK . lock ( ) . await ;
109
+ let _guard = UPDATE_LOCK . lock ( ) . await ;
110
110
// fail this request if the user does not exists
111
111
if !Users . contains ( & username) {
112
112
return Err ( RBACError :: UserDoesNotExist ) ;
@@ -120,11 +120,21 @@ pub async fn delete_user(username: web::Path<String>) -> Result<impl Responder,
120
120
let mut groups_to_update = Vec :: new ( ) ;
121
121
for user_group in user_groups {
122
122
if let Some ( ug) = write_user_groups ( ) . get_mut ( & user_group) {
123
- ug. remove_users_by_user_ids ( HashSet :: from_iter ( [ username. clone ( ) ] ) ) ?;
124
- groups_to_update. push ( ug. clone ( ) ) ;
123
+ // Look up the user by display name to get the correct userid
124
+ if let Some ( user) = users ( ) . get ( & username) {
125
+ let user_id = match & user. ty {
126
+ UserType :: Native ( basic) => basic. username . clone ( ) ,
127
+ UserType :: OAuth ( oauth) => oauth. userid . clone ( ) ,
128
+ } ;
129
+ ug. remove_users_by_user_ids ( HashSet :: from_iter ( [ user_id] ) ) ?;
130
+ groups_to_update. push ( ug. clone ( ) ) ;
131
+ } else {
132
+ // User not found, skip or log as needed
133
+ continue ;
134
+ }
125
135
} else {
126
136
continue ;
127
- } ;
137
+ }
128
138
}
129
139
130
140
// For each updated group, replace in place if found; otherwise push
@@ -134,7 +144,7 @@ pub async fn delete_user(username: web::Path<String>) -> Result<impl Responder,
134
144
. iter_mut ( )
135
145
. find ( |ug| ug. name == updated_group. name )
136
146
{
137
- * existing = updated_group . clone ( ) ;
147
+ existing. clone_from ( updated_group ) ;
138
148
} else {
139
149
metadata. user_groups . push ( updated_group. clone ( ) ) ;
140
150
}
@@ -262,7 +272,7 @@ pub async fn post_gen_password(username: web::Path<String>) -> Result<impl Respo
262
272
let mut new_hash = String :: default ( ) ;
263
273
let mut metadata = get_metadata ( ) . await ?;
264
274
265
- let _ = UPDATE_LOCK . lock ( ) . await ;
275
+ let _guard = UPDATE_LOCK . lock ( ) . await ;
266
276
let user:: PassCode { password, hash } = user:: Basic :: gen_new_password ( ) ;
267
277
new_password. clone_from ( & password) ;
268
278
new_hash. clone_from ( & hash) ;
0 commit comments