fix: get bookings handler for pbac and fallback roles#1
Conversation
📝 WalkthroughWalkthroughThe PR extends permission-based access control (PBAC) repository methods and their consumers with optional organization ID filtering. An Changes
Sequence Diagram(s)sequenceDiagram
participant Handler as Booking Handler
participant Service as PermissionCheckService
participant Repo as PermissionRepository
participant DB as Database
Handler->>Service: getTeamIdsWithPermission({userId, permission, fallbackRoles, orgId?})
Service->>Repo: getTeamIdsWithPermission({userId, permission, fallbackRoles, orgId?})
rect rgba(100, 150, 200, 0.5)
Note over Repo: Parallel Execution
par PBAC Path
Repo->>DB: Query teams by direct PBAC permission<br/>(filtered by orgId if provided)
and Fallback Roles Path
Repo->>DB: Query teams by fallback roles<br/>(filtered by orgId if provided)
end
end
DB-->>Repo: PBAC teams + Fallback teams
Repo->>Repo: Deduplicate & merge team IDs
Repo-->>Service: Promise<number[]>
Service-->>Handler: Team IDs with permission
Handler->>Handler: Filter event types & users by team permissions
Handler-->>Client: Accessible bookings
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
1 similar comment
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/features/pbac/infrastructure/repositories/PermissionRepository.ts (1)
211-223:⚠️ Potential issue | 🔴 CriticalMissing orgId propagation drops org scoping.
getTeamIdsWithPermissionignoresorgIdwhen delegating, so org-scoped calls can return teams outside the intended organization.🛠️ Proposed fix
- return this.getTeamIdsWithPermissions({ userId, permissions: [permission], fallbackRoles }); + return this.getTeamIdsWithPermissions({ userId, permissions: [permission], fallbackRoles, orgId });packages/trpc/server/routers/viewer/bookings/get.handler.ts (1)
144-155:⚠️ Potential issue | 🔴 CriticalAuthorization bypass when userIds include self + unauthorized users.
If
filters.userIdscontains the current user plus any unauthorized IDs, the current check allows the whole set. That enables access beyond permitted scope.🛠️ Proposed fix
- const areUserIdsWithinUserOrgOrTeam = filters.userIds.every((userId) => - allAccessibleUserIds.includes(userId) - ); - - const isCurrentUser = filters.userIds.includes(user.id); + const unauthorizedUserIds = filters.userIds.filter( + (userId) => userId !== user.id && !allAccessibleUserIds.includes(userId) + );- if (!areUserIdsWithinUserOrgOrTeam && !isCurrentUser) { + if (unauthorizedUserIds.length > 0) { throw new TRPCError({ code: "FORBIDDEN", message: "You do not have permissions to fetch bookings for specified userIds", }); }
Benchmark PR from agentic-review-benchmarks#1
Summary by CodeRabbit
New Features
Tests