Repository navigation
feat(booking): optional redirect after a confirmed booking (#268) - #285
dominik-myszkowski wants to merge 7 commits into
Conversation
…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.
There was a problem hiding this comment.
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_idonevent_types(migration 00077), exposed on create/PATCH/GET and copied by duplication. - Validation —
validRedirectURLon save,servedRedirectURLon serve,BookingLogic.redirectTargetin the browser with anembed.jsmirror. - Booking page —
finalize()shows Continue and auto-navigates after 1.5 s; the Stripe success URL carriesbooking_idfor 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.
deepseek-v4.1-flash | 𝕏
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.
c88eb86 to
139bd14
Compare
…-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
There was a problem hiding this comment.
✅ 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 —
PatchEventTypenow readsCOALESCE(redirect_url, '')in the same lookup aslocation/invite_deliveryand 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 —
validRedirectURLnow testsu.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 announcescalnode:assistant-bookedand the page script finalizes on it (time,finalize(), right step, calendar re-render); the widget'sasstSubmitswitches toconfirmwithstate.bookingIdand the booked start, so both surfaces now honour the redirect from a chat booking. - Mobile step-flow —
book.htmlshows 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-assistantin the node harness, andTestAssistantBooking_reachesTheFinalState; the targetedgo testandnode --testruns pass locally.
deepseek-v4.1-flash | 𝕏
There was a problem hiding this comment.
✅ 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
maininto the branch — brings in #254 (show_next_available) alongside this PR'sredirect_url/redirect_with_booking_idcolumns; the resolution keeps both inetColumns,scanEventTypeRow, the create/duplicate INSERTs,api.tsand the admin editor. - Dropped the duplicated form-defaults line — the merge had left
is_active, is_public, show_taken_slotstwice in the event-type editor's$statedefaults; it now appears once, withshow_next_availablefrommain.
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.
deepseek-v4.1-flash | 𝕏

The
redirect_urlhalf of #268. Stacked on #284: this branch contains its commit (the final confirmation state), and the redirect hangs off itsfinalize(). Please review #284 first. The diff of this PR alone is the second commit,c88eb86.What it does
event_types.redirect_url(NULL = none) andredirect_with_booking_id(default 0), migration00077. They are exposed on the event type API (create, PATCH, where""clears) and carried by duplication.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 afterfinalize(). "Book another time" is hidden then, since the page is leaving.booking_id, so?booking_id=works for paid bookings too. Without it, the return leg has no way to know which booking it was.noopener.Open-redirect handling
Your three conditions, checked at three points:
On save:
validRedirectURL(internal/handler/redirect_url.go) requires:httpsURL with a host;https://trusted.example@evil.example/reads as one site and goes to another;It follows the same https-and-host pattern as
validVideoURL/validatedLegalURL, tightened because this one is followed automatically.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.In the browser, right before use:
BookingLogic.redirectTarget, mirrored inembed.js(which doesn't load the module) with the same rules. It also appendsbooking_idviaURLSearchParams.redirect_with_booking_idis 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/publicpayload carry the redirect. A bad value written straight into the row is served as none.TestBookingCheckout_successURLCarriesBookingID.TestEmbedJS_redirectOpensNewTab: source pins on the mirror, thewindow.open(..., 'noopener'), and nolocationnavigation.booking-logic.test.js:redirectTargetcases.book.htmlharness 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 withbooking_id, exactly one navigation is scheduled, and it goes there when the delay fires;redirect-paid: the same on the Stripe return, withbooking_idtaken from the return URL;redirect-refused: the page is rendered with anhttp://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:visualandmake buildpass locally.I also checked it on a running binary in Chromium:
@trick with 400;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_typescolumns at the same spots (scan list,etColumns, INSERT, duplicate,api.ts). With #281 it is only the CHANGELOG. I'll rebase whichever lands second.