Refactor organization handling in OrganizationAndEntityTypePolicyHelper - BUG 4572#1601
Conversation
…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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🟠 MajorDuplicate guard is missing in the
ASSOCIATEDpathAfter adding the current org at Line 68-Line 70, the
ASSOCIATEDbranch still appends rawfindAllresults (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
📒 Files selected for processing (1)
src/helpers/getOrgIdAndEntityTypewithEntitiesBasedOnPolicy.js
…tityTypePolicyHelper to simplify logic by removing duplication checks. This change enhances code clarity and ensures consistent handling of organization data.
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
Contributor Statistics