Skip to content

Commit 391d23a

Browse files
committed
fix: reserve default group user role
1 parent f263481 commit 391d23a

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

api/src/routes/groups.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,15 @@ pub async fn add_group_member(
627627
.collect::<ServerResult<_>>()?,
628628
_ => {
629629
let (_, auth_doc) = load_group(&state, group_id).await?;
630-
auth_doc
630+
let role_ids = auth_doc
631631
.roles
632632
.iter()
633633
.filter_map(|(role_id, role)| (role.name == "user").then_some(*role_id))
634-
.collect()
634+
.collect::<HashSet<_>>();
635+
if role_ids.len() != 1 {
636+
return Err(ServerError::BadRequest);
637+
}
638+
role_ids
635639
}
636640
};
637641
if role_ids.is_empty() {
@@ -767,7 +771,7 @@ pub async fn create_group_role(
767771
let realm_id = state.get_realm_id();
768772

769773
let name = request.name.trim().to_string();
770-
if name.is_empty() || name == "admin" {
774+
if name.is_empty() || matches!(name.as_str(), "admin" | "user") {
771775
return Err(ServerError::BadRequest);
772776
}
773777

0 commit comments

Comments
 (0)