Skip to content

Commit bf0fbe4

Browse files
feat: skip authentication check for reschedule bookings with validation (calcom#24903)
* feat: skip authentication check for reschedule bookings with validation - Skip checkBookingRequiresAuthentication when rescheduleUid is present - Add validation to ensure rescheduleUid points to a real booking - Verify booking status is ACCEPTED (upcoming) - Verify booking uses the same event-type - Throw appropriate errors for invalid reschedule attempts Co-Authored-By: morgan@cal.com <morgan@cal.com> * refactor: move reschedule validation logic into checkBookingRequiresAuthentication - Refactor checkBookingRequiresAuthentication to accept optional rescheduleUid parameter - Move reschedule booking validation logic inside the method - Simplify createBooking method by removing duplicate validation code - Maintain same validation logic: check booking exists, is ACCEPTED, and uses same event-type Co-Authored-By: morgan@cal.com <morgan@cal.com> * fix: allow PENDING bookings to be rescheduled - Update status validation to allow both ACCEPTED and PENDING bookings - Change error message to reflect both allowed statuses - PENDING bookings can now be rescheduled without authentication check Co-Authored-By: morgan@cal.com <morgan@cal.com> * refactor: separate reschedule validation from auth check - Extract validateRescheduleBooking method to handle reschedule-specific validation - Keep checkBookingRequiresAuthentication strictly for auth checks - Use conditional logic in createBooking: validate reschedule OR check auth - Improves code clarity by separating concerns per lauris's feedback Co-Authored-By: morgan@cal.com <morgan@cal.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent eb6418c commit bf0fbe4

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

apps/api/v2/src/ee/bookings/2024-04-15/controllers/bookings.controller.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ export class BookingsController_2024_04_15 {
205205
clientId?.toString() || (await this.getOAuthClientIdFromEventType(body.eventTypeId));
206206
const { orgSlug, locationUrl } = body;
207207
try {
208-
await this.checkBookingRequiresAuthentication(req, body.eventTypeId);
208+
if (body.rescheduleUid) {
209+
await this.validateRescheduleBooking(body.rescheduleUid, body.eventTypeId);
210+
} else {
211+
await this.checkBookingRequiresAuthentication(req, body.eventTypeId);
212+
}
209213
const bookingRequest = await this.createNextApiBookingRequest(req, oAuthClientId, locationUrl, isEmbed);
210214
const booking = await this.regularBookingService.createBooking({
211215
bookingData: bookingRequest.body,
@@ -459,6 +463,25 @@ export class BookingsController_2024_04_15 {
459463
return oAuthClientParams.platformClientId;
460464
}
461465

466+
private async validateRescheduleBooking(rescheduleUid: string, eventTypeId: number): Promise<void> {
467+
const { bookingInfo } = await getBookingInfo(rescheduleUid);
468+
if (!bookingInfo) {
469+
throw new NotFoundException(
470+
`Booking with UID=${rescheduleUid} does not exist. Cannot reschedule a non-existent booking.`
471+
);
472+
}
473+
if (bookingInfo.status !== "ACCEPTED" && bookingInfo.status !== "PENDING") {
474+
throw new BadRequestException(
475+
`Booking with UID=${rescheduleUid} has invalid status (status: ${bookingInfo.status}). Only ACCEPTED or PENDING bookings can be rescheduled.`
476+
);
477+
}
478+
if (bookingInfo.eventTypeId !== eventTypeId) {
479+
throw new BadRequestException(
480+
`Booking with UID=${rescheduleUid} is for a different event type (eventTypeId: ${bookingInfo.eventTypeId}). Cannot reschedule to a different event type (eventTypeId: ${eventTypeId}).`
481+
);
482+
}
483+
}
484+
462485
private async checkBookingRequiresAuthentication(req: Request, eventTypeId: number): Promise<void> {
463486
const eventType = await this.eventTypeRepository.findByIdIncludeHostsAndTeamMembers({
464487
id: eventTypeId,

0 commit comments

Comments
 (0)