Skip to content

Refactor organization handling in OrganizationAndEntityTypePolicyHelper - BUG 4572#1601

Merged
nevil-mathew merged 3 commits intodevelopfrom
BUG_4572_Mentee_list_Filters_after_policy_change
Mar 9, 2026
Merged

Refactor organization handling in OrganizationAndEntityTypePolicyHelper - BUG 4572#1601
nevil-mathew merged 3 commits intodevelopfrom
BUG_4572_Mentee_list_Filters_after_policy_change

Conversation

@sumanvpacewisdom
Copy link
Copy Markdown
Collaborator

@sumanvpacewisdom sumanvpacewisdom commented Mar 4, 2026

Enhance organization and tenant code handling in OrganizationAndEntityTypePolicyHelper by ensuring the current organization is included explicitly while preventing duplication in results. This refactor improves code clarity and maintains consistency in data processing.

Release Notes

  • OrganizationAndEntityTypePolicyHelper now explicitly includes the current organization for ASSOCIATED and ALL visibility policies, matching CURRENT branch behavior.
  • Prevents duplicate entries by ensuring the current organization is added before aggregating related organizations and by filtering duplicates when collecting related/extended organizations.
  • Simplified and clarified processing of organization codes, tenant codes, and organization info to maintain consistent data handling.

Contributor Statistics

Author Lines Added Lines Removed
sumanvpacewisdom 5 0

…yTypePolicyHelper by ensuring the current organization is included explicitly while preventing duplication in results. This refactor improves code clarity and maintains consistency in data processing.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 09b0f493-3755-426a-9d5c-090734c6a5aa

📥 Commits

Reviewing files that changed from the base of the PR and between 93a28f2 and 8698011.

📒 Files selected for processing (1)
  • src/helpers/getOrgIdAndEntityTypewithEntitiesBasedOnPolicy.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/helpers/getOrgIdAndEntityTypewithEntitiesBasedOnPolicy.js

Walkthrough

The helper now always appends the current organization's code, info, and tenant code in the ASSOCIATED and ALL visibility branches before collecting related/extended organizations, aligning their behavior with the CURRENT branch and affecting subsequent aggregation of organizationCodes, tenantCodes, and organizationInfo.

Changes

Cohort / File(s) Summary
Org inclusion logic
src/helpers/getOrgIdAndEntityTypewithEntitiesBasedOnPolicy.js
In ASSOCIATED and ALL branches, the current org's organization_code, organizationInfo entry, and tenant_code are added upfront (mirrors CURRENT branch) before gathering related/extended orgs; prevents exclusion of current org from aggregated lists.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • nevil-mathew

Poem

🐰 I hop and add the current code with cheer,
I tuck the tenant and the info near,
Then gather kin from branches wide and far,
So no small org is missing from the bar,
A tidy trail beneath the evening star.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring organization handling in a specific helper file to fix bug 4572, which aligns with the actual code changes that ensure current organization data inclusion.
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 (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BUG_4572_Mentee_list_Filters_after_policy_change

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.

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/helpers/getOrgIdAndEntityTypewithEntitiesBasedOnPolicy.js (1)

67-131: ⚠️ Potential issue | 🟠 Major

Duplicate guard is missing in the ASSOCIATED path

After adding the current org at Line 68-Line 70, the ASSOCIATED branch still appends raw findAll results (Line 128-Line 130). If the related-org list contains the current org, duplicates reappear.

Suggested fix
 						if (organizationExtension) {
-							const organizationCodesFromOrgExtension = organizationExtension.map(
+							const filteredOrgExtension = organizationExtension.filter(
+								(org) => org.organization_code !== orgExtension.organization_code
+							)
+
+							const organizationCodesFromOrgExtension = filteredOrgExtension.map(
 								(orgExt) => orgExt.organization_code
 							)
 
-							const tenantCodesFromOrgExtension = organizationExtension.map(
+							const tenantCodesFromOrgExtension = filteredOrgExtension.map(
 								(orgExt) => orgExt.tenant_code
 							)
 
-							organizationInfo.push(...organizationExtension)
+							organizationInfo.push(...filteredOrgExtension)
 							organizationCodes.push(...organizationCodesFromOrgExtension)
 							tenantCodes.push(...tenantCodesFromOrgExtension)
 						}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/helpers/getOrgIdAndEntityTypewithEntitiesBasedOnPolicy.js` around lines
67 - 131, The ASSOCIATED branch can re-add the current org because relatedOrgs
may include it; update the visibilityPolicy === common.ASSOCIATED handling
(around organisationExtensionQueries.findAll and the subsequent push into
organizationInfo, organizationCodes, tenantCodes) to deduplicate before
appending: either filter out entries whose organization_code (or
organization_id) already exists in organizationCodes/organizationInfo (or match
orgExtension.organization_code) or perform a Set-based merge of
organizationCodes/tenantCodes/organizationInfo so duplicates are not pushed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/helpers/getOrgIdAndEntityTypewithEntitiesBasedOnPolicy.js`:
- Around line 67-131: The ASSOCIATED branch can re-add the current org because
relatedOrgs may include it; update the visibilityPolicy === common.ASSOCIATED
handling (around organisationExtensionQueries.findAll and the subsequent push
into organizationInfo, organizationCodes, tenantCodes) to deduplicate before
appending: either filter out entries whose organization_code (or
organization_id) already exists in organizationCodes/organizationInfo (or match
orgExtension.organization_code) or perform a Set-based merge of
organizationCodes/tenantCodes/organizationInfo so duplicates are not pushed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 06e2399e-df4a-48fa-b5e8-d7c7a2a9975c

📥 Commits

Reviewing files that changed from the base of the PR and between 58b9d33 and 4a2398f.

📒 Files selected for processing (1)
  • src/helpers/getOrgIdAndEntityTypewithEntitiesBasedOnPolicy.js

sumanvpacewisdom and others added 2 commits March 9, 2026 14:26
…tityTypePolicyHelper to simplify logic by removing duplication checks. This change enhances code clarity and ensures consistent handling of organization data.
@nevil-mathew nevil-mathew merged commit f86a0a9 into develop Mar 9, 2026
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