@@ -11,11 +11,14 @@ use schemars::JsonSchema;
1111use serde:: { Deserialize , Serialize } ;
1212
1313use crate :: {
14- app:: models:: {
15- CollectionSettings , Entity , EntityCollectionSettings , Project , ProjectDisplaySettings ,
16- ResolvedCollectionSettings , UserRole ,
14+ PASSWORD_MIN_LENGTH ,
15+ app:: {
16+ models:: {
17+ CollectionSettings , Entity , EntityCollectionSettings , Project , ProjectDisplaySettings ,
18+ ResolvedCollectionSettings , UserRole ,
19+ } ,
20+ reports:: { Dimension , Metric } ,
1721 } ,
18- app:: reports:: { Dimension , Metric } ,
1922 utils:: validate:: can_access_project,
2023 web:: {
2124 RouterState ,
@@ -267,14 +270,18 @@ async fn update_user_password(
267270 app : State < RouterState > ,
268271 Path ( username) : Path < String > ,
269272 Auth ( session_user) : Auth ,
270- password : Json < UpdatePasswordRequest > ,
273+ params : Json < UpdatePasswordRequest > ,
271274) -> ApiResult < impl IntoApiResponse > {
272275 if session_user. role != UserRole :: Admin || username != session_user. username {
273276 http_bail ! ( StatusCode :: FORBIDDEN , "Forbidden" )
274277 }
275278
279+ if params. password . len ( ) < PASSWORD_MIN_LENGTH {
280+ http_bail ! ( StatusCode :: BAD_REQUEST , "password must be at least 8 characters long" ) ;
281+ }
282+
276283 app. users
277- . update_password ( & username, & password . password )
284+ . update_password ( & username, & params . password )
278285 . http_err ( "Failed to update password" , StatusCode :: INTERNAL_SERVER_ERROR ) ?;
279286
280287 Ok ( empty_response ( ) )
@@ -301,14 +308,18 @@ async fn remove_user(
301308async fn create_user (
302309 app : State < RouterState > ,
303310 Auth ( session_user) : Auth ,
304- user : Json < CreateUserRequest > ,
311+ params : Json < CreateUserRequest > ,
305312) -> ApiResult < impl IntoApiResponse > {
306313 if session_user. role != UserRole :: Admin {
307314 http_bail ! ( StatusCode :: FORBIDDEN , "Forbidden" )
308315 }
309316
317+ if params. password . len ( ) < PASSWORD_MIN_LENGTH {
318+ http_bail ! ( StatusCode :: BAD_REQUEST , "password must be at least 8 characters long" ) ;
319+ }
320+
310321 let app = app. app . clone ( ) ;
311- tokio:: task:: spawn_blocking ( move || app. users . create ( & user . username , & user . password , user . role , & [ ] ) )
322+ tokio:: task:: spawn_blocking ( move || app. users . create ( & params . username , & params . password , params . role , & [ ] ) )
312323 . await
313324 . http_err ( "Failed to create user" , StatusCode :: INTERNAL_SERVER_ERROR ) ?
314325 . http_err ( "Failed to create user" , StatusCode :: INTERNAL_SERVER_ERROR ) ?;
@@ -646,6 +657,7 @@ async fn entity_delete_handler(
646657 }
647658
648659 app. entities . delete ( & entity_id) . http_err ( "Failed to delete entity" , StatusCode :: INTERNAL_SERVER_ERROR ) ?;
660+ app. settings . reload ( ) . http_err ( "Failed to reload collection settings" , StatusCode :: INTERNAL_SERVER_ERROR ) ?;
649661
650662 Ok ( empty_response ( ) )
651663}
0 commit comments