-
-
Notifications
You must be signed in to change notification settings - Fork 153
fix: add empty check before removing users from session #1418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add empty check before removing users from session #1418
Conversation
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
WalkthroughAdds early-return guards to four UserGroup mutator methods in Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant UG as UserGroup
participant Sess as SessionManager
Caller->>UG: add_roles/add_users/remove_roles/remove_users(set)
alt set is empty
note right of UG #f4f4f8: Early return\nNo state change\nNo session refresh
UG-->>Caller: Ok(())
else set is non-empty
UG->>UG: Compute diffs / Update internal sets
alt add_roles or remove_roles changed
UG->>Sess: Refresh sessions for all current users
else add_users: users added
UG->>Sess: Refresh sessions for added users
else remove_users: users removed
UG->>Sess: Refresh sessions for removed users
end
Sess-->>UG: Acknowledged
UG-->>Caller: Ok(())
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/rbac/user.rs (1)
286-288
: Only invalidate sessions for actually newly added users (avoid unnecessary logouts).Current logic refreshes sessions for every username in the request, even if some are already in the group. Compute the delta and refresh only those.
Apply this diff:
- self.users.extend(users.clone()); + let newly_added: std::collections::HashSet<String> = + users.difference(&self.users).cloned().collect(); + if newly_added.is_empty() { + return Ok(()); + } + self.users.extend(newly_added.iter().cloned()); // also refresh all user sessions - for username in &users { + for username in &newly_added { mut_sessions().remove_user(username); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/rbac/user.rs
(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/rbac/user.rs (1)
src/rbac/map.rs (2)
roles
(74-80)users
(58-64)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: coverage
- GitHub Check: Build Default x86_64-apple-darwin
- GitHub Check: Quest Smoke and Load Tests for Standalone deployments
- GitHub Check: Quest Smoke and Load Tests for Distributed deployments
- GitHub Check: Build Default aarch64-apple-darwin
- GitHub Check: Build Default x86_64-pc-windows-msvc
- GitHub Check: Build Default x86_64-unknown-linux-gnu
- GitHub Check: Build Default aarch64-unknown-linux-gnu
- GitHub Check: Build Kafka aarch64-apple-darwin
- GitHub Check: Build Kafka x86_64-unknown-linux-gnu
🔇 Additional comments (2)
src/rbac/user.rs (2)
274-276
: Early-return correctly prevents mass session invalidation on empty role updates.This aligns with the PR objective and avoids logging out all group members on no-op modify requests.
298-300
: Good guard on empty role removals.Prevents needless work and session invalidation on no-op delete requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/rbac/user.rs (2)
273-283
: Avoid logging out everyone when nothing actually changes in roles.Only refresh sessions if the group’s role set grows. Compute the delta first to skip no-op updates and needless logouts.
pub fn add_roles(&mut self, roles: HashSet<String>) -> Result<(), RBACError> { if roles.is_empty() { return Ok(()); } - self.roles.extend(roles); + // Add only roles that are not already present + let to_add: std::collections::HashSet<String> = + roles.difference(&self.roles).cloned().collect(); + if to_add.is_empty() { + return Ok(()); + } + self.roles.extend(to_add.iter().cloned()); // also refresh all user sessions for username in &self.users { mut_sessions().remove_user(username); } Ok(()) }
285-295
: Restrict session invalidation to newly added users and avoid cloning.If the incoming set contains users already in the group, their sessions are unnecessarily invalidated. Refresh only the delta.
pub fn add_users(&mut self, users: HashSet<String>) -> Result<(), RBACError> { if users.is_empty() { return Ok(()); } - self.users.extend(users.clone()); - // also refresh all user sessions - for username in &users { + // Compute only the newly added users + let to_add: std::collections::HashSet<String> = + users.difference(&self.users).cloned().collect(); + if to_add.is_empty() { + return Ok(()); + } + self.users.extend(to_add.iter().cloned()); + // refresh sessions only for actually added users + for username in &to_add { mut_sessions().remove_user(username); } Ok(()) }
♻️ Duplicate comments (1)
src/rbac/user.rs (1)
316-332
: Good fix: invalidate sessions only for users actually removed.This addresses the earlier review about over-invalidating sessions when extra usernames are present in the request.
🧹 Nitpick comments (1)
src/rbac/user.rs (1)
273-273
: Minor: parameter names shadow imported helpers.The parameters
roles
/users
shadowroles()
/users()
from the prelude, which can hinder readability. Considerrole_names
/usernames
for clarity.- pub fn add_roles(&mut self, roles: HashSet<String>) -> Result<(), RBACError> { + pub fn add_roles(&mut self, role_names: HashSet<String>) -> Result<(), RBACError> { - pub fn add_users(&mut self, users: HashSet<String>) -> Result<(), RBACError> { + pub fn add_users(&mut self, usernames: HashSet<String>) -> Result<(), RBACError> { - pub fn remove_roles(&mut self, roles: HashSet<String>) -> Result<(), RBACError> { + pub fn remove_roles(&mut self, role_names: HashSet<String>) -> Result<(), RBACError> { - pub fn remove_users(&mut self, users: HashSet<String>) -> Result<(), RBACError> { + pub fn remove_users(&mut self, usernames: HashSet<String>) -> Result<(), RBACError> {Also applies to: 285-285, 297-297, 316-316
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/rbac/user.rs
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Build Default aarch64-apple-darwin
- GitHub Check: Build Default x86_64-pc-windows-msvc
- GitHub Check: Build Default x86_64-apple-darwin
- GitHub Check: Build Default aarch64-unknown-linux-gnu
- GitHub Check: Build Default x86_64-unknown-linux-gnu
- GitHub Check: Build Kafka aarch64-apple-darwin
- GitHub Check: Build Kafka x86_64-unknown-linux-gnu
- GitHub Check: Quest Smoke and Load Tests for Distributed deployments
- GitHub Check: Quest Smoke and Load Tests for Standalone deployments
- GitHub Check: coverage
🔇 Additional comments (1)
src/rbac/user.rs (1)
297-314
: LGTM: correct early-return and refresh semantics for role removal.No-op guard prevents unnecessary work; session refresh for all current members is appropriate when roles change.
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
Summary by CodeRabbit