Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions apps/web/components/booking/CancelBooking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ export default function CancelBooking(props: Props) {

const cancellationNoShowFeeWarning = autoChargeNoShowFee();

const isCancellationUserHost =
props.isHost || bookingCancelledEventProps.organizer.email === currentUserEmail;

const hostMissingCancellationReason =
props.isHost &&
isCancellationUserHost &&
(!cancellationReason?.trim() || (props.internalNotePresets.length > 0 && !internalNote?.id));
const cancellationNoShowFeeNotAcknowledged =
!props.isHost && cancellationNoShowFeeWarning && !acknowledgeCancellationNoShowFee;
Expand Down Expand Up @@ -211,7 +214,7 @@ export default function CancelBooking(props: Props) {
</>
)}

<Label>{props.isHost ? t("cancellation_reason_host") : t("cancellation_reason")}</Label>
<Label>{isCancellationUserHost ? t("cancellation_reason_host") : t("cancellation_reason")}</Label>

<TextArea
data-testid="cancel_reason"
Expand All @@ -222,7 +225,7 @@ export default function CancelBooking(props: Props) {
className="mb-4 mt-2 w-full "
rows={3}
/>
{props.isHost ? (
{isCancellationUserHost ? (
<div className="-mt-2 mb-4 flex items-center gap-2">
<Icon name="info" className="text-subtle h-4 w-4" />
<p className="text-default text-subtle text-sm leading-none">
Expand Down Expand Up @@ -296,11 +299,13 @@ export default function CancelBooking(props: Props) {
});
refreshData();
} else {
const data = await res.json();
setLoading(false);
setError(
`${t("error_with_status_code_occured", { status: res.status })} ${t(
"please_try_again"
)}`
data.message ||
`${t("error_with_status_code_occured", { status: res.status })} ${t(
"please_try_again"
)}`
);
}
}}
Expand Down
5 changes: 4 additions & 1 deletion packages/features/bookings/lib/handleCancelBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ async function handler(input: CancelBookingInput) {
});
}

if (!platformClientId && !cancellationReason?.trim() && bookingToDelete.userId == userId) {
const isCancellationUserHost =
bookingToDelete.userId == userId || bookingToDelete.user.email === cancelledBy;

if (!platformClientId && !cancellationReason?.trim() && isCancellationUserHost) {
throw new HttpError({
statusCode: 400,
message: "Cancellation reason is required when you are the host",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ describe("Cancel Booking", () => {
id: idOfBookingToBeCancelled,
uid: uidOfBookingToBeCancelled,
cancelledBy: organizer.email,
cancellationReason: "No reason",
},
});

Expand Down Expand Up @@ -261,6 +262,7 @@ describe("Cancel Booking", () => {
id: idOfBookingToBeCancelled,
uid: uidOfBookingToBeCancelled,
cancelledBy: organizer.email,
cancellationReason: "No reason",
},
});

Expand Down Expand Up @@ -510,6 +512,74 @@ describe("Cancel Booking", () => {
).rejects.toThrow("Cannot cancel a booking that has already ended");
});

test("Should block canceling bookings without a cancellation reason when cancelledBy is set to the host", async () => {
const handleCancelBooking = (await import("@calcom/features/bookings/lib/handleCancelBooking")).default;

const booker = getBooker({
email: "booker@example.com",
name: "Booker",
});

const organizer = getOrganizer({
name: "Organizer",
email: "organizer@example.com",
id: 101,
schedules: [TestData.schedules.IstWorkHours],
credentials: [getGoogleCalendarCredential()],
selectedCalendars: [TestData.selectedCalendars.google],
});

const uidOfBookingToBeCancelled = "cancelled-booking";
const idOfBookingToBeCancelled = 3040;
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });

await createBookingScenario(
getScenarioData({
eventTypes: [
{
id: 1,
slotInterval: 30,
length: 30,
users: [
{
id: 101,
},
],
},
],
bookings: [
{
id: idOfBookingToBeCancelled,
uid: uidOfBookingToBeCancelled,
eventTypeId: 1,
userId: 101,
responses: {
email: booker.email,
name: booker.name,
location: { optionValue: "", value: BookingLocations.CalVideo },
},
status: BookingStatus.ACCEPTED,
startTime: `${plus1DateString}T05:00:00.000Z`,
endTime: `${plus1DateString}T05:30:00.000Z`,
},
],
organizer,
apps: [TestData.apps["daily-video"]],
})
);

// This should throw an error with current implementation
await expect(
handleCancelBooking({
bookingData: {
id: idOfBookingToBeCancelled,
uid: uidOfBookingToBeCancelled,
cancelledBy: organizer.email,
},
})
).rejects.toThrow("Cancellation reason is required when you are the host");
});

test("Should not charge cancellation fee when organizer cancels booking", async () => {
const handleCancelBooking = (await import("@calcom/features/bookings/lib/handleCancelBooking")).default;

Expand Down Expand Up @@ -615,6 +685,7 @@ describe("Cancel Booking", () => {
id: idOfBookingToBeCancelled,
uid: uidOfBookingToBeCancelled,
cancelledBy: organizer.email,
cancellationReason: "No reason",
},
});

Expand Down Expand Up @@ -747,6 +818,7 @@ describe("Cancel Booking", () => {
id: idOfBookingToBeCancelled,
uid: uidOfBookingToBeCancelled,
cancelledBy: organizer.email,
cancellationReason: "No reason",
},
});

Expand Down
Loading