fix: (booking-audit) Remove IS_PRODUCTION gate and add feature flag check in producer (#26524)

* fix: remove IS_PRODUCTION gate from BookingAuditProducer

Remove the IS_PRODUCTION check that was preventing booking audits from
being queued in production. Audits are still properly gated by:

1. Organization check: Audits are skipped for non-organization bookings
   (organizationId === null)
2. Feature flag: The BookingAuditTaskConsumer checks if the 'booking-audit'
   feature is enabled for the organization via featuresRepository.checkIfTeamHasFeature()

The IS_PRODUCTION gate was intentionally added to prevent logs from being
created in production while the action data versioning was being actively
reviewed and finalized. Without proper versioning handling, the Booking
History UI could crash when encountering unversioned data. Now that the
versioning system is in place, this gate can be safely removed.

Co-Authored-By: [email protected] <[email protected]>

* fix: revert formatting, keep only IS_PRODUCTION removal

Reverts the unintended formatting changes from the previous commit.
Only removes the IS_PRODUCTION gate without changing indentation.

Co-Authored-By: [email protected] <[email protected]>

* feat: add booking-audit feature flag check in producer to avoid unnecessary task creation

- Query booking-audit and booking-email-sms-tasker flags in parallel before fireBookingEvents
- Pass isBookingAuditEnabled through BookingEventHandler to producer's queueTask method
- Add conditional check in queueTask with debug log when skipping audit
- Reuse pre-queried isBookingEmailSmsTaskerEnabled flag instead of querying again

Co-Authored-By: [email protected] <[email protected]>

* feat: make isBookingAuditEnabled required and pass it through all booking audit flows

- Make isBookingAuditEnabled a required property in BookingAuditProducerService interface
- Update all BookingEventHandler methods to require isBookingAuditEnabled
- Add feature flag check in all flows that call booking audit:
  - handleSeats (seat booking/rescheduling)
  - RecurringBookingService (bulk bookings)
  - handleCancelBooking (booking cancellation)
  - handleConfirmation (booking acceptance)
  - roundRobinReassignment (automatic reassignment)
  - roundRobinManualReassignment (manual reassignment)
  - trpc handlers: addGuests, confirm, editLocation, requestReschedule
- Skip queueing audit tasks when feature is disabled with debug logging

Co-Authored-By: [email protected] <[email protected]>

* fix: add featuresRepository dependency to RecurringBookingService DI module

Co-Authored-By: [email protected] <[email protected]>

* refactor: make isBookingAuditEnabled optional for non-main flows

Keep feature flag check only in main flows (handleSeats, RegularBookingService, RecurringBookingService) which are frequently triggered. For other flows (handleCancelBooking, handleConfirmation, roundRobinReassignment, etc.), rely on the existing consumer-level check.

Changes:
- Revert feature flag check from non-main flows
- Make isBookingAuditEnabled optional in interface for non-main flow methods
- Keep isBookingAuditEnabled required for main flow methods (queueCreatedAudit, queueRescheduledAudit, queueSeatBookedAudit, queueSeatRescheduledAudit, queueBulkCreatedAudit, queueBulkRescheduledAudit)
- Update BookingEventHandlerService to use required params for main flows and optional for non-main flows

Co-Authored-By: [email protected] <[email protected]>

* refactor: remove isBookingAuditEnabled from non-main flow methods

Co-Authored-By: [email protected] <[email protected]>

* feat: make isBookingAuditEnabled required in all BookingEventHandlerService methods

- Add isBookingAuditEnabled as required parameter in all BookingAuditProducerService interface methods
- Update BookingAuditTaskerProducerService to use simplified check (!params.isBookingAuditEnabled)
- Update BookingEventHandlerService to require isBookingAuditEnabled in all methods
- Update all callers to query booking-audit feature flag and pass isBookingAuditEnabled:
  - handleCancelBooking
  - handleConfirmation
  - roundRobinReassignment
  - roundRobinManualReassignment
  - addGuests.handler
  - confirm.handler
  - editLocation.handler
  - requestReschedule.handler
- Inject featuresRepository in API V2's booking-location.service.ts

Co-Authored-By: [email protected] <[email protected]>

* test: update roundRobinReassignment tests to include isBookingAuditEnabled

Co-Authored-By: [email protected] <[email protected]>

* test: update roundRobinManualReassignment tests to include isBookingAuditEnabled

Co-Authored-By: [email protected] <[email protected]>

* fix: inject featuresRepository in API V2 RecurringBookingService

Co-Authored-By: [email protected] <[email protected]>

* fix: import PrismaWorkerModule for PrismaFeaturesRepository dependency

Co-Authored-By: [email protected] <[email protected]>

* fix: use booking's organization for feature flag check in addGuests handler

Use booking.user?.profiles?.[0]?.organizationId instead of user.organizationId
to check the booking-audit feature flag. This ensures the feature flag is
checked against the booking's organization rather than the actor's organization,
which is consistent with other handlers in this PR.

Addresses Cubic AI review feedback (confidence 9/10).

Co-Authored-By: unknown <>

* Add comment

* fix: use user.organizationId for feature flag check in addGuests handler

Co-Authored-By: [email protected] <[email protected]>

* fix: use booking's organizationId for feature flag check in addGuests handler

Co-Authored-By: [email protected] <[email protected]>

* fix: revert to user.organizationId for feature flag check in addGuests handler

Co-Authored-By: [email protected] <[email protected]>

* fix: add isBookingAuditEnabled to onNoShowUpdated calls after main merge

Co-Authored-By: [email protected] <[email protected]>

* fix: add isBookingAuditEnabled to onNoShowUpdated calls and update tests

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-02-09 09:25:33 -03:00
1 parent b1b73f7fcc
commit e04a394e1c
25 files changed
+342 -103

No files matched your search

@@ -4,6 +4,7 @@ import dayjs from "@calcom/dayjs";
import { makeUserActor } from "@calcom/features/booking-audit/lib/makeActor";
import type { ActionSource } from "@calcom/features/booking-audit/lib/types/actionSource";
import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
import { BookingEmailSmsHandler } from "@calcom/features/bookings/lib/BookingEmailSmsHandler";
import EventManager from "@calcom/features/bookings/lib/EventManager";
import { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
@@ -88,14 +89,21 @@ export const addGuestsHandler = async ({
}
const bookingEventHandlerService = getBookingEventHandlerService();
const featuresRepository = getFeaturesRepository();
const organizationId = user.organizationId ?? null;
const isBookingAuditEnabled = organizationId
? await featuresRepository.checkIfTeamHasFeature(organizationId, "booking-audit")
: false;
await bookingEventHandlerService.onAttendeeAdded({
bookingUid: booking.uid,
actor: makeUserActor(user.uuid),
organizationId: user.organizationId ?? null,
organizationId,
source: actionSource,
auditData: {
added: uniqueGuestEmails,
},
isBookingAuditEnabled,
});
return { message: "Guests added" };
@@ -3,6 +3,7 @@ import type { LocationObject } from "@calcom/app-store/locations";
import { getLocationValueForDB } from "@calcom/app-store/locations";
import { sendDeclinedEmailsAndSMS } from "@calcom/emails/email-manager";
import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
import { getAllCredentialsIncludeServiceAccountKey } from "@calcom/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials";
import { getAssignmentReasonCategory } from "@calcom/features/bookings/lib/getAssignmentReasonCategory";
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
@@ -55,6 +56,7 @@ async function fireRejectionEvent({
actionSource,
rejectedBookings,
rejectionReason,
isBookingAuditEnabled,
tracingLogger,
}: {
actor: Actor;
@@ -65,6 +67,7 @@ async function fireRejectionEvent({
uid: string;
oldStatus: BookingStatus;
}[];
isBookingAuditEnabled: boolean;
tracingLogger: ISimpleLogger;
}): Promise<void> {
try {
@@ -83,6 +86,7 @@ async function fireRejectionEvent({
organizationId,
operationId,
source: actionSource,
isBookingAuditEnabled,
});
} else if (rejectedBookings.length === 1) {
const booking = rejectedBookings[0];
@@ -95,6 +99,7 @@ async function fireRejectionEvent({
status: { old: booking.oldStatus, new: BookingStatus.REJECTED },
},
source: actionSource,
isBookingAuditEnabled,
});
}
} catch (error) {
@@ -495,12 +500,18 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
const orgId = await getOrgIdFromMemberOrTeamId({ memberId: booking.userId, teamId });
const featuresRepository = getFeaturesRepository();
const isBookingAuditEnabled = orgId
? await featuresRepository.checkIfTeamHasFeature(orgId, "booking-audit")
: false;
await fireRejectionEvent({
actor,
actionSource,
organizationId: orgId ?? null,
rejectionReason: rejectionReason ?? null,
rejectedBookings,
isBookingAuditEnabled,
tracingLogger: log,
});
@@ -5,6 +5,7 @@ import { sendLocationChangeEmailsAndSMS } from "@calcom/emails/email-manager";
import { makeUserActor } from "@calcom/features/booking-audit/lib/makeActor";
import type { ValidActionSource } from "@calcom/features/booking-audit/lib/types/actionSource";
import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
import EventManager from "@calcom/features/bookings/lib/EventManager";
import { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
import { CredentialRepository } from "@calcom/features/credentials/repositories/CredentialRepository";
@@ -315,6 +316,11 @@ export async function editLocationHandler({ ctx, input, actionSource }: EditLoca
}
const bookingEventHandlerService = getBookingEventHandlerService();
const featuresRepository = getFeaturesRepository();
const isBookingAuditEnabled = organizationId
? await featuresRepository.checkIfTeamHasFeature(organizationId, "booking-audit")
: false;
await bookingEventHandlerService.onLocationChanged({
bookingUid: booking.uid,
actor: makeUserActor(loggedInUser.uuid),
@@ -326,6 +332,7 @@ export async function editLocationHandler({ ctx, input, actionSource }: EditLoca
new: updatedLocation,
},
},
isBookingAuditEnabled,
});
return { message: "Location updated" };
@@ -8,6 +8,7 @@ import { sendRequestRescheduleEmailAndSMS } from "@calcom/emails/email-manager";
import { makeUserActor } from "@calcom/features/booking-audit/lib/makeActor";
import type { ActionSource } from "@calcom/features/booking-audit/lib/types/actionSource";
import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
import { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
import { deleteMeeting } from "@calcom/features/conferencing/lib/videoClient";
@@ -315,6 +316,11 @@ export const requestRescheduleHandler = async ({ ctx, input, source }: RequestRe
await Promise.all(promises);
const bookingEventHandlerService = getBookingEventHandlerService();
const featuresRepository = getFeaturesRepository();
const isBookingAuditEnabled = orgId
? await featuresRepository.checkIfTeamHasFeature(orgId, "booking-audit")
: false;
await bookingEventHandlerService.onRescheduleRequested({
bookingUid: bookingToReschedule.uid,
actor: makeUserActor(user.uuid),
@@ -324,5 +330,6 @@ export const requestRescheduleHandler = async ({ ctx, input, source }: RequestRe
rescheduleReason: cancellationReason ?? null,
rescheduledRequestedBy: user.email,
},
isBookingAuditEnabled,
});
};