-
Notifications
You must be signed in to change notification settings - Fork 10.2k
fix: (PBAC) Add organization fallback on resources #22733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughA new method, Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/features/pbac/services/__tests__/permission-check.service.test.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-playwright". (The package "eslint-plugin-playwright" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-playwright" was referenced from the config file in ".eslintrc.js". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. ✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (07/25/25)1 reviewer was added to this PR based on Keith Williams's automation. "Add ready-for-e2e label" took an action on this PR • (07/25/25)1 label was added to this PR based on Keith Williams's automation. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/features/pbac/domain/repositories/IPermissionRepository.ts
(3 hunks)packages/features/pbac/services/__tests__/permission-check.service.test.ts
(6 hunks)packages/features/pbac/services/permission-check.service.ts
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/features/pbac/domain/repositories/IPermissionRepository.ts
- packages/features/pbac/services/tests/permission-check.service.test.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code. Functions like .add, .diff, .isBefore, and .isAfter are slow, especially in timezone mode. Prefer .utc() for better performance. Where possible, replace with native Date and direct .valueOf() comparisons for faster execution. Recommend using native methods or Day.js .utc() consistently in hot paths like loops.
Files:
packages/features/pbac/services/permission-check.service.ts
🧬 Code Graph Analysis (1)
packages/features/pbac/services/permission-check.service.ts (1)
packages/features/pbac/domain/mappers/PermissionMapper.ts (1)
PermissionMapper
(7-116)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Install dependencies / Yarn install & cache
🔇 Additional comments (2)
packages/features/pbac/services/permission-check.service.ts (2)
9-14
: LGTM - Import changes support the new functionality.The addition of
CrudAction
andCustomAction
types to the import is necessary for the refactoredgetResourcePermissions
method implementation.
246-247
: LGTM - Property access updated for nested team structure.The change from
membership.team_parentId
tomembership.team.parentId
correctly reflects the updated membership data structure with nested team objects.
@@ -20,7 +22,9 @@ export interface IPermissionRepository { | |||
teamId: number; | |||
userId: number; | |||
customRoleId: string | null; | |||
team_parentId?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outdated type from when this used to use ksyely
…ac-fallback-to-org' into fix/getResoruces-pbac-fallback-to-org
|
||
// Get team-level permissions | ||
if (membership?.customRoleId) { | ||
const teamActions = await this.repository.getResourcePermissionsByRoleId( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we turn getResourcePermissionsByRoleId
to accept roleIds
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
o.o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think passing in a teamId + an optionalRoleId might be a good shout here. Let me play around with that
There was a problem hiding this 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
🧹 Nitpick comments (1)
packages/features/pbac/services/__tests__/permission-check.service.test.ts (1)
388-635
: Excellent comprehensive test coverage for getResourcePermissions.The test suite thoroughly covers all major scenarios including:
- Feature flag states
- Team-only and org-only permissions
- Combined permission aggregation
- Permission deduplication
- Error handling and edge cases
The test structure is well-organized and the mocking strategy is appropriate.
Minor suggestion for the hierarchy test (lines 591-634): The test name suggests "precedence" but the implementation shows additive behavior. Consider renaming to "should combine team and org permissions additively" to better reflect the actual behavior being tested.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/features/pbac/services/__tests__/permission-check.service.test.ts
(6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code. Functions like .add, .diff, .isBefore, and .isAfter are slow, especially in timezone mode. Prefer .utc() for better performance. Where possible, replace with native Date and direct .valueOf() comparisons for faster execution. Recommend using native methods or Day.js .utc() consistently in hot paths like loops.
Files:
packages/features/pbac/services/__tests__/permission-check.service.test.ts
🔇 Additional comments (3)
packages/features/pbac/services/__tests__/permission-check.service.test.ts (3)
9-9
: LGTM! Import addition supports new test functionality.The Resource import is necessary for the new getResourcePermissions test cases.
38-38
: LGTM! Mock method addition aligns with interface changes.The
getResourcePermissionsByRoleId
mock properly supports the new repository method.
83-83
: LGTM! Team structure updated to match new membership data model.The changes from
team_parentId
toteam: { parentId }
properly reflect the updated membership structure.Also applies to: 198-198, 275-275
Problem
The getResourcePermissions method in PermissionCheckService only
checked team-level permissions, while the checkPermission method
correctly implements a fallback hierarchy that checks both team and
organization-level permissions. This inconsistency meant that users
with organization-level permissions wouldn't see those permissions
when using getResourcePermissions, even though they would be granted
access via checkPermission.
Business Logic Alignment
This change ensures getResourcePermissions now follows the exact same
permission hierarchy as checkPermission:
// Both methods now follow this pattern:
match (checkPermission)
Example Usage
Breaking Changes
None. This is a backward-compatible enhancement that only adds
functionality.