Skip to content

Commit 642211d

Browse files
authored
Add role to newly created user if provided (#470)
1 parent 30e7f96 commit 642211d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

server/src/handlers/http/rbac.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ pub async fn list_users() -> impl Responder {
4545
// Creates a new user by username if it does not exists
4646
// Otherwise make a call to reset password
4747
// returns password generated for this user
48-
pub async fn put_user(username: web::Path<String>) -> Result<impl Responder, RBACError> {
48+
pub async fn put_user(
49+
username: web::Path<String>,
50+
body: Option<web::Json<serde_json::Value>>,
51+
) -> Result<impl Responder, RBACError> {
4952
let username = username.into_inner();
5053
validator::user_name(&username)?;
5154
if username == CONFIG.parseable.username {
@@ -60,13 +63,16 @@ pub async fn put_user(username: web::Path<String>) -> Result<impl Responder, RBA
6063
// should be unreachable given state is always consistent
6164
return Err(RBACError::UserExists);
6265
}
63-
64-
let (user, password) = User::create_new(username);
66+
let (user, password) = User::create_new(username.clone());
6567
metadata.users.push(user.clone());
6668
put_metadata(&metadata).await?;
6769
// set this user to user map
6870
Users.put_user(user);
6971

72+
if let Some(body) = body {
73+
put_role(web::Path::<String>::from(username), body).await?;
74+
}
75+
7076
Ok(password)
7177
}
7278
}

0 commit comments

Comments
 (0)