Skip to content

Conversation

@nevil-mathew
Copy link
Collaborator

@nevil-mathew nevil-mathew commented Aug 12, 2025

Summary by CodeRabbit

  • New Features

    • Support for deactivating an organization within a specific tenant.
    • Automatically deactivates users in the organization and signs them out of active sessions.
  • Bug Fixes

    • More accurate reporting of how many users were deactivated.
    • Avoids unnecessary session notifications when no users are affected.
  • Chores

    • Improved admin action validation and documentation for deactivation flows.

@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The admin controller now extracts tenant-id and adminId and calls adminService.deactivateOrg with (orgId/code, tenantId, adminId). The service changes to deactivate organizations by organizationCode and tenantCode, deactivates users via a helper, conditionally removes sessions, and broadcasts events. JSDocs and logging were updated.

Changes

Cohort / File(s) Summary
Controller v1 Admin
src/controllers/v1/admin.js
Expanded JSDoc for multi-tenant inputs; controller now passes orgId, tenant-id (from headers), and adminId (from decoded token) to service; retains admin-role guard and error handling.
Admin Service
src/services/admin.js
Signature changed to (organizationCode, tenantCode, loggedInUserId); deactivates org by code+tenant; delegates user deactivation to deactivateUserInOrg; derives affected user IDs from result; conditionally removes all sessions and broadcasts deactivateUpcomingSession; improved error logging; updated JSDoc.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AdminController
  participant AdminService
  participant OrgStore as Org DB
  participant UserHelper
  participant SessionHelper
  participant EventBus

  Client->>AdminController: DELETE /v1/admin/orgs/:id (tenant-id)
  AdminController->>AdminService: deactivateOrg(orgId/code, tenantId, adminId)
  AdminService->>OrgStore: UPDATE organization SET status=INACTIVE WHERE code & tenant_code
  AdminService->>UserHelper: deactivateUserInOrg(orgCode, tenantCode)
  UserHelper-->>AdminService: {rowsAffected, updatedUsers}
  alt rowsAffected > 0
    AdminService->>SessionHelper: removeAllUserSessions(userIds)
    AdminService->>EventBus: broadcast(deactivateUpcomingSession, userIds)
  end
  AdminService-->>AdminController: {deactivated_users, org}
  AdminController-->>Client: 200 OK
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

I twitch my whiskers, flip a switch—deactivate!
Codes and tenants neatly find their fate.
Users nap, sessions fade,
Quiet burrows newly made.
I thump, “All set!” with cheerful vim—
Multi-tenant, tidy, trim. 🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a745fc and 5dad396.

📒 Files selected for processing (2)
  • src/controllers/v1/admin.js (2 hunks)
  • src/services/admin.js (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch deactivate-org

🪧 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 @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai 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 @coderabbitai help to get the list of available commands.

Other keywords and placeholders

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

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.

@nevil-mathew nevil-mathew deleted the deactivate-org branch August 12, 2025 12:44
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