Repository navigation
Delete a booking for a GDPR erasure request #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mehr-Vertrieb
wants to merge
1
commit into
Calnode:main
Choose a base branch
from
Mehr-Vertrieb:delete-booking-erasure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = ?`}, | ||
| {"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 | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meeting_consentsstores the display name each participant types into the LiveKit room, keyed byroom = 'booking-<id>', and nothing deletes those rows: not the recording deletion therecordings_firstrefusal sends the admin to, and not this transaction. So a successful delete returns204while 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