refactor: do a permission check in removeHostsFromEventTypes trpc handler#24176
refactor: do a permission check in removeHostsFromEventTypes trpc handler#24176
Conversation
Walkthrough
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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. 🧪 Early access (Sonnet 4.5): enabledWe are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience. Note:
Comment |
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 (1)
packages/trpc/server/routers/viewer/organizations/removeHostsFromEventTypes.handler.ts (1)
38-47: Ensure eventTypeIds belong to the user’s organization before deletion.
While you check the user’s organizationId and update permission, thedeleteManycall itself isn’t scoped to the org—anyeventTypeIdpassed could delete hosts on another org’s event type. Pre-validate allinput.eventTypeIdsagainstctx.user.organizationId(e.g. count matching eventTypes with that orgId and compare toeventTypeIds.length, throwing if they differ) before invokingprisma.host.deleteMany.
🧹 Nitpick comments (1)
packages/trpc/server/routers/viewer/organizations/removeHostsFromEventTypes.handler.ts (1)
50-50: Prefer named export over default export.The handler is already exported as a named export (line 17), making the default export redundant. Named exports provide better tree-shaking and clearer imports.
Apply this diff to remove the default export:
-export default removeHostsFromEventTypesHandler; -
📜 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)
packages/trpc/server/routers/viewer/organizations/removeHostsFromEventTypes.handler.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: For Prisma queries, only select data you need; never useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/trpc/server/routers/viewer/organizations/removeHostsFromEventTypes.handler.ts
**/*.{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:
packages/trpc/server/routers/viewer/organizations/removeHostsFromEventTypes.handler.ts
**/*.{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:
packages/trpc/server/routers/viewer/organizations/removeHostsFromEventTypes.handler.ts
🧬 Code graph analysis (1)
packages/trpc/server/routers/viewer/organizations/removeHostsFromEventTypes.handler.ts (1)
packages/features/pbac/services/permission-check.service.ts (2)
PermissionCheckService(19-306)hasPermission(183-201)
⏰ 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). (1)
- GitHub Check: Install dependencies / Yarn install & cache
🔇 Additional comments (2)
packages/trpc/server/routers/viewer/organizations/removeHostsFromEventTypes.handler.ts (2)
1-3: LGTM! Imports are appropriate for PBAC refactor.The new imports for
PermissionCheckServiceandMembershipRoleare correctly added to support the permission-based access control implementation.
20-34: No action required: ‘eventType.update’ is the correct permission. All host-management handlers use this existing permission and no more granular permission is defined in the PBAC model.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
E2E results are ready! |
What does this PR do?
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?