Skip to content

feature/ST-1742-TK-2815-added-tenant-admin-flow#213

Merged
VISHNUDAS-tunerlabs merged 4 commits intodevelopfrom
tenantAdminFlow
Mar 24, 2026
Merged

feature/ST-1742-TK-2815-added-tenant-admin-flow#213
VISHNUDAS-tunerlabs merged 4 commits intodevelopfrom
tenantAdminFlow

Conversation

@MallanagoudaB
Copy link
Copy Markdown
Collaborator

@MallanagoudaB MallanagoudaB commented Feb 26, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Corrected organization ID handling in authentication and entity management flows to use consistent scalar values instead of array-based access.
    • Streamlined tenant-admin authentication workflow by removing redundant validation steps while maintaining security through token-based organization verification.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 26, 2026

📝 Walkthrough

Walkthrough

The changes refactor organization ID handling from array-based to scalar values across the authentication and entity management layers. The authenticator middleware simplifies the TENANT_ADMIN flow by deriving orgId directly from the decoded token's first organization code and removing prior validation checks. Entity and entity type helpers updated accordingly to treat orgId as a primitive value.

Changes

Cohort / File(s) Summary
Authenticator Middleware
src/generics/middleware/authenticator.js
Simplified TENANT_ADMIN flow to initialize req.headers['orgid'] directly from decoded token's first organization code; removed validateIfOrgsBelongsToTenant validation step; added string coercion for orgId during admin scope elevation.
Entity Helpers
src/module/entities/helper.js
Changed orgId retrieval from array access (orgId[0]) to scalar access in add and bulkCreate flows.
Entity Type Helpers
src/module/entityTypes/helper.js
Changed orgId assignment from array element extraction (orgId[0]) to direct scalar value in bulkCreate and create flows.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Suggested reviewers

  • VISHNUDAS-tunerlabs

Poem

🐰 From arrays to scalars, the orgId takes flight,
No more nested checks slowing down the night,
The token now speaks its org truth so clear,
Authentication hops lighter, crisp and sincere!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'feature/ST-1742-TK-2815-added-tenant-admin-flow' is overly broad and uses multiple issue identifiers and a generic qualifier ('added') that obscure the specific changes. Revise the title to be more specific about the key behavioral change. Consider: 'Simplify TENANT_ADMIN orgId initialization and fix orgId scalar handling' or similar to reflect the actual refactoring.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tenantAdminFlow

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@MallanagoudaB
Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 26, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/generics/middleware/authenticator.js`:
- Around line 491-493: When extracting org for TENANT_ADMIN in the authenticator
middleware, guard access to decodedToken.data.organizations to avoid null/empty
array access and ensure the user's chosen org is persisted: check role (e.g.
TENANT_ADMIN) and if decodedToken.data.organizations exists and has elements use
decodedToken.data.organizations[0].code, otherwise fall back safely (e.g.
undefined) without throwing; also when req.body.orgId is present set
req.headers['orgid'] = req.body.orgId (not just read it) so the selected org is
honored; update the logic around the orgId assignment that currently reads
decodedToken and req.body (the lines referencing
decodedToken.data.organizations, req.headers['orgid'], and req.body.orgId) to
include these guards and the header assignment.
- Line 510: The assignment decodedToken.data.tenantAndOrgInfo['orgId'] =
req.headers['orgid'].toString() corrupts arrays into comma strings; change it to
preserve arrays or explicitly pick a single ID: check if
Array.isArray(req.headers['orgid']) then assign the array directly to
decodedToken.data.tenantAndOrgInfo['orgId'], else if you expect a single org id
wrap the string in an array (e.g. [req.headers['orgid']]) or extract the first
element; update the assignment in the authenticator middleware (the
decodedToken.data.tenantAndOrgInfo['orgId'] set used in SUPER_ADMIN / ORG_ADMIN
flows) to use this conditional logic instead of .toString().

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 071c5ac and 671ceee.

📒 Files selected for processing (3)
  • src/generics/middleware/authenticator.js
  • src/module/entities/helper.js
  • src/module/entityTypes/helper.js

Comment thread src/generics/middleware/authenticator.js Outdated
Comment thread src/generics/middleware/authenticator.js Outdated
Copy link
Copy Markdown
Collaborator

@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First review - Mar 3

Comment thread src/generics/services/users.js Outdated
Comment thread src/generics/middleware/authenticator.js Outdated
@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs changed the base branch from develop to release-3.4.1 March 4, 2026 08:22
Copy link
Copy Markdown
Collaborator

@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed on 4 March - 2nd review

@MallanagoudaB MallanagoudaB changed the base branch from release-3.4.1 to develop March 9, 2026 05:27
@MallanagoudaB MallanagoudaB changed the title tenant-admin-flow-handled feature/ST-1742-TK-2815-added-tenant-admin-flow Mar 24, 2026
Copy link
Copy Markdown
Collaborator

@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on 24 March

@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs merged commit b82143e into develop Mar 24, 2026
1 check 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