feat: api v2 GET booking attendees endpoint (#27664)

* feat: add booking attendees endpoint to API v2

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

* feat: add rate limiting to booking attendees endpoint

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

* refactor: simplify attendees output to id, bookingId, name, email, timeZone

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

* test: add E2E tests for booking attendees endpoint

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

* chore: update bookings repository

* fixup: add pbac guards and update service logic

* chore: update openapi spec

* test: add rate limiting E2E test for booking attendees endpoint

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

* fix: tests

* fix: return 404 instead of 403 for non-existent booking in BookingPbacGuard

The BookingPbacGuard was returning 403 (Forbidden) for non-existent bookings
because doesUserIdHaveAccessToBooking returns false when a booking doesn't
exist, which the guard treated as an access denial.

Added an explicit booking existence check in the guard before the access
check, so non-existent bookings now correctly return 404 (Not Found) as
documented in the PR description.

Updated the E2E test to expect 404 for non-existent booking UIDs.

Issue identified by cubic.

Co-Authored-By: unknown <>

* fixup

* fix: return 404 instead of 403 for non-existent booking in attendees endpoint

BookingPbacGuard now checks booking existence before the access check,
returning 404 (Not Found) instead of 403 (Forbidden) for non-existent
booking UIDs. Updated the E2E test assertion and description to match.

Issue identified by cubic (confidence 9/10).

Co-Authored-By: unknown <>

* chore: implement PR feedback

* chore: update tests

* fixup

* chore: update endpoint decsription

* feat: endpoint to retrieve specific attendee

* chore: update e2e tests

* chore: implement cubic feedback

* fix: update test to expect 403 for non-existent booking UID (BookingPbacGuard behavior)

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

* fix: merge conflicts

* feat: endpoint to get attendees

* chore: update findByUidIncludeEventTypeAttendeesAndUser method

* chore: implement PR feedback

* fix: e2e tests

* chore: update e2e tests

* fixup fixup

* fix: remove phoneNumber assertion since it's optional and not provided in test

* chore: implement PR feedback

* fix: keep the same output shape for get attendees and get attendee endpoint

* chore: update openapi spec

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: bot_apk <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-03-06 09:50:29 +02:00
1 parent 658e65be4d
commit 5a7e783a0a
11 files changed
+906 -29

No files matched your search

@@ -493,11 +493,13 @@ export class BookingRepository implements IBookingRepository {
},
attendees: {
select: {
id: true,
email: true,
name: true,
timeZone: true,
locale: true,
phoneNumber: true,
noShow: true,
},
},
user: {
@@ -3,9 +3,16 @@ 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 { BookingEmailSmsHandler } from "@calcom/features/bookings/lib/BookingEmailSmsHandler";
import { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
import { ErrorCode } from "@calcom/lib/errorCodes";
import { ErrorWithCode } from "@calcom/lib/errors";
import logger from "@calcom/lib/logger";
import type { Booking, TUser } from "@calcom/trpc/server/routers/viewer/bookings/addGuests.handler";
import { prisma } from "@calcom/prisma";
import type {
Booking,
TUser,
} from "@calcom/trpc/server/routers/viewer/bookings/addGuests.handler";
import {
buildCalendarEvent,
getBooking,
@@ -41,6 +48,42 @@ export type CreatedAttendee = {
};
export class BookingAttendeesService {
async getBookingAttendees(bookingUid: string) {
const bookingRepository = new BookingRepository(prisma);
const booking =
await bookingRepository.findByUidIncludeEventTypeAttendeesAndUser({
bookingUid,
});
if (!booking) {
throw new Error(`Booking with uid ${bookingUid} not found`);
}
return booking.attendees;
}
async getBookingAttendee(bookingUid: string, attendeeId: number) {
const bookingRepository = new BookingRepository(prisma);
const booking =
await bookingRepository.findByUidIncludeEventTypeAttendeesAndUser({
bookingUid,
});
if (!booking) {
throw new Error(`Booking with uid ${bookingUid} not found`);
}
const attendee = booking.attendees.find((a) => a.id === attendeeId);
if (!attendee) {
throw new ErrorWithCode(
ErrorCode.NotFound,
`Attendee with id ${attendeeId} not found in booking ${bookingUid}`
);
}
return attendee;
}
async addAttendee({
bookingId,
attendee,
@@ -56,7 +99,10 @@ export class BookingAttendeesService {
const organizer = await getOrganizerData(booking.userId);
const validatedAttendees = await sanitizeAndFilterGuests([attendee], booking);
const validatedAttendees = await sanitizeAndFilterGuests(
[attendee],
booking
);
const newAttendeeDetails = validatedAttendees.map((a) => ({
name: a.name || "",
@@ -89,7 +135,10 @@ export class BookingAttendeesService {
const featuresRepository = getFeaturesRepository();
const organizationId = user.organizationId ?? null;
const isBookingAuditEnabled = organizationId
? await featuresRepository.checkIfTeamHasFeature(organizationId, "booking-audit")
? await featuresRepository.checkIfTeamHasFeature(
organizationId,
"booking-audit"
)
: false;
await bookingEventHandlerService.onAttendeeAdded({
@@ -134,7 +183,9 @@ export class BookingAttendeesService {
await emailsAndSmsHandler.handleAddAttendee({
evt,
eventType: {
metadata: eventTypeMetaDataSchemaWithTypedApps.parse(booking?.eventType?.metadata),
metadata: eventTypeMetaDataSchemaWithTypedApps.parse(
booking?.eventType?.metadata
),
schedulingType: booking.eventType?.schedulingType || null,
},
newGuests: [attendeeEmail],
@@ -291,11 +291,11 @@ class BaseBookingOutput_2024_08_13 {
}
export class BookingOutput_2024_08_13 extends BaseBookingOutput_2024_08_13 {
@ApiProperty({ type: [BookingAttendee] })
@ValidateNested({ each: true })
@Type(() => BookingAttendee)
@Expose()
attendees!: BookingAttendee[];
@ApiProperty({ type: [BookingAttendee] })
@ValidateNested({ each: true })
@Type(() => BookingAttendee)
@Expose()
attendees!: BookingAttendee[];
@ApiPropertyOptional({
type: [String],