fix(admin): per-row check-in toggle; feat(db): front-desk gate + badge copies

Registrations table felt buggy because both row actions did
setBusy(true) -> write -> reloadRegistrations() -> setBusy(false):
the list is sorted by points, so a reload made the row you just
touched jump (or vanish under a Checked-in filter), and the single
`busy` flag disabled every control in the table for the whole
request. The fix is per-row in-flight state (busyIds + withRowBusy)
and no reload at all: the toggle patches its own row's checked_in
plus the points delta the RPC returns, the type change patches
`type`; a rejected write rolls both back. Only the touched row is
disabled, shows a "Saving…" pulse, and two rows can save at once.
Toggle hit area is now 40x41 px with a focus-visible ring.

Front-desk gate: checkin_attendee reads registrations.checked_in
and raises "This attendee needs to be checked in at the front desk
first." when it is not true, and no longer sets checked_in as a
side effect. checkins has no INSERT policy, so the RPC is the only
write path and the gate cannot be bypassed. The scanner shows a
dedicated "Not checked in yet" sheet instead of a toast.

Badge copies: events.badge_copies (1..4, default 1). welcome_checkin
sends that many pgmq jobs in one transaction (the Pi prints one
label per job, so N jobs = N labels; no worker change) and clamps
the value again itself. preview_welcome_checkin gained a `copies`
column (drop + recreate) so the popup states the real count. Manual
reprint still prints exactly one. Set from Settings -> Badge
printing (active event) and the Events form, always as a
single-column update; the Settings badge section now renders even
when the LLM settings call fails.

Tests: badge_print 113 (+6), leaderboard 47 (+1), new
registration-checkin-toggle (6), front-desk-gate (3),
welcome-badge-copies (3); the stale registrations-PATCH mock in
registration-ticket-merge now targets set_registration_checked_in,
the ambiguous Save button is "Save copies", and the print-copy
assertion tolerates the typographic apostrophe. Docs updated
(rpcs, schema, printing, tests, admin-app, screens) with a release
record; NOT deployed - see docs/releases/2026-10-19.md.

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-10-19 15:10:20 +02:00
1 parent d3531e1fac
commit 17473916a6
27 files changed
+1378 -73

No files matched your search

+22 -4
View File
@@ -99,7 +99,7 @@ cross-reference list.
| Function | Purpose |
|---|---|
| `enqueue_badge_print(p_registration_id)` | Manual reprint: queue the badge of one registration (`kind = reprint`); returns the queue msg id |
| `enqueue_badge_print(p_registration_id)` | Manual reprint: queue the badge of one registration (`kind = reprint`); returns the queue msg id. Always **one** label — `events.badge_copies` belongs to the welcome check-in, so reprinting a lost badge never produces a stack |
| `create_print_station(p_name)` | Register a station. Generates `cvp_<64 hex>` (32 random bytes), stores only its **SHA-256 hex digest**, returns the plaintext token **once** |
| `rename_print_station(p_id, p_name)` | Rename (trimmed, required, ≤ 80 chars). Revoked stations stay renamable so history remains readable |
| `revoke_print_station(p_id)` | Sets `revoked_at`; the token stops working immediately |
@@ -125,15 +125,33 @@ worker) and stamps `last_seen_at`.
behaviour, plus the `badge_print` enqueue for a **genuine first check-in** only,
inside the same transaction (see [rpcs.md](./rpcs.md#welcome_checkinp_attendee_qr--attendee_email-attendee_name-already)).
### How many labels one welcome prints
`events.badge_copies` (`1..4`, default `1`, added in
[`20261019110000_front_desk_gate_and_badge_copies.sql`](../../supabase/migrations/20261019110000_front_desk_gate_and_badge_copies.sql))
is the per-event copy count for the **front desk**. `welcome_checkin` builds the
payload once and calls `pgmq.send` that many times in the same transaction; the
worker already prints exactly one label per job, so **N jobs = N labels** and no
worker, renderer or queue change was needed. The value is clamped with
`greatest(1, least(4, …))` *inside* the function too, so a hand-edited row can
never flood the queue, and the same clamp is used by
`preview_welcome_checkin`'s `copies` column so the popup states the true number
(*"you will print their badge 3 times"*). Re-welcoming an already-checked-in
attendee prints nothing, copies included. Admins set it in **Settings → Badge
printing** (the active event) or on the Events form; both write the single
column, never the whole row.
The staff scanner (attendee app → Scan → Welcome check-in) does **not** fire
`welcome_checkin` directly. It first calls the read-only
`preview_welcome_checkin(qr)` and shows a confirmation — *"You are checking in
[Name]. By confirming, you will print this person's label."* — with **Yes/No**.
[Name]. By confirming, you will print this person's label"* (or *"…their badge 3
times"*, from `copies`) — with **Yes/No**.
Only **Yes** runs `welcome_checkin`. The preview's `will_print` mirrors the exact
enqueue condition (first check-in **and** a layout exists), so the popup never
promises a print that won't happen; when it is `false` the popup says the person
is checked in without mentioning a label. Session check-in is unchanged and never
prints. (Added in `20261019090000_welcome_checkin_preview.sql`.)
prints. (Added in `20261019090000_welcome_checkin_preview.sql`, `copies` in
`20261019110000_front_desk_gate_and_badge_copies.sql`.)
## 5. Station tokens & security model
@@ -280,7 +298,7 @@ and staged (`STAGE_APP` / `STAGE_WIFI_PORTAL` / `REBOOT`):
## 12. Tests
- **SQL:** [`supabase/tests/badge_print_tests.sql`](../../supabase/tests/badge_print_tests.sql)
— rollback-only, **101 assertions**; run it **combined with the migration**
— rollback-only, **113 assertions**; run it **combined with the migration**
(idempotent, works before and after apply):
```sh
(echo 'begin;'; \