fix: pbac being enabled when a team has ANY features#24494
Conversation
WalkthroughThe settings layout now loads permissions conditionally based on a PBAC feature flag. It first fetches features. If PBAC is enabled, it fetches rolePermissions and organizationPermissions in parallel and applies them. If PBAC is disabled or features are not loaded, it falls back: when features exist, canViewRoles derives from admin/owner status; when features are not loaded, canViewRoles defaults to false. This introduces a feature-flag gate and changes the permission-loading control flow. No exported/public declarations changed. Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ 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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/layout.tsx (2)
56-62: Fetch features first: correct sequencing; minor perf trade-off notedFetching features first prevents PBAC checks from running when not needed. This fixes the bug. If PBAC-enabled orgs are common and latency is critical, consider pre-starting permission fetches and only awaiting/using them when PBAC is true to hide the extra RTT; otherwise current approach reduces unnecessary DB load for PBAC-off orgs.
64-73: Proper PBAC gate around permission fetch/useGating both the fetch and application of PBAC permissions on
features?.pbac === trueresolves the “ANY feature enables PBAC” issue.One follow-up to verify: the repository currently maps slugs to
trueand ignores theenabledflag (see packages/features/flags/features.repository.ts, Lines 67-89). If a PBAC relation exists but is disabled,features.pbacwould still be truthy and keep PBAC enabled here. Recommend filtering onfeature.enabled: truein the repository, e.g.:// In FeaturesRepository.getTeamFeatures await this.prismaClient.teamFeatures.findMany({ where: { teamId, feature: { enabled: true } }, // ensure only enabled features include: { feature: { select: { slug: true } } }, // enabled no longer needed });
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/layout.tsx(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Always use
t()for text localization in frontend code; direct text embedding should trigger a warning
Files:
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/layout.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()in hot paths like loops
Files:
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/layout.tsx
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/layout.tsx
🧬 Code graph analysis (1)
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/layout.tsx (1)
packages/features/flags/features.repository.ts (1)
getTeamFeatures(68-90)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Type check / check-types
- GitHub Check: Linters / lint
- GitHub Check: Tests / Unit
🔇 Additional comments (1)
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/layout.tsx (1)
81-85: Legacy fallback is correct and conservativeWhen PBAC is off or features missing, falling back to admin/owner for all checks (and
falsefor roles when no features loaded) is safe and matches expected behavior.Please re-run the two test steps in the PR description to confirm visibility toggles match expectations.
E2E results are ready! |
What does this PR do?
Currently if a team has ANY features we are checking PBAC permissions in the UI to display the nav items.
How should this be tested?
Assign an org two random features (not pbac)
notice you do have access to a few of the settings nav items (previously this is hidden)
Assign an org two random features (including pbac)
Notive everything works as expected