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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad
deliveries. Migration `00075` normalises `bookings.updated_at` to whole-second RFC 3339 and
hands it to triggers, so every change to a booking (payment transitions, meeting links,
RSVPs included) now moves it.
- **Redirect after booking.** An event type can send the booker to a page of your own once
a booking is confirmed (Event type → General, `redirect_url`), typically a thank-you page
where site analytics count the conversion, optionally with `?booking_id=` appended. The
booking page shows a "Continue" button and moves on after a moment, also after paying
through Stripe. The embedded widget never leaves the host site: it offers "Continue" in a
new tab instead. Only absolute `https://` URLs without credentials are accepted, checked
when saved, when served and again in the browser. Migration `00077` adds the columns.
- **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
Expand Down
2 changes: 2 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ The `phone_outbound` location type ("we'll call you") is the outbound counterpar

A confirmed booking is a **final state** on all three booking surfaces (#268). A page that kept its calendar live and re-enabled its submit button after confirming invited a second booking under a different email, which `max_active_bookings` cannot catch. On `book.html`, `finalize()` (on success, and on the return from Stripe Checkout) disables the calendar, month navigation, timezone and submit, resets the form, and every handler checks the `finalized` flag rather than relying on the markup alone; a `submitting` flag also drops a second submit while the first request is in flight. "Book another time" is a fresh load of the page without the Stripe return parameters, so no picked day, slot or host state survives. The embed widget renders its calendar disabled while `state.view === 'confirm'` and refuses a second submit; its "Book another time" resets the widget's own state and reloads the month, never navigating the host page. On `manage.html` the success views (rescheduled, cancelled) are final: `showView` no longer leaves them and neither action can be sent again, because the page's times describe the booking as it was; a reload shows it as it now is. `TestBookPage_confirmationIsFinal` runs book.html's real page script under node against a small fake DOM (`testdata/book_final_state.js`) to check that a second submit sends nothing; the widget and manage page are pinned at source level.

An event type can set a **post-booking redirect** (`redirect_url`, `redirect_with_booking_id`, migration 00077, #268), typically the operator's own thank-you page, where site analytics count the conversion. Although admin-configured, it is an open-redirect surface, so it is checked three times: `validRedirectURL` when the event type is saved (absolute https, a host, no credentials: `https://trusted.example@evil.example/` reads as one site and goes to another; no whitespace or control characters; at most 2000 characters), `servedRedirectURL` when a page or the widget is given it (a stored value that no longer passes is served as no redirect and logged), and `redirectTarget` in the browser right before use (`booking-logic.js`, mirrored in `embed.js`). `redirect_with_booking_id` appends `?booking_id=`; it is off by default because the booking id is a lookup key (`GET /v1/bookings/{id}` is public). On `book.html`, `finalize()` shows a "Continue" button and navigates after a short delay (`REDIRECT_DELAY_MS`), which leaves time for the dataLayer/GA4 conversion pushed right after it; this covers the return from Stripe Checkout too, whose success URL carries `booking_id` for that purpose. The **embed widget never navigates the host page**: its confirmation offers "Continue", which opens the redirect in a new tab (`noopener`). The manage page does not redirect: a reschedule or a cancellation is not a conversion.

`internal/booking/service.go` (transactions) + `internal/handler/booking_handler.go`
(HTTP + async side effects).

Expand Down
6 changes: 6 additions & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export type EventType = {
/** List the attendee's intake answers in each host's new-booking email. Off by
* default; never added to the attendee's emails or the calendar event. */
answers_in_host_email: boolean;
/** Where the booking page sends the booker after a confirmed booking (absolute https,
* no credentials). Absent/null = no redirect. The embed widget only offers it as a
* "Continue" button that opens a new tab. */
redirect_url?: string | null;
/** Append ?booking_id=<id> to redirect_url. */
redirect_with_booking_id: boolean;
/** Show the next free time above the booking page's time list, as a button that
* opens that day. Off by default. */
show_next_available: boolean;
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,9 @@
"showTaken": "Show booked times as unavailable",
"showTakenHint": "Booked times appear struck through on the booking page instead of being hidden, so visitors can see the calendar filling up. Only times inside your working hours are shown, never the rest of your day.",
"showTakenWarning": "Anyone with the booking link can see which hours are taken.",
"redirectUrl": "Redirect after booking (optional)",
"redirectUrlHint": "After a confirmed booking, the booking page sends the booker here, for example your own thank-you page. Must start with https://. The embedded widget never leaves your site: it shows a Continue button that opens this page in a new tab.",
"redirectWithBookingId": "Add the booking ID to the address (?booking_id=…)",
"showNextAvailable": "Show the next available time",
"showNextAvailableHint": "Adds a button above the time list, such as \"Next available: Wed, Nov 18, 10:00 AM\", that opens that day. It uses the same times a visitor can already see.",
"allowPhoneCall": "Let invitees choose a phone call by entering their number"
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,9 @@
"showTaken": "Afficher les horaires réservés comme indisponibles",
"showTakenHint": "Les horaires réservés apparaissent barrés sur la page de réservation au lieu d'être masqués, afin que les visiteurs voient le calendrier se remplir. Seuls les horaires dans vos heures de travail sont affichés, jamais le reste de votre journée.",
"showTakenWarning": "Quiconque dispose du lien de réservation peut voir quels horaires sont pris.",
"redirectUrl": "Redirection après la réservation (facultatif)",
"redirectUrlHint": "Après une réservation confirmée, la page de réservation y envoie la personne, par exemple vers votre page de remerciement. Doit commencer par https://. Le widget intégré ne quitte jamais votre site : il affiche un bouton Continuer qui ouvre cette page dans un nouvel onglet.",
"redirectWithBookingId": "Ajouter l'identifiant de réservation à l'adresse (?booking_id=…)",
"showNextAvailable": "Afficher le prochain horaire disponible",
"showNextAvailableHint": "Ajoute au-dessus de la liste des horaires un bouton, par exemple « Prochain créneau disponible : mer. 18 nov., 10:00 », qui ouvre ce jour. Il utilise les mêmes horaires que ceux déjà visibles par un visiteur.",
"allowPhoneCall": "Permettre aux invités de choisir un appel téléphonique en saisissant leur numéro"
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/routes/event-types/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
display_order: 0,
name: '', slug: '', description: '', duration_minutes: 30, slot_interval_minutes: 30,
is_active: true, is_public: true, show_taken_slots: false, show_next_available: false,
redirect_url: '', redirect_with_booking_id: false,
invite_delivery: 'calendar' as EventType['invite_delivery'],
location_type: 'link', location_value: '',
buffer_before_minutes: 0, buffer_after_minutes: 0,
Expand Down Expand Up @@ -337,6 +338,8 @@
is_active: et.is_active,
is_public: et.is_public,
show_taken_slots: et.show_taken_slots ?? false,
redirect_url: et.redirect_url ?? '',
redirect_with_booking_id: et.redirect_with_booking_id ?? false,
show_next_available: et.show_next_available ?? false,
invite_delivery: et.invite_delivery ?? 'calendar',
location_type: et.location_type,
Expand Down Expand Up @@ -400,6 +403,9 @@
is_active: form.is_active,
is_public: form.is_public,
show_taken_slots: form.show_taken_slots,
// '' clears it server-side (null would mean "leave unchanged").
redirect_url: form.redirect_url.trim(),
redirect_with_booking_id: form.redirect_with_booking_id,
show_next_available: form.show_next_available,
invite_delivery: form.invite_delivery,
allow_phone_call: allowPhoneCall,
Expand Down Expand Up @@ -718,6 +724,16 @@
<p class="text-xs text-muted-foreground">{$t('eventTypeEditor.general.showNextAvailableHint')}</p>
</div>

<div class="mt-4 space-y-1.5">
<Label for="redirect-url">{$t('eventTypeEditor.general.redirectUrl')}</Label>
<Input id="redirect-url" type="url" inputmode="url" placeholder="https://example.com/thank-you" bind:value={form.redirect_url} />
<p class="text-xs text-muted-foreground">{$t('eventTypeEditor.general.redirectUrlHint')}</p>
<div class="flex items-center gap-2 pt-1">
<Checkbox id="redirect-with-id" bind:checked={form.redirect_with_booking_id} disabled={!form.redirect_url.trim()} />
<Label for="redirect-with-id" class="cursor-pointer font-normal">{$t('eventTypeEditor.general.redirectWithBookingId')}</Label>
</div>
</div>

{#if isOnlineMeeting(form.location_type)}
<label class="flex items-center gap-3 text-sm"><input type="checkbox" bind:checked={allowPhoneCall} />{$t('eventTypeEditor.general.allowPhoneCall')}</label>
{/if}
Expand Down
19 changes: 19 additions & 0 deletions internal/db/migrations/00077_event_type_redirect_url.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- +goose Up
-- Where the booker goes after a confirmed booking: typically the operator's own thank-you
-- page, which is also where site analytics usually count the conversion. Requested in
-- discussion #268.
--
-- redirect_url is NULL when unset, and the booking page then shows its own final
-- confirmation. It is admin-configured, but it is still an open-redirect surface, so it
-- is validated when saved and again before the page navigates: an absolute https URL
-- with a host and no credentials, nothing else.
--
-- redirect_with_booking_id appends ?booking_id=<id> so the thank-you page can tie the
-- conversion to the booking. Off by default: the booking id is a lookup key
-- (GET /v1/bookings/{id} is public), so handing it to another site is the operator's call.
ALTER TABLE event_types ADD COLUMN redirect_url TEXT;
ALTER TABLE event_types ADD COLUMN redirect_with_booking_id INTEGER NOT NULL DEFAULT 0;

-- +goose Down
ALTER TABLE event_types DROP COLUMN redirect_with_booking_id;
ALTER TABLE event_types DROP COLUMN redirect_url;
16 changes: 16 additions & 0 deletions internal/handler/assets/booking-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,23 @@
// consolidated onto it. If these are ever unified, the shared version must take the
// locale's list_separator/list_conjunction, not hardcode punctuation.

// redirectTarget is where to send the booker after a confirmed booking, or '' (#268):
// the event type's redirect_url, checked once more right before navigating even though
// the server already validated it on save and on serve, then ?booking_id= appended when
// the event type asks for it. Absolute https with a host and no credentials, exactly as
// the server's validRedirectURL; anything else yields '' and the page simply stays on
// its own confirmation. MIRRORED in embed.js (which does not load this module).
function redirectTarget(raw, bookingId, withId) {
if (typeof raw !== 'string' || raw === '' || /[\u0000-\u0020\u007f]/.test(raw)) return '';
var u;
try { u = new URL(raw); } catch (e) { return ''; }
if (u.protocol !== 'https:' || !u.hostname || u.username || u.password) return '';
if (withId && bookingId) u.searchParams.set('booking_id', String(bookingId));
return u.href;
}

return {
redirectTarget: redirectTarget,
dateKeyFromISO: dateKeyFromISO,
ymd: ymd,
groupSlotsByDay: groupSlotsByDay,
Expand Down
12 changes: 12 additions & 0 deletions internal/handler/assets/booking-logic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ test('fmt leaves a string with no verbs untouched', () => {
assert.equal(B.fmt('Inga lediga tider.'), 'Inga lediga tider.');
});

test('redirectTarget: https only, no credentials, optional booking_id', () => {
assert.equal(B.redirectTarget('https://example.com/thanks', 'b1', false), 'https://example.com/thanks');
assert.equal(B.redirectTarget('https://example.com/thanks?src=cal', 'b 1', true),
'https://example.com/thanks?src=cal&booking_id=b+1');
assert.equal(B.redirectTarget('https://example.com/thanks', '', true), 'https://example.com/thanks');
for (const bad of ['', 'http://example.com/', 'javascript:alert(1)', '//example.com/x', '/thanks',
'https://user:pw@example.com/', 'https://trusted.example@evil.example/', 'https://exa mple.com/',
'https://example.com/\nx', 'data:text/html,hi', null, undefined]) {
assert.equal(B.redirectTarget(bad, 'b1', true), '', String(bad));
}
});

test('earliestFreeSlot picks the soonest slot and the day it falls on in the selected tz', () => {
const slots = [
{ start: '2026-06-16T09:00:00Z' },
Expand Down
Loading