chore: Integrate confirmation booking audit#10
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request integrates comprehensive audit tracking for booking confirmation and rejection events across all entry points in the Cal.com application. The PR adds support for tracking when bookings are accepted or rejected through the webapp, API v2, magic links, and payment webhooks.
Changes:
- Adds
MAGIC_LINKas a new audit source in the database schema - Integrates audit event firing for booking confirmations and rejections across all entry points
- Updates payment webhook handlers to pass actor and action source information
- Adds comprehensive test coverage for the new audit functionality
- Implements bulk audit event support for recurring bookings
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/trpc/server/routers/viewer/bookings/confirm.handler.ts |
Main confirmation handler - integrates rejection audit events with a critical bug in oldStatus capture for recurring bookings |
packages/features/bookings/lib/handleConfirmation.ts |
Confirmation handler - integrates acceptance audit events with a critical bug in oldStatus for non-recurring bookings |
packages/trpc/server/routers/viewer/bookings/_router.tsx |
TRPC router - adds actor and actionSource to confirm handler inputs |
packages/prisma/schema.prisma |
Schema update - adds MAGIC_LINK to BookingAuditSource enum |
packages/prisma/migrations/20260107093019_add_magic_link_source/migration.sql |
Migration file for MAGIC_LINK enum value |
packages/features/booking-audit/lib/types/actionSource.ts |
Type updates - adds ValidActionSource schema without UNKNOWN |
packages/features/booking-audit/lib/actions/RejectedAuditActionService.ts |
Updates rejection action schema to use BookingStatusChangeSchema |
packages/features/bookings/lib/onBookingEvents/BookingEventHandlerService.ts |
Adds onBulkBookingsRejected method |
packages/features/booking-audit/lib/service/BookingAuditTaskerProducerService.ts |
Adds queueBulkRejectedAudit method |
packages/features/booking-audit/lib/service/BookingAuditProducerService.interface.ts |
Interface update with queueBulkRejectedAudit method and formatting |
packages/features/ee/payments/api/webhook.ts |
Stripe webhook - adds actor and actionSource to handleConfirmation calls |
packages/app-store/paypal/api/webhook.ts |
PayPal webhook - updates handlePaymentSuccess signature |
packages/app-store/hitpay/api/webhook.ts |
HitPay webhook - updates handlePaymentSuccess signature |
packages/app-store/btcpayserver/api/webhook.ts |
BTCPay webhook - updates handlePaymentSuccess signature |
packages/app-store/alby/api/webhook.ts |
Alby webhook - updates handlePaymentSuccess signature |
packages/app-store/_utils/payments/handlePaymentSuccess.ts |
Payment handler - changes signature to object parameter and adds audit support |
packages/app-store/_utils/getAppActor.ts |
New utility for creating app actors with credential fallback |
apps/web/app/api/verify-booking-token/route.ts |
Verification token handler - adds audit parameters |
apps/web/app/api/link/route.ts |
Link handler - adds audit parameters |
apps/api/v2/src/ee/bookings/2024-08-13/services/bookings.service.ts |
API v2 service - adds audit parameters to confirm/reject calls |
packages/platform/libraries/bookings.ts |
Exports makeUserActor for platform usage |
packages/features/booking-audit/lib/service/__tests__/accepted-action.integration-test.ts |
Comprehensive integration tests for accepted action auditing |
packages/app-store/_utils/payments/handlePaymentSuccess.test.ts |
Updates tests for new function signature |
apps/web/test/lib/confirm.handler.test.ts |
Comprehensive tests for both acceptance and rejection audit events |
apps/web/app/api/verify-booking-token/__tests__/route.test.ts |
Updates tests with audit parameters |
apps/web/app/api/link/__tests__/route.test.ts |
Updates tests with audit parameters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const updatedRecurringBookings = await prisma.booking.findMany({ | ||
| where: { | ||
| uid: { | ||
| in: unconfirmedRecurringBookings.map((booking) => booking.uid), | ||
| }, | ||
| }, | ||
| select: { | ||
| uid: true, | ||
| status: true, | ||
| }, | ||
| }); | ||
|
|
||
| rejectedBookings = updatedRecurringBookings.map((recurringBooking) => ({ |
There was a problem hiding this comment.
The oldStatus is incorrectly set after the database update. At this point, updatedRecurringBookings already have status REJECTED (from the previous updateMany call on lines 420-430), so oldStatus will incorrectly be REJECTED instead of PENDING. The oldStatus should be captured from unconfirmedRecurringBookings before the update, similar to how it's done in handleConfirmation.ts (lines 263-266).
| const updatedRecurringBookings = await prisma.booking.findMany({ | |
| where: { | |
| uid: { | |
| in: unconfirmedRecurringBookings.map((booking) => booking.uid), | |
| }, | |
| }, | |
| select: { | |
| uid: true, | |
| status: true, | |
| }, | |
| }); | |
| rejectedBookings = updatedRecurringBookings.map((recurringBooking) => ({ | |
| rejectedBookings = unconfirmedRecurringBookings.map((recurringBooking) => ({ |
| updatedBookings.push(updatedBooking); | ||
| acceptedBookings = [ | ||
| { | ||
| oldStatus: BookingStatus.ACCEPTED, |
There was a problem hiding this comment.
The oldStatus is hardcoded to BookingStatus.ACCEPTED, but this is incorrect. For a non-recurring booking acceptance, the oldStatus should be the booking's status before the update (likely PENDING). It should be set to booking.status, similar to how it's done correctly in the recurring case (line 264) and in the rejection path in confirm.handler.ts (line 471).
| oldStatus: BookingStatus.ACCEPTED, | |
| oldStatus: booking.status, |
Benchmark PR from agentic-review-benchmarks#10