Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion server/src/handlers/http/rbac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ pub async fn post_user(
let roles: Option<HashSet<String>> = body
.map(|body| serde_json::from_value(body.into_inner()))
.transpose()?;

if roles.is_none() || roles.as_ref().unwrap().is_empty() {
return Err(RBACError::RoleValidationError);
}
validator::user_name(&username)?;
let _ = UPDATE_LOCK.lock().await;
if Users.contains(&username) {
Expand Down Expand Up @@ -215,6 +217,8 @@ pub enum RBACError {
ObjectStorageError(#[from] ObjectStorageError),
#[error("invalid Username: {0}")]
ValidationError(#[from] UsernameValidationError),
#[error("User cannot be created without a role")]
RoleValidationError,
}

impl actix_web::ResponseError for RBACError {
Expand All @@ -225,6 +229,7 @@ impl actix_web::ResponseError for RBACError {
Self::SerdeError(_) => StatusCode::BAD_REQUEST,
Self::ValidationError(_) => StatusCode::BAD_REQUEST,
Self::ObjectStorageError(_) => StatusCode::INTERNAL_SERVER_ERROR,
Self::RoleValidationError => StatusCode::BAD_REQUEST,
}
}

Expand Down