fix: getTeamIdsWithPermission return sub teams#25387
Merged
Conversation
sean-brydon
commented
Nov 25, 2025
packages/features/pbac/infrastructure/repositories/PermissionRepository.ts
Show resolved
Hide resolved
sean-brydon
commented
Nov 25, 2025
| SELECT child."id" as "teamId" | ||
| FROM "Membership" org_m | ||
| INNER JOIN "Role" org_r ON org_m."customRoleId" = org_r.id | ||
| INNER JOIN "Team" child ON child."parentId" = org_m."teamId" |
Contributor
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="packages/features/pbac/infrastructure/repositories/PermissionRepository.ts">
<violation number="1" location="packages/features/pbac/infrastructure/repositories/PermissionRepository.ts:326">
PBAC-disabled fallback filtering is applied to the parent org instead of the child team, so PBAC-enabled child teams can be unlocked via fallback roles. Ensure the NOT EXISTS check inspects the child team’s feature flag.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
packages/features/pbac/infrastructure/repositories/PermissionRepository.ts
Outdated
Show resolved
Hide resolved
volnei
previously approved these changes
Nov 25, 2025
Contributor
E2E results are ready! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Udit-takkar
previously approved these changes
Nov 25, 2025
Contributor
There was a problem hiding this comment.
2 issues found across 3 files
Prompt for AI agents (all 2 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/features/pbac/services/__tests__/permission-check.service.test.ts">
<violation number="1" location="packages/features/pbac/services/__tests__/permission-check.service.test.ts:558">
The new “PBAC permissions” test is a duplicate of the fallback-role test, so it does not verify PBAC behavior and will never fail if PBAC support breaks. Please rewrite it to exercise PBAC-specific logic (or drop it) instead of duplicating the previous test.</violation>
</file>
<file name="packages/features/pbac/infrastructure/repositories/PermissionRepository.ts">
<violation number="1" location="packages/features/pbac/infrastructure/repositories/PermissionRepository.ts:326">
Child fallback role query only checks the parent org’s PBAC flag, so PBAC-enabled child teams become accessible via fallback roles, bypassing PBAC safeguards.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
| }); | ||
| }); | ||
|
|
||
| it("should include child teams where user has org-level PBAC permissions", async () => { |
Contributor
There was a problem hiding this comment.
The new “PBAC permissions” test is a duplicate of the fallback-role test, so it does not verify PBAC behavior and will never fail if PBAC support breaks. Please rewrite it to exercise PBAC-specific logic (or drop it) instead of duplicating the previous test.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/features/pbac/services/__tests__/permission-check.service.test.ts, line 558:
<comment>The new “PBAC permissions” test is a duplicate of the fallback-role test, so it does not verify PBAC behavior and will never fail if PBAC support breaks. Please rewrite it to exercise PBAC-specific logic (or drop it) instead of duplicating the previous test.</comment>
<file context>
@@ -534,6 +534,46 @@ describe("PermissionCheckService", () => {
+ });
+ });
+
+ it("should include child teams where user has org-level PBAC permissions", async () => {
+ // User has PBAC permission in org (teamId: 100) but not in child team (teamId: 1)
+ // Should get access to child team via org-level PBAC permission
</file context>
✅ Addressed in 381c1b8
packages/features/pbac/infrastructure/repositories/PermissionRepository.ts
Outdated
Show resolved
Hide resolved
Co-Authored-By: sean@cal.com <Sean@brydon.io>
…ermission-org' into fix/getTeamIdsWithPermission-org
Co-Authored-By: sean@cal.com <Sean@brydon.io>
6 tasks
volnei
approved these changes
Dec 2, 2025
This was referenced Jan 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Pr fixes the issue where getTeamIdsWithPermissions would only return the direct teamId queried permission if it exist and did not count the org Id if they had the permission granted in the parent TeamId