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.
This commit is contained in:
Lago committed 2026-10-19 15:10:20 +02:00
1 parent c857204cfe
commit c49a94fe80
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;'; \
+38 -2
View File
@@ -124,6 +124,14 @@ Staff checks an attendee into a session.
- **Role check:** `is_staff_or_admin()` (i.e. `is_admin()`) or it raises
`staff or admin only`.
- Resolves the attendee by `qr_token`.
- **Front-desk gate:** when the attendee's `registrations.checked_in` is not
`true`, it raises `This attendee needs to be checked in at the front desk
first.` Nobody can be checked into a session before the **welcome** check-in at
the front desk has marked them present at the event. The scanner shows this as
its own sheet instead of a generic error (see
[../frontend/screens.md](../frontend/screens.md)). `checkin_attendee` also
stopped setting `checked_in = true` as a side effect — the welcome check-in
(or an admin's Registrations toggle) is now the only way to earn it.
- **Service-session guard:** if the session's slot is a `service_session`, it
raises `service sessions cannot be checked in` (there's nothing to check into —
everyone is in the room).
@@ -148,9 +156,13 @@ from `checkin_attendee`, which checks someone into a specific session).
check-in's job).
- `already` is `true` if the attendee was already checked in to the event.
- On a **first** check-in (and only when the event has a badge layout), enqueues
a `badge_print` job in the same transaction (see [printing.md](printing.md)).
`events.badge_copies` identical `badge_print` jobs in the same transaction — the
Pi worker prints exactly one label per job, so N jobs = N labels (see
[printing.md](printing.md)). The value is clamped to `1..4` inside the function,
so a bad row can never flood the queue. A re-check-in (`already`) enqueues
nothing. Manual reprint (`enqueue_badge_print`) still prints **one** label.
### `preview_welcome_checkin(p_attendee_qr)` → `(attendee_email, attendee_name, already, will_print)`
### `preview_welcome_checkin(p_attendee_qr)` → `(attendee_email, attendee_name, already, will_print, copies)`
Read-only preview shown by the staff scanner **before** a welcome check-in is
committed, so the confirmation popup can name the attendee and be honest about
printing.
@@ -161,6 +173,10 @@ printing.
- `will_print` is `true` only for a genuine first check-in **and** when the
event has a badge layout with elements — exactly the condition under which
`welcome_checkin` enqueues a job.
- `copies` is the number of labels a confirm would queue — the same
clamp `welcome_checkin` applies, and `0` when nothing would print. The popup
uses it to say "print their badge 3 times" instead of a fixed "this person's
label", so it can never over- or under-promise.
- Checks nobody in and enqueues nothing; it is a pure lookup.
### `merge_tickets(p_source_id, p_target_id)` -> `jsonb`
@@ -507,6 +523,26 @@ genuine **first** check-in it enqueues the badge job in the same transaction
when the event has a layout with elements (see
[welcome_checkin](#welcome_checkinp_attendee_qr--attendee_email-attendee_name-already).
## Front-desk gate and badge copies
Source of truth:
[`supabase/migrations/20261019110000_front_desk_gate_and_badge_copies.sql`](../../supabase/migrations/20261019110000_front_desk_gate_and_badge_copies.sql)
(see [release record](../releases/2026-10-19.md)).
- `events.badge_copies` — new `integer not null default 1` with
`check (badge_copies between 1 and 4)`. Admins edit it from **Settings → Badge
printing** for the active event, and when creating/editing an event (see
[../frontend/admin-app.md](../frontend/admin-app.md)).
- `checkin_attendee` re-creates: adds the **front-desk gate** and drops the
`checked_in = true` side effect.
- `welcome_checkin` re-creates: enqueues `badge_copies` jobs instead of one.
- `preview_welcome_checkin` **drops and re-creates** (the return type gained
`copies`, and Postgres cannot `create or replace` across a signature change);
grants are re-applied in the same migration.
`checkins` has no `INSERT` policy, so `checkin_attendee` is the only write path
for session check-ins — the gate cannot be bypassed from the API.
## Error handling
RPCs raise Postgres exceptions with human-readable messages (e.g. `you cannot
+2 -1
View File
@@ -81,6 +81,7 @@ queries everything for the active event and handles "no active event" gracefully
| `sessionize_endpoint` | `text` | nullable — the Sessionize API URL for this event (see [sidecar.md](./sidecar.md)) |
| `use_realtime_clock` | `boolean` | default `false` — when `true`, the attendee app drives slot status (Live/Next/Done) from the real system clock; when `false` it uses the simulated mid-event clock (see [../frontend/app-structure.md](../frontend/app-structure.md)) |
| `talk_networking_bonus` | `integer` | default `2` — bonus points awarded to **each** party when two people who were checked into the same session (talk) accept a connection. `0` disables the feature (the +5 connection award still applies). Awarded with the `talk_networking` points category (see [rpcs.md](./rpcs.md#accept_connectionp_connection_id-uuid)) |
| `badge_copies` | `integer` | default `1`, `check (between 1 and 4)` — how many badge labels a **welcome (front-desk) check-in** prints. Enforced again inside `welcome_checkin`, so a hand-edited row cannot flood the queue. Manual reprint ignores it and always prints one. Set from **Settings → Badge printing** (see [printing.md](./printing.md)) |
| `last_synced_at` | `timestamptz` | nullable — when the Sessionize sync last ran |
| `created_at` | `timestamptz` | |
@@ -98,7 +99,7 @@ Points are scoped **per event** here (one row per contact per event).
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `contact_email` | `text` FK → `contacts` | `on delete cascade` |
| `type` | `registration_type` (enum) | `attendee` \| `speaker` \| `staff` \| `sponsor` (default `attendee`) |
| `checked_in` | `boolean` | default `false` |
| `checked_in` | `boolean` | default `false` — **the front-desk flag.** Set by the welcome check-in (or an admin's Registrations toggle); it is what makes someone eligible for session check-ins. `checkin_attendee` refuses anyone with this flag `false` |
| `points` | `integer` | `>= 0`, default 0 |
| `qr_token` | `text` | nullable — the lanyard token; **doubles as the Auth password** (generated per event) |
| `external_id` | `text` | nullable — reserved for an external system's id (currently unused) |
+49 -1
View File
@@ -1,3 +1,50 @@
# Front-Desk Gate + Badge Copies Regression
After applying `20261019110000_front_desk_gate_and_badge_copies.sql`, run the
SQL suite **combined with the migration** in one transaction (the migration is
`create or replace`, so the same stream also re-verifies an already-applied
database):
```sh
(echo 'begin;'; \
cat supabase/migrations/20261019110000_front_desk_gate_and_badge_copies.sql; \
sed '/^begin;$/d' supabase/tests/badge_print_tests.sql) \
| docker exec -i supabase_db_Convivo psql -X -U postgres -d postgres -v ON_ERROR_STOP=1
docker exec -i supabase_db_Convivo psql -X -U postgres -d postgres \
-v ON_ERROR_STOP=1 < supabase/tests/set_registration_checked_in_tests.sql
CONVIVO_BASE_URL=http://127.0.0.1:3000 npm test --prefix e2e -- front-desk-gate.spec.ts --project=chromium
CONVIVO_BASE_URL=http://127.0.0.1:3000 npm test --prefix e2e -- welcome-badge-copies.spec.ts --project=chromium
CONVIVO_ADMIN_URL=http://127.0.0.1:3001 npm test --prefix e2e -- registration-checkin-toggle.spec.ts --project=chromium
```
The SQL fixture is rollback-only: **113 assertions** — six of them added with the
gate and the copies (the badge-print suite owns both functions) — cover the gate
refusing a session check-in for an attendee with no front-desk check-in
(`session check-in requires a front-desk check-in`), the copies loop
(`badge_copies = 3` queues three more labels) and the savepoint that returns the
queue to one so the rest of the run is unaffected, plus
`preview_welcome_checkin`'s new `copies` column: `1` by default, `0` when nothing
would print, `3` after the event is changed. The pre-existing "session check-in
records / enqueues nothing" case now flips `checked_in` on first, because the
gate makes it a precondition.
`set_registration_checked_in_tests.sql` (**15 assertions**) covers the admin
toggle that grants and revokes the same flag, with its points accounting.
`front-desk-gate.spec.ts` and `welcome-badge-copies.spec.ts` are real-browser
suites against the local stack (real Auth + PostgREST + pgmq): they provision a
disposable attendee, assert the scanner shows its **"Not checked in yet"** sheet
while recording no check-in, that a session check-in no longer sets the
front-desk flag by itself, that the same scan succeeds once the welcome check-in
is done, that the queue grows by exactly `badge_copies` messages, and
that a re-welcome prints nothing. They delete their own rows and restore
`badge_copies = 1`. `registration-checkin-toggle.spec.ts` is API-mocked and
covers the table behaviour the old build got wrong: no refetch on a toggle or a
type change, row order preserved, only the touched row busy while its checkbox
is disabled, other rows still usable, rollback on a rejected RPC, and the
Settings copies picker saving and reloading.
See [release record](../releases/2026-10-19.md) for the bug this started with.
# Badge Print Queue Regression
After applying `20261018170000_badge_print_queue`, run the SQL suite **combined
@@ -13,7 +60,8 @@ CONVIVO_ADMIN_URL=http://127.0.0.1:3001 npm test --prefix e2e -- printing.spec.t
pytest apps/printer/tests # worker unit tests (no hardware, no browser)
```
The SQL fixture is rollback-only: **101 assertions** cover queue creation and
The SQL fixture is rollback-only: **113 assertions** (six of them the front-desk
gate and badge copies, covered in the section above) cover queue creation and
migration idempotency, pgmq/API isolation, the self-contained payload shape and
layout resolution (default-with-elements, fallback, none → no job), first-scan
enqueue inside `welcome_checkin` (re-scan enqueues nothing), station token