Skip to content

feat(booking): optional redirect after a confirmed booking (#268) - #285

Open
dominik-myszkowski wants to merge 7 commits into
Calnode:mainfrom
dominik-myszkowski:feat/booking-redirect-url
Open

dominik-myszkowski wants to merge 7 commits into
Calnode:mainfrom
dominik-myszkowski:feat/booking-redirect-url

Conversation

@dominik-myszkowski

Copy link
Copy Markdown
Contributor

The redirect_url half of #268. Stacked on #284: this branch contains its commit (the final confirmation state), and the redirect hangs off its finalize(). Please review #284 first. The diff of this PR alone is the second commit, c88eb86.

What it does

  • New columns event_types.redirect_url (NULL = none) and redirect_with_booking_id (default 0), migration 00077. They are exposed on the event type API (create, PATCH, where "" clears) and carried by duplication.
  • Booking page: once confirmed, finalize() shows a Continue button to the target and navigates after 1.5 s. The delay leaves time for the dataLayer/GA4 conversion pushed right after finalize(). "Book another time" is hidden then, since the page is leaving.
  • Stripe return: the success URL now also carries booking_id, so ?booking_id= works for paid bookings too. Without it, the return leg has no way to know which booking it was.
  • Embed widget: never navigates the host page, as you suggested. The confirmation offers Continue, which opens the redirect in a new tab with noopener.
  • Manage page: no redirect. A reschedule or a cancellation is not the conversion a thank-you page is for.
  • Admin: a URL field and a "add the booking ID" checkbox in the General tab (en/fr). The hint says the widget opens it in a new tab.

Open-redirect handling

Your three conditions, checked at three points:

  1. On save: validRedirectURL (internal/handler/redirect_url.go) requires:

    • an absolute https URL with a host;
    • no userinfo, since https://trusted.example@evil.example/ reads as one site and goes to another;
    • no whitespace or control characters, and at most 2000 characters.

    It follows the same https-and-host pattern as validVideoURL/validatedLegalURL, tightened because this one is followed automatically.

  2. On serve: servedRedirectURL. If a stored value no longer passes (a row written by hand, or before a rule was tightened), it is served to the page and the widget as no redirect, and logged.

  3. In the browser, right before use: BookingLogic.redirectTarget, mirrored in embed.js (which doesn't load the module) with the same rules. It also appends booking_id via URLSearchParams.

redirect_with_booking_id is off by default because the booking id works as a lookup key (GET /v1/bookings/{id} is public), so passing it to another site should be the operator's explicit choice.

Tests

  • TestValidRedirectURL: accepted and refused forms (http:, javascript:, data:, protocol-relative, relative, opaque, credentials, the @ trick, whitespace, control characters, length).
  • TestRedirectURL_savedOnlyWhenValid: create and PATCH refuse bad values with 400 and leave nothing behind; a valid value is trimmed and stored; "" clears it.
  • TestRedirectURL_servedToPageAndWidget: the page constants and the /public payload carry the redirect. A bad value written straight into the row is served as none.
  • TestBookingCheckout_successURLCarriesBookingID.
  • TestEmbedJS_redirectOpensNewTab: source pins on the mirror, the window.open(..., 'noopener'), and no location navigation.
  • booking-logic.test.js: redirectTarget cases.
  • The book.html harness from fix(booking): a confirmed booking is a final state on all three surfaces (#268) #284 gets three scenarios, each running the real page script under node:
    • redirect: after booking, Continue points at the URL with booking_id, exactly one navigation is scheduled, and it goes there when the delay fires;
    • redirect-paid: the same on the Stripe return, with booking_id taken from the return URL;
    • redirect-refused: the page is rendered with an http:// value that server validation would never pass. The browser check alone keeps it on the confirmation. Disabling that check fails this scenario.

gofmt, go vet ./..., go build ./..., go test ./..., go run ./cmd/i18n-coverage, node --test internal/handler/assets/booking-logic.test.js, pnpm check, pnpm check:i18n, pnpm build, pnpm test:visual and make build pass locally.

I also checked it on a running binary in Chromium:

  • the API refused the @ trick with 400;
  • the booking page showed Continue and landed on the thank-you URL with the booking's id after about 1.5 s;
  • in the widget, on a page from another origin, Continue opened a new tab with no opener, and the host page's URL was unchanged after waiting past the delay.

Merge notes

Mechanical conflicts are expected with our other open PRs. With #283, both add event_types columns at the same spots (scan list, etColumns, INSERT, duplicate, api.ts). With #281 it is only the CHANGELOG. I'll rebase whichever lands second.

…ces (Calnode#268)

book.html left its calendar clickable after confirming and re-enabled the
submit button, inviting a second booking under a different email, which
max_active_bookings cannot catch.

- book.html: finalize() on success and on the Stripe return disables the
  calendar, month navigation, timezone and submit and resets the form; every
  handler checks the flag. A submitting flag drops a second submit while the
  first is in flight. "Book another time" is a fresh load without the Stripe
  return parameters.
- embed.js: the calendar renders disabled in the confirm view and a second
  submit is refused. "Book another time" resets the widget's own state and
  reloads the month; it never navigates the host page.
- manage.html: the rescheduled and cancelled views are final; showView no
  longer leaves them and neither action can be sent again.

New booker key book_another_time in every locale. TestBookPage_confirmationIsFinal
runs book.html's real page script under node against a small fake DOM and
checks that a second submit sends nothing; the widget and manage page are
pinned at source level.

@pullfrog pullfrog Bot left a comment

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.

Important

Two gaps worth addressing before merge: an unchanged invalid redirect_url locks the event type out of the admin editor, and assistant bookings bypass the new confirmation/redirect entirely. The open-redirect handling itself is solid.

Approach: sound — the redirect is a small, opt-in addition validated at save, serve and use, and the embed never navigates the host page.

Reviewed changes — the redirect commit (c88eb86) in full, plus the stacked #284 commit as context.

  • Schema + API — redirect_url / redirect_with_booking_id on event_types (migration 00077), exposed on create/PATCH/GET and copied by duplication.
  • Validation — validRedirectURL on save, servedRedirectURL on serve, BookingLogic.redirectTarget in the browser with an embed.js mirror.
  • Booking page — finalize() shows Continue and auto-navigates after 1.5 s; the Stripe success URL carries booking_id for the paid return.
  • Embed widget — confirmation offers Continue in a new tab; never navigates the host page.
  • Admin — General-tab URL field and booking-ID checkbox (en/fr).
  • Tests — server validation, page/widget payloads, Stripe URL, node harness scenarios, and source pins for the widget.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

Comment thread internal/handler/event_type.go Resolved
Comment thread internal/handler/templates/book.html Resolved
Comment thread internal/handler/redirect_url.go Resolved
On the return from Stripe Checkout finalize() shows the confirmation,
but the step-flow init then set the calendar step, which on a narrow
viewport hides the right pane: a disabled calendar and no confirmation.
The init now opens a final page on the right pane.
event_types.redirect_url and redirect_with_booking_id (migration 00077):
where the booker goes once a booking is confirmed, typically the operator's
thank-you page, optionally with ?booking_id= appended (off by default; the
booking id is a lookup key).

The value is an open-redirect surface, so it is checked three times:
validRedirectURL on save (absolute https, a host, no credentials, no
whitespace or control characters, <= 2000 chars), servedRedirectURL when a
page or the widget is given it (an invalid stored value is served as none
and logged), and BookingLogic.redirectTarget in the browser before use,
mirrored in embed.js.

- book.html: finalize() shows "Continue" and navigates after 1.5 s, leaving
  time for the conversion push. Covers the Stripe return too: the success
  URL now carries booking_id.
- embed.js: never navigates the host page; "Continue" opens the redirect in
  a new tab (noopener).
- manage.html: no redirect; a reschedule or cancel is not a conversion.
- Admin: URL field and booking-id checkbox in the General tab (en/fr).
- New booker key "continue" in every locale.

Builds on the final confirmation state from the previous commit (Calnode#284).
… a hostname

The editor re-submits the whole form, so a stored redirect that no longer
passes (servedRedirectURL already serves it as none) made every unrelated
edit fail. It is now validated when the value changes, as location and
invite_delivery are. https://:8080/ passed the server check through
u.Host while the browser refused it; u.Hostname() matches both.
…state (Calnode#268)

The chat's booking never went through finalize(): no redirect, and the
calendar stayed live. book.html's chat script now announces the booking
to the page script, which finalizes as for the form; the widget's chat
switches to the confirmation view, where Continue lives.
@dominik-myszkowski
dominik-myszkowski force-pushed the feat/booking-redirect-url branch from c88eb86 to 139bd14 Compare December 1, 2026 09:01
…-url

# Conflicts:
#	frontend/src/lib/api.ts
#	frontend/src/lib/i18n/en.json
#	frontend/src/lib/i18n/fr.json
#	frontend/src/routes/event-types/[slug]/+page.svelte
#	internal/handler/assets/booking-logic.test.js
#	internal/handler/book.go
#	internal/handler/event_type.go

@pullfrog pullfrog Bot left a comment

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.

✅ No new issues found.

Approach: unchanged and still sound — the redirect stays a small, opt-in addition validated at save, serve and use, and these commits close the two gaps raised last round without widening the mechanism.

Reviewed changes — the delta since the prior pullfrog review at c88eb86 (0b24ebf, d5d0ac9, 139bd14).

  • On-change redirect validation — PatchEventType now reads COALESCE(redirect_url, '') in the same lookup as location / invite_delivery and validates only when the trimmed request value differs, so a stored value that no longer passes can no longer lock the operator out of unrelated fields.
  • Hostname check — validRedirectURL now tests u.Hostname(), refusing a port-only authority (https://:8080/thanks) that the browser mirror already rejected.
  • Assistant bookings reach the final state — book.html's chat script announces calnode:assistant-booked and the page script finalizes on it (time, finalize(), right step, calendar re-render); the widget's asstSubmit switches to confirm with state.bookingId and the booked start, so both surfaces now honour the redirect from a chat booking.
  • Mobile step-flow — book.html shows one pane at a time under 700 px and opens an already-final page (the Stripe return) on the right pane, so the confirmation is not hidden behind a disabled calendar.
  • Tests — a seeded-legacy-row PATCH case, the port-only refused URL, redirect-assistant in the node harness, and TestAssistantBooking_reachesTheFinalState; the targeted go test and node --test runs pass locally.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash | 𝕏

@pullfrog pullfrog Bot left a comment

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.

✅ No new issues found.

Reviewed changes — the delta since the prior pullfrog review at 139bd14 (80f196a, 4124508), i.e. the origin/main merge and the conflict fix that follows it.

  • Merged main into the branch — brings in #254 (show_next_available) alongside this PR's redirect_url / redirect_with_booking_id columns; the resolution keeps both in etColumns, scanEventTypeRow, the create/duplicate INSERTs, api.ts and the admin editor.
  • Dropped the duplicated form-defaults line — the merge had left is_active, is_public, show_taken_slots twice in the event-type editor's $state defaults; it now appears once, with show_next_available from main.

Checked that the resolution is coherent rather than merely compiling: no conflict markers remain, etColumns ordering matches the scan dests, both admin catalogs carry the redirect* and showNextAvailable* keys, book.html's timezone handler and init call both loadNextAvailable() and loadMonthAvailability(), and this PR's finalized guards survive in the handlers main touched. go test ./internal/handler/ ./internal/i18n/ passes, including next_available_test.go, embed_handler_test.go and the redirect/final-state tests.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash | 𝕏

shockalotti added a commit that referenced this pull request Dec 1, 2026
#281 holds 00075, and the queue runs 00076 #283, 00077 #285, 00078 #286.
This must merge after those, so it takes 00079. A lower number landing later
leaves a gap and goose refuses to boot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant