File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,9 @@ pub async fn post_user(
67
67
let roles: Option < HashSet < String > > = body
68
68
. map ( |body| serde_json:: from_value ( body. into_inner ( ) ) )
69
69
. transpose ( ) ?;
70
-
70
+ if roles. is_none ( ) || roles. as_ref ( ) . unwrap ( ) . is_empty ( ) {
71
+ return Err ( RBACError :: RoleValidationError ) ;
72
+ }
71
73
validator:: user_name ( & username) ?;
72
74
let _ = UPDATE_LOCK . lock ( ) . await ;
73
75
if Users . contains ( & username) {
@@ -215,6 +217,8 @@ pub enum RBACError {
215
217
ObjectStorageError ( #[ from] ObjectStorageError ) ,
216
218
#[ error( "invalid Username: {0}" ) ]
217
219
ValidationError ( #[ from] UsernameValidationError ) ,
220
+ #[ error( "User cannot be created without a role" ) ]
221
+ RoleValidationError ,
218
222
}
219
223
220
224
impl actix_web:: ResponseError for RBACError {
@@ -225,6 +229,7 @@ impl actix_web::ResponseError for RBACError {
225
229
Self :: SerdeError ( _) => StatusCode :: BAD_REQUEST ,
226
230
Self :: ValidationError ( _) => StatusCode :: BAD_REQUEST ,
227
231
Self :: ObjectStorageError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
232
+ Self :: RoleValidationError => StatusCode :: BAD_REQUEST ,
228
233
}
229
234
}
230
235
You can’t perform that action at this time.
0 commit comments