Skip to content
Open
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad

### Added

- **Delete a booking for an erasure request.** Owners and admins can now permanently remove a
booking from the Bookings list (trash icon, confirmation dialog; `DELETE /v1/bookings/{id}`).
It removes the booking with its attendees, answers, manage links and host assignments, plus the
rows that name the person without a cascade: webhook deliveries and their queued jobs, reminder
jobs, idempotency records, transcripts and notes. It sends no email and fires no webhook.
Offered only where it is safe: an upcoming booking must be cancelled first (so the booker is
told and the calendar event goes); paid bookings keep their record; recordings must be deleted
first (they are files in object storage); and a cancelled booking whose calendar event removal
is still pending is refused until the reconciler has removed it. A past meeting's event stays on
the host's calendar, because removing it through the provider would email the guest; the
dialog says so. Database backups keep the data until their own retention ends.
- **German without du or Sie (`de-x-neutral`).** An opt-in wording variant of the German
booker catalogue that addresses nobody: "Tag auswählen" rather than "Wählen Sie einen
Tag". It is for operators whose own site is informal, where the formal widget stands out
Expand Down
17 changes: 16 additions & 1 deletion frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@
"hideResponses": "Hide responses",
"showResponses": "Show responses",
"reschedule": "Reschedule",
"cancel": "Cancel booking"
"cancel": "Cancel booking",
"delete": "Delete booking"
},
"cancelReschedule": "Cancel reschedule",
"details": {
Expand Down Expand Up @@ -221,6 +222,20 @@
"status": {
"confirmed": "confirmed",
"cancelled": "cancelled"
},
"confirmDelete": {
"title": "Delete this booking permanently?",
"description": "Removes the booking with the attendee's name, email and answers, for a data deletion request. No one is notified. A calendar event of a past meeting stays on your calendar; delete it there without notifying guests. This can't be undone.",
"confirm": "Delete permanently",
"cancel": "Keep booking"
},
"delete": {
"error": {
"cancel_first": "Cancel the upcoming booking first, then delete it.",
"paid_booking": "Paid bookings keep their record and cannot be deleted here.",
"recordings_first": "Delete the recordings of this booking first (Recordings).",
"calendar_pending": "The calendar event is still being removed. Try again in a few minutes."
}
}
},
"availability": {
Expand Down
17 changes: 16 additions & 1 deletion frontend/src/lib/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@
"hideResponses": "Masquer les réponses",
"showResponses": "Afficher les réponses",
"reschedule": "Reprogrammer",
"cancel": "Annuler la réservation"
"cancel": "Annuler la réservation",
"delete": "Supprimer la réservation"
},
"cancelReschedule": "Annuler la reprogrammation",
"details": {
Expand Down Expand Up @@ -221,6 +222,20 @@
"status": {
"confirmed": "confirmée",
"cancelled": "annulée"
},
"confirmDelete": {
"title": "Supprimer définitivement cette réservation ?",
"description": "Supprime la réservation avec le nom, l'e-mail et les réponses du participant, par exemple pour une demande d'effacement. Personne n'est notifié. L'événement d'une réunion passée reste dans votre agenda ; supprimez-le là-bas sans notifier les invités. Action irréversible.",
"confirm": "Supprimer définitivement",
"cancel": "Conserver la réservation"
},
"delete": {
"error": {
"cancel_first": "Annulez d'abord la réservation à venir, puis supprimez-la.",
"paid_booking": "Les réservations payées conservent leur trace et ne peuvent pas être supprimées ici.",
"recordings_first": "Supprimez d'abord les enregistrements de cette réservation (Enregistrements).",
"calendar_pending": "L'événement d'agenda est encore en cours de suppression. Réessayez dans quelques minutes."
}
}
},
"availability": {
Expand Down
55 changes: 55 additions & 0 deletions frontend/src/routes/bookings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,38 @@
}
}

// Permanent erasure for a data-deletion request (owner/admin only). Offered where the
// server can do it: cancelled or already-ended free bookings. The server re-checks and
// answers 409 with a code naming the step to take first (recordings, calendar pending).
let deleteOpen = $state(false);
let pendingDeleteId = $state<string | null>(null);
const deleteErrorCodes = ['cancel_first', 'paid_booking', 'recordings_first', 'calendar_pending'];

function canDelete(b: Booking): boolean {
if (!isAdmin || b.payment_status) return false;
return b.status === 'cancelled' || new Date(b.end_at).getTime() <= Date.now();
}

function requestDelete(id: string) {
pendingDeleteId = id;
deleteOpen = true;
}

async function deleteBooking() {
const id = pendingDeleteId;
if (!id) return;
try {
await api.del(`/v1/bookings/${id}`);
if (expandedId === id) expandedId = null;
await load();
} catch (e: any) {
error = deleteErrorCodes.includes(e.message) ? $t(`bookings.delete.error.${e.message}`) : e.message;
} finally {
deleteOpen = false;
pendingDeleteId = null;
}
}

function startReschedule(b: Booking) {
reschedulingId = b.id;
reschedulingSlug = b.event_type_slug ?? '';
Expand Down Expand Up @@ -516,6 +548,19 @@
</Tooltip.Root>
{/if}
{/if}

{#if canDelete(b)}
<Tooltip.Root>
<Tooltip.Trigger
class={buttonVariants({ variant: 'ghost', size: 'icon' })}
onclick={() => requestDelete(b.id)}
aria-label={$t('bookings.tooltip.delete')}
>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/><path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>
</Tooltip.Trigger>
<Tooltip.Content>{$t('bookings.tooltip.delete')}</Tooltip.Content>
</Tooltip.Root>
{/if}
</div>
</Tooltip.Provider>
</td>
Expand Down Expand Up @@ -667,3 +712,13 @@
destructive
onConfirm={cancel}
/>

<ConfirmDialog
bind:open={deleteOpen}
title={$t('bookings.confirmDelete.title')}
description={$t('bookings.confirmDelete.description')}
confirmText={$t('bookings.confirmDelete.confirm')}
cancelText={$t('bookings.confirmDelete.cancel')}
destructive
onConfirm={deleteBooking}
/>
114 changes: 114 additions & 0 deletions internal/booking/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package booking

import (
"context"
"database/sql"
"errors"
"fmt"
"time"
)

// Errors returned by Delete when a booking must not be erased yet. Each names the step
// that comes first, so the admin UI can say what to do instead of a bare refusal.
var (
// ErrDeleteUpcoming: a confirmed booking that has not ended yet. Deleting it would make
// the meeting vanish for the host while the booker still holds the invite; cancel it
// first (which tells the booker, removes the calendar event, refunds and fires the
// cancellation webhook), then delete.
ErrDeleteUpcoming = errors.New("booking: cancel the upcoming booking before deleting it")
// ErrDeletePaid: the booking carries a payment record. Payment records have their own
// retention duties, so this path refuses rather than silently dropping one.
ErrDeletePaid = errors.New("booking: a paid booking keeps its record")
// ErrDeleteRecordings: recordings are files in object storage; removing only the row
// would orphan the file. Delete them on the Recordings page first.
ErrDeleteRecordings = errors.New("booking: delete the booking's recordings first")
// ErrDeleteCalendarPending: the booking was cancelled but a host's calendar event is still
// recorded as present (removal failed and the reconciler will retry). Deleting the row now
// would lose the id needed to remove that event, leaving it on the calendar for good.
ErrDeleteCalendarPending = errors.New("booking: the cancelled booking's calendar event is still being removed")
)

// Delete permanently erases a booking and the personal data stored with it, for an
// erasure request (GDPR Art. 17). It sends no email and fires no webhook: the person
// asked for their data to be removed, not to be told about a cancellation.
//
// Removed in one transaction:
// - the booking row, and by ON DELETE CASCADE its attendees, form answers, manage
// tokens and host assignments;
// - rows that reference it without a cascade: webhook deliveries (their payload holds
// the attendee's name and email) and the jobs that would deliver them, reminder jobs,
// idempotency records (their stored response holds the booking), transcripts and notes.
//
// Not touched: a calendar event that still exists for a past booking stays on the host's
// calendar (removing it through the provider would email the guest a cancellation), and
// database backups keep the data until their own retention ends. Both are documented for
// the operator.
func (s *Service) Delete(ctx context.Context, id string, now time.Time) error {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return fmt.Errorf("booking: delete: begin: %w", err)
}
defer func() { _ = tx.Rollback() }()

var status, endStr, paymentStatus string
err = tx.QueryRowContext(ctx,
`SELECT status, end_at, payment_status FROM bookings WHERE id = ?`, id).
Scan(&status, &endStr, &paymentStatus)
if errors.Is(err, sql.ErrNoRows) {
return ErrNotFound
}
if err != nil {
return fmt.Errorf("booking: delete: load: %w", err)
}
endAt, err := time.Parse(time.RFC3339Nano, endStr)
if err != nil {
return fmt.Errorf("booking: delete: parse end_at %q: %w", endStr, err)
}
if status != "cancelled" && endAt.After(now) {
return ErrDeleteUpcoming
}
if paymentStatus != "" && paymentStatus != "none" {
return ErrDeletePaid
}

var n int
if err := tx.QueryRowContext(ctx,
`SELECT COUNT(*) FROM recordings WHERE booking_id = ?`, id).Scan(&n); err != nil {
return fmt.Errorf("booking: delete: count recordings: %w", err)
}
if n > 0 {
return ErrDeleteRecordings
}
if status == "cancelled" {
if err := tx.QueryRowContext(ctx, `
SELECT COUNT(*) FROM booking_hosts
WHERE booking_id = ? AND COALESCE(external_event_id, '') != ''`, id).Scan(&n); err != nil {
return fmt.Errorf("booking: delete: count calendar events: %w", err)
}
if n > 0 {
return ErrDeleteCalendarPending
}
}

// Order matters: jobs point at webhook deliveries by id inside their JSON payload, and
// webhook_deliveries.booking_id references bookings without a cascade.
steps := []struct{ what, query string }{
{"webhook jobs", `DELETE FROM jobs WHERE type = 'webhook.deliver'
AND json_extract(payload, '$.webhook_delivery_id') IN (SELECT id FROM webhook_deliveries WHERE booking_id = ?)`},
{"booking jobs", `DELETE FROM jobs WHERE json_valid(payload) AND json_extract(payload, '$.booking_id') = ?`},
{"webhook deliveries", `DELETE FROM webhook_deliveries WHERE booking_id = ?`},
{"idempotency keys", `DELETE FROM idempotency_keys WHERE booking_id = ?`},
{"transcripts", `DELETE FROM transcripts WHERE booking_id = ?`},
{"notes", `DELETE FROM notes WHERE booking_id = ?`},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meeting_consents stores the display name each participant types into the LiveKit room, keyed by room = 'booking-<id>', and nothing deletes those rows: not the recording deletion the recordings_first refusal sends the admin to, and not this transaction. So a successful delete returns 204 while the person's name is still in the database — the outcome this feature exists to prevent. Add a step for the booking's room and seed a consent row in the handler test.

Technical details
# meeting_consents is not part of the erasure

## Affected sites
- internal/booking/delete.go:95-103 — the steps slice removes jobs, webhook deliveries, idempotency keys, transcripts and notes, but not meeting_consents
- internal/db/migrations/00044_meeting_consents.sql:5 — keyed (room, participant_identity); no FK to bookings, so the cascade never reaches it
- internal/handler/livekit_recording.go:207 — the only writer; room is `booking-<id>` (internal/handler/booking_handler.go:1168)
- internal/handler/livekit_recording.go:439 — `deleteRecordingArtifacts` removes the file, transcripts, notes and the recordings row only; there is no `DELETE FROM meeting_consents` anywhere in the repo

## Required outcome
- After `Delete` commits, no `meeting_consents` row remains for the booking's room.
- `internal/handler/booking_delete_test.go` seeds a consent row for the booking room and asserts it is gone (the fixture currently never creates one).

## Suggested approach
- Add `{"meeting consents", `DELETE FROM meeting_consents WHERE room = 'booking-' || ?`}` to the steps slice, before the bookings delete.

## Open question
- The room holds hosts and attendees alike; erasing the whole room's consent log is the simplest reading of the erasure request, but confirm that is the intent.
Suggested change
{"notes", `DELETE FROM notes WHERE booking_id = ?`},
{"notes", `DELETE FROM notes WHERE booking_id = ?`},
{"meeting consents", `DELETE FROM meeting_consents WHERE room = 'booking-' || ?`},

{"booking", `DELETE FROM bookings WHERE id = ?`},
}
for _, step := range steps {
if _, err := tx.ExecContext(ctx, step.query, id); err != nil {
return fmt.Errorf("booking: delete %s: %w", step.what, err)
}
}
if err := tx.Commit(); err != nil {
return fmt.Errorf("booking: delete: commit: %w", err)
}
return nil
}
Loading
Loading