Skip to content

Commit d3227ef

Browse files
fix: add empty check before removing users from session
issue - when user is added to group, all existing users in the group get logged out the change fixes the issue by not removing users from session when users / roles in the modify / delete request are empty
1 parent 290806c commit d3227ef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/rbac/user.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ impl UserGroup {
271271
}
272272

273273
pub fn add_roles(&mut self, roles: HashSet<String>) -> Result<(), RBACError> {
274+
if roles.is_empty() {
275+
return Ok(());
276+
}
274277
self.roles.extend(roles);
275278
// also refresh all user sessions
276279
for username in &self.users {
@@ -280,6 +283,9 @@ impl UserGroup {
280283
}
281284

282285
pub fn add_users(&mut self, users: HashSet<String>) -> Result<(), RBACError> {
286+
if users.is_empty() {
287+
return Ok(());
288+
}
283289
self.users.extend(users.clone());
284290
// also refresh all user sessions
285291
for username in &users {
@@ -289,6 +295,9 @@ impl UserGroup {
289295
}
290296

291297
pub fn remove_roles(&mut self, roles: HashSet<String>) -> Result<(), RBACError> {
298+
if roles.is_empty() {
299+
return Ok(());
300+
}
292301
let old_roles = &self.roles;
293302
let new_roles = HashSet::from_iter(self.roles.difference(&roles).cloned());
294303

@@ -305,6 +314,9 @@ impl UserGroup {
305314
}
306315

307316
pub fn remove_users(&mut self, users: HashSet<String>) -> Result<(), RBACError> {
317+
if users.is_empty() {
318+
return Ok(());
319+
}
308320
let old_users = &self.users;
309321
let new_users = HashSet::from_iter(self.users.difference(&users).cloned());
310322

0 commit comments

Comments
 (0)