-
Notifications
You must be signed in to change notification settings - Fork 11.5k
feat(api): add team event-types webhooks controller #26449
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
feat(api): add team event-types webhooks controller #26449
Conversation
- Add TeamsEventTypesWebhooksController for managing webhooks on team event types - Add IsTeamEventTypeWebhookGuard for authorization - Add TeamEventTypeWebhooksService for business logic - Register new controller in TeamsEventTypesModule - Enable unsafeParameterDecoratorsEnabled in biome.json for NestJS support Co-Authored-By: morgan@cal.com <morgan@cal.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: morgan@cal.com <morgan@cal.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Co-Authored-By: morgan@cal.com <morgan@cal.com>
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.
4 issues found across 7 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts">
<violation number="1" location="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts:25">
P1: Using `import type` for DTO classes used with `@Body()` will prevent class-validator and class-transformer from working correctly. The actual class constructors are needed at runtime for validation. Use a regular import instead.</violation>
<violation number="2" location="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts:34">
P0: Using `import type` for injected services will break NestJS dependency injection at runtime. Type-only imports are erased during compilation, so the DI container cannot resolve `TeamEventTypeWebhooksService`. Use a regular import instead.</violation>
</file>
<file name="apps/api/v2/src/modules/webhooks/services/team-event-type-webhooks.service.ts">
<violation number="1" location="apps/api/v2/src/modules/webhooks/services/team-event-type-webhooks.service.ts:4">
P0: Using `import type` for `WebhooksRepository` will break NestJS dependency injection. The type is erased at compile time, so the DI container won't know what to inject. Use a regular import like the existing `event-type-webhooks.service.ts` does.</violation>
</file>
<file name="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.e2e-spec.ts">
<violation number="1" location="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.e2e-spec.ts:80">
P2: Missing test case for non-admin team member authorization. The PR claims to test that "non-admin team members cannot access the endpoints (should get 403)" but all test users are created with `role: "ADMIN"`. Consider adding a test user with `role: "MEMBER"` and a test case verifying they receive 403 when accessing webhook endpoints on their team's event types.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts
Outdated
Show resolved
Hide resolved
apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts
Outdated
Show resolved
Hide resolved
apps/api/v2/src/modules/webhooks/services/team-event-type-webhooks.service.ts
Outdated
Show resolved
Hide resolved
.../src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.e2e-spec.ts
Show resolved
Hide resolved
Co-Authored-By: morgan@cal.com <morgan@cal.com>
Co-Authored-By: morgan@cal.com <morgan@cal.com>
supalarry
left a comment
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.
Review:
apps/api/v2/src/modules/webhooks/guards/is-team-event-type-webhook-guard.ts
Outdated
Show resolved
Hide resolved
.../src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.e2e-spec.ts
Show resolved
Hide resolved
E2E results are ready! |
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.
1 issue found across 9 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts">
<violation number="1" location="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts:2">
P1: Using `import type` for `SkipTakePagination` will erase the class at runtime, breaking query parameter validation and transformation. This class has `@Transform`, `@IsNumber`, `@Min`, `@Max` decorators that require runtime availability. Change to a regular import to match the pattern in `event-types-webhooks.controller.ts`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts
Outdated
Show resolved
Hide resolved
supalarry
left a comment
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.
Review:
apps/api/v2/src/modules/webhooks/guards/is-team-event-type-webhook-guard.ts
Show resolved
Hide resolved
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.
4 issues found across 9 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.e2e-spec.ts">
<violation number="1" location="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.e2e-spec.ts:79">
P2: Missing test coverage for MEMBER role restriction. The PR specifically changes the guard to only allow team admins/owners, but there's no test verifying that a regular team MEMBER gets 403 when accessing these endpoints. Consider adding a test with a user who has `role: "MEMBER"` membership on the team and verify they receive 403.</violation>
</file>
<file name="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts">
<violation number="1" location="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts:52">
P1: Missing authorization check: The `eventTypeId` is not validated to belong to the team. A team admin could create webhooks on event types belonging to other teams. Consider adding a guard that validates event type ownership (similar to how `IsTeamEventTypeWebhookGuard.validateAndGetEventType` checks `teamsEventTypesRepository.getTeamEventType(teamId, eventTypeId)`).</violation>
<violation number="2" location="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts:52">
P0: Missing authorization check: The `eventTypeId` is not validated to belong to the team. A team admin could delete all webhooks from event types belonging to other teams. This is a critical authorization bypass. Consider adding a guard that validates event type ownership before allowing deletion.</violation>
<violation number="3" location="apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts:91">
P1: Missing authorization check: The `eventTypeId` is not validated to belong to the team. A team member could list webhooks from event types belonging to other teams. Consider adding a guard that validates the event type belongs to the specified team before returning webhooks.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
.../src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.e2e-spec.ts
Show resolved
Hide resolved
apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts
Show resolved
Hide resolved
apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts
Show resolved
Hide resolved
apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types-webhooks.controller.ts
Show resolved
Hide resolved
volnei
left a comment
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 does this PR do?
Adds a new API v2 controller for managing webhooks on team event types, following the existing pattern from
event-types-webhooks.controller.ts.New endpoints at
/v2/teams/:teamId/event-types/:eventTypeId/webhooks:POST /- Create a webhook for a team event typePATCH /:webhookId- Update a webhookGET /:webhookId- Get a specific webhookGET /- List all webhooks (paginated)DELETE /:webhookId- Delete a specific webhookDELETE /- Delete all webhooks for the event typeNew files:
TeamsEventTypesWebhooksController- Main controller with CRUD endpointsIsTeamEventTypeWebhookGuard- Authorization guard validating team admin/owner membership and event type ownershipTeamEventTypeWebhooksService- Business logic layer for webhook operationsteams-event-types-webhooks.controller.e2e-spec.ts- E2E tests covering all endpointsConfiguration change:
unsafeParameterDecoratorsEnabled: trueto biome.json to support NestJS parameter decoratorsUpdates since last revision
IsTeamEventTypeWebhookGuardto only allow team admins or owners to manage webhooks (not regular team members). The guard now usesgetUserAdminOrOwnerTeamMembershipinstead offindMembershipByTeamId.import typestatements in controller, service, and guard files per cubic-dev-ai feedback. Changed to regular imports for services, repositories, and DTOs that require runtime availability for NestJS dependency injection and class-validator/class-transformer.Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
/v2/teams/{teamId}/event-types/{eventTypeId}/webhooksE2E tests can be run with:
TZ=UTC yarn test:e2e --testPathPattern="teams-event-types-webhooks.controller.e2e-spec.ts"Human Review Checklist
getUserAdminOrOwnerTeamMembership)Link to Devin run: https://app.devin.ai/sessions/3afb0c9b900f43f8a86ace48c190c5a0
Requested by: morgan@cal.com (@ThyMinimalDev)