Skip to content

updating orgCode#804

Merged
nevil-mathew merged 1 commit intodevelopfrom
updateRoleFix
Aug 22, 2025
Merged

updating orgCode#804
nevil-mathew merged 1 commit intodevelopfrom
updateRoleFix

Conversation

@rakeshSgr
Copy link
Collaborator

@rakeshSgr rakeshSgr commented Aug 22, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Role request status emails now display the correct organization name and code for both accepted and rejected decisions.
    • Ensures organization details in these emails are accurately populated, improving clarity and reducing confusion for recipients.

@coderabbitai
Copy link

coderabbitai bot commented Aug 22, 2025

Walkthrough

Updated sendRoleRequestStatusEmail in src/services/org-admin.js to consistently use organizationCode instead of orgCode for organization lookup and the organization_code field in both ACCEPTED and REJECTED branches. No function signatures or exports changed.

Changes

Cohort / File(s) Summary
Org admin email identifier fix
src/services/org-admin.js
Replaced orgCode with organizationCode in organization lookup { code: organizationCode } and in the organization_code field assignment across ACCEPTED/REJECTED paths; no API/signature changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I twitch my whiskers, double-check the code,
org to organization—now the proper road.
Emails hop correctly, no more stray abode,
ACCEPT or REJECT, the right field bestowed.
Thump! A tidy patch along the rabbit’s node. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.

Copy link

@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/services/org-admin.js (2)

673-686: Email portalURL is set to the tenantDomain object instead of its domain string

tenantDomainQueries.findOne returns an object with a domain attribute, but the template variable portalURL is currently assigned the entire object. This will likely serialize to "[object Object]" or an unexpected structure in emails.

Apply this minimal diff to pass the string domain:

-        const tenantDomain = await tenantDomainQueries.findOne(
+        const tenantDomain = await tenantDomainQueries.findOne(
           { tenant_code: tenantCode },
           { attributes: ['domain'] }
         )
+        const portalURL = tenantDomain?.domain || ''
...
-            portalURL: tenantDomain,
+            portalURL,

165-171: Queue retry attempts hardcoded to 1 due to 1 || common.NO_OF_ATTEMPTS

1 || common.NO_OF_ATTEMPTS always evaluates to 1, overriding configured retries and reducing reliability for bulk jobs.

Use the configured attempts with a safe fallback:

-          attempts: 1 || common.NO_OF_ATTEMPTS,
+          attempts: Number(common.NO_OF_ATTEMPTS) || 1,
🧹 Nitpick comments (3)
src/services/org-admin.js (3)

631-652: Unify terminology: rename orgCode parameter to organizationCode for clarity

This file uses organization_code/organizationCode almost everywhere else. Renaming the local parameter improves readability and reduces confusion.

-function updateRoleForApprovedRequest(requestDetails, user, tenantCode, orgCode) {
+function updateRoleForApprovedRequest(requestDetails, user, tenantCode, organizationCode) {
   return new Promise(async (resolve, reject) => {
     try {
       const newRole = await roleQueries.findOne(
         { id: requestDetails.role, status: common.ACTIVE_STATUS, tenant_code: tenantCode },
         { attributes: ['title', 'id', 'user_type', 'status'] }
       )
 
       await userOrganizationRoleQueries.create({
         tenant_code: tenantCode,
         user_id: user.id,
-        organization_code: orgCode,
+        organization_code: organizationCode,
         role_id: newRole.id,
       })
 
       eventBroadcaster('roleChange', {
         requestBody: {
           user_id: requestDetails.requester_id,
           new_roles: [newRole.title],
-          current_roles: _.map(_.find(user.organizations, { code: orgCode })?.roles || [], 'title'),
+          current_roles: _.map(_.find(user.organizations, { code: organizationCode })?.roles || [], 'title'),
         },
       })

331-337: Typo in message key 'INAVLID_ORG_ROLE_REQ'

The constant looks misspelled; expected 'INVALID_ORG_ROLE_REQ'. If these keys map to i18n resources, changing it may require updating translations.

If it’s safe to correct, apply:

-          message: 'INAVLID_ORG_ROLE_REQ',
+          message: 'INVALID_ORG_ROLE_REQ',

456-459: Avoid logging full updated user objects

console.log(rowsAffected, updatedUsers) may log PII (user IDs/emails). Prefer targeted, non-PII logs or a debug logger gated by environment.

-        console.log(rowsAffected, updatedUsers)
+        console.debug('deactivateUser by IDs affected:', rowsAffected)
📜 Review details

Configuration used: Path: .coderabbit.yaml

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 002c907 and cc2c737.

📒 Files selected for processing (1)
  • src/services/org-admin.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/services/**

⚙️ CodeRabbit configuration file

This is core business logic. Please check for correctness, efficiency, and potential edge cases.

Files:

  • src/services/org-admin.js
🧬 Code graph analysis (1)
src/services/org-admin.js (1)
src/services/account.js (1)
  • organizationCode (194-194)
🔇 Additional comments (2)
src/services/org-admin.js (2)

696-702: Consistent use of organizationCode in REJECTED email — LGTM

Both orgName resolution and organization_code now consistently use organizationCode in the REJECTED branch, matching the ACCEPTED branch usage. No further action needed here.


375-381: No further action needed for organization_code availability

The authentication middleware (src/middlewares/authenticator.js) always extracts and injects organization_code (from decodedToken.data.organizations[0].code) into req.decodedToken.data alongside tenant_code, so downstream service calls—including both updateRoleForApprovedRequest and sendRoleRequestStatusEmail—will always receive a valid tokenInformation.organization_code. Missing or undefined values would already have been caught earlier in the middleware. Consequently, no additional checks are required here and this review comment can be resolved.

@nevil-mathew nevil-mathew merged commit d734d91 into develop Aug 22, 2025
1 of 2 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