From e2cc7198c69635c9707a9a780c4aa2e1559f7f3b Mon Sep 17 00:00:00 2001 From: MinosChatzidakis Date: Wed, 23 Sep 2026 18:54:50 +0300 Subject: [PATCH] fix(bookings): attribute cancellation reason server-side (#61) --- frontend/src/routes/bookings/+page.svelte | 2 +- internal/handler/booking_handler.go | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/bookings/+page.svelte b/frontend/src/routes/bookings/+page.svelte index 6955d0a8..099b3785 100644 --- a/frontend/src/routes/bookings/+page.svelte +++ b/frontend/src/routes/bookings/+page.svelte @@ -207,7 +207,7 @@ const id = pendingCancelId; if (!id) return; try { - await api.post(`/v1/bookings/${id}/cancel`, { reason: 'cancelled by admin' }); + await api.post(`/v1/bookings/${id}/cancel`, {}); await load(); } catch (e: any) { error = e.message; diff --git a/internal/handler/booking_handler.go b/internal/handler/booking_handler.go index ba7f8019..7c940d6f 100644 --- a/internal/handler/booking_handler.go +++ b/internal/handler/booking_handler.go @@ -1625,13 +1625,31 @@ func (h *Handler) CancelBooking(w http.ResponseWriter, r *http.Request) { // Ignore decode errors — reason is optional. _ = json.NewDecoder(r.Body).Decode(&req) + + actor := user.Name + if actor == "" { + actor = user.Email + } + if actor == "" { + actor = "host" + } + + // Compose the attribution server-side. + // Ignore legacy hardcoded "cancelled by admin" from older frontend builds. + reason := fmt.Sprintf("Cancelled by %s", actor) + cleanReason := strings.TrimSpace(req.Reason) + if cleanReason != "" && !strings.EqualFold(cleanReason, "cancelled by admin") { + reason = fmt.Sprintf("%s: %s", reason, cleanReason) + } + + // Admins (and the owner) may cancel any booking — needed to resolve a // departing member's meetings. Non-admin hosts can cancel only their own. var cancelErr error if user.IsAdmin { - cancelErr = h.bookingSvc.CancelByID(r.Context(), id, req.Reason) + cancelErr = h.bookingSvc.CancelByID(r.Context(), id, reason) } else { - cancelErr = h.bookingSvc.Cancel(r.Context(), user.ID, id, req.Reason) + cancelErr = h.bookingSvc.Cancel(r.Context(), user.ID, id, reason) } if err := cancelErr; err != nil { switch {