Skip to content

Conversation

nikhilsinhaparseable
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Aug 28, 2025

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

  • Refactor
    • Improved user-group management to short-circuit no-op updates (e.g., empty add/remove requests), avoiding unnecessary background session refreshes and state changes. When real changes occur, behavior is unchanged: affected users’ sessions are refreshed as before. This reduces overhead and can make administrative actions that have no effect respond faster.

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
Copy link
Contributor

coderabbitai bot commented Aug 28, 2025

Walkthrough

Adds early-return guards to four UserGroup mutator methods in src/rbac/user.rs so empty input HashSets return Ok(()) immediately without modifying state or refreshing sessions. Non-empty inputs keep existing behavior: update sets and refresh sessions. Public method signatures are unchanged.

Changes

Cohort / File(s) Summary of changes
RBAC user group mutators
src/rbac/user.rs
Added empty-input guards to add_roles, add_users, remove_roles, remove_users to return early on empty HashSets. For non-empty inputs: add_roles extends roles and refreshes sessions for all current users; add_users extends users and refreshes sessions for added users; remove_roles computes new roles and, if changed, updates and refreshes sessions for all current users; remove_users computes removed users and, if any, refreshes sessions for removed users and updates internal users. No public signatures changed.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I hop through code with tidy cheer,
Empty baskets? Nothing here.
No sessions stirred, no needless fuss,
Quick return—leave state for us.
For non-empty, onward we press—🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 290806c and d3227ef.

📒 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 shadow roles()/users() from the prelude, which can hinder readability. Consider role_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.

📥 Commits

Reviewing files that changed from the base of the PR and between d3227ef and 4b98181.

📒 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.

@nitisht nitisht merged commit 92485d4 into parseablehq:main Aug 28, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants