feat(scan): confirm before welcome check-in, with print warning

The staff scanner checked attendees in silently, and the default session
mode never prints — so a welcome-desk scan could check someone in with no
badge and no confirmation.

- new read-only RPC preview_welcome_checkin(qr): resolves the attendee and
  reports already + will_print (mirrors the exact welcome_checkin enqueue
  condition: first check-in AND a layout exists). Staff/admin only; checks
  nobody in, enqueues nothing.
- attendee Scan screen previews first and shows a Yes/No sheet: "You are
  checking in [Name]. By confirming, you will print this person's label."
  Only Yes runs welcome_checkin. Session check-in unchanged (never prints).
- badge_print_tests.sql +8 assertions (109 total); ScanPage + welcome specs
  drive the confirm step; new CONV-CHECKIN-003 (No cancels, Yes checks in).
- docs: rpcs.md, printing.md, 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 09:45:20 +02:00
1 parent 00c89c1b48
commit 65dcf64c4e
11 files changed
+348 -7

No files matched your search

@@ -0,0 +1,54 @@
-- -----------------------------------------------------------------------------
-- Welcome check-in preview.
--
-- The staff scanner now shows a confirmation before a welcome check-in:
-- "You are checking in [Name]. By confirming, you will print this person's
-- label." This read-only RPC resolves a scanned QR token to the attendee and
-- reports whether a badge would actually print, so the popup can show the real
-- name and be honest about the print (a person already checked in, or an event
-- without a badge layout, will NOT print — mirroring welcome_checkin exactly).
--
-- It does NOT check anyone in and does NOT enqueue anything; it is a pure
-- lookup. Staff/admin only, same guard as welcome_checkin.
-- -----------------------------------------------------------------------------
create or replace function public.preview_welcome_checkin(p_attendee_qr text)
returns table (attendee_email text, attendee_name text, already boolean, will_print boolean)
language plpgsql stable security definer set search_path = public as $$
declare
v_staff text := public.current_email();
v_attendee text;
v_name text;
v_event_id uuid;
v_checked boolean;
v_reg_id uuid;
begin
if v_staff is null then raise exception 'not authenticated'; end if;
if not public.is_staff_or_admin() then raise exception 'staff or admin only'; end if;
select id into v_event_id from public.events where is_active limit 1;
if v_event_id is null then raise exception 'no active event'; end if;
select r.contact_email, c.full_name, r.id into v_attendee, v_name, v_reg_id
from public.registrations r
join public.contacts c on c.email = r.contact_email
where r.qr_token = p_attendee_qr
and r.event_id = v_event_id;
if v_attendee is null then raise exception 'no attendee found for that QR code'; end if;
select checked_in into v_checked
from public.registrations
where event_id = v_event_id and contact_email = v_attendee;
-- A badge prints only on a genuine first check-in AND when the event has a
-- layout with elements (the same condition welcome_checkin uses to enqueue).
will_print := coalesce(v_checked, false) is not true
and public._badge_print_payload(v_reg_id, 'checkin', v_staff) is not null;
return query select v_attendee, v_name, coalesce(v_checked, false), will_print;
end;
$$;
revoke execute on function public.preview_welcome_checkin(text) from public, anon;
grant execute on function public.preview_welcome_checkin(text) to authenticated;
notify pgrst, 'reload schema';
+70
View File
@@ -262,6 +262,76 @@ select pg_temp.assert_bp(
(select not checked_in from public.registrations where contact_email = '[email protected]'),
'rolled back check-in leaves the attendee unchecked');
-- -----------------------------------------------------------------------------
-- 2b. WELCOME CHECK-IN PREVIEW (read-only: resolves the name + will_print)
-- -----------------------------------------------------------------------------
-- bp-att5 is still unchecked (its scan was rolled back) and event A has a
-- layout, so the preview must report will_print = true WITHOUT checking in or
-- enqueueing anything.
create temporary table bp_prev1 as
select * from public.preview_welcome_checkin('BPQR-ATT-5');
select pg_temp.assert_bp(
(select attendee_email = '[email protected]' and attendee_name = 'Savepoint Sol' from bp_prev1),
'preview resolves the attendee name from the QR token');
select pg_temp.assert_bp(
(select already = false and will_print = true from bp_prev1),
'preview of an unchecked attendee reports will_print');
select pg_temp.assert_bp(
(select count(*) = 1 from pgmq.q_badge_print),
'preview enqueues nothing');
select pg_temp.assert_bp(
(select not checked_in from public.registrations where contact_email = '[email protected]'),
'preview does not check the attendee in');
-- An already-checked-in attendee: preview reports already and will_print = false.
create temporary table bp_prev2 as
select * from public.preview_welcome_checkin('BPQR-ATT-2');
select pg_temp.assert_bp(
(select already = true and will_print = false from bp_prev2),
'preview of a checked-in attendee reports no print');
-- An event without a badge layout: check-in would work but nothing prints.
-- (bp-attb was checked in by the section-2 scan; reset it so the preview
-- isolates the "no layout" reason rather than "already checked in".)
update public.registrations set checked_in = false where contact_email = '[email protected]';
update public.events set is_active = true where id = 'b9d00002-0000-0000-0000-00000000000b';
update public.events set is_active = false where id = 'b9d00001-0000-0000-0000-00000000000a';
create temporary table bp_prev3 as
select * from public.preview_welcome_checkin('BPQR-ATT-B');
select pg_temp.assert_bp(
(select already = false and will_print = false from bp_prev3),
'preview without a layout reports no print');
update public.events set is_active = true where id = 'b9d00001-0000-0000-0000-00000000000a';
update public.events set is_active = false where id = 'b9d00002-0000-0000-0000-00000000000b';
-- A plain (non-staff) viewer cannot preview; the guard matches welcome_checkin
-- (a plain RAISE EXCEPTION, i.e. sqlstate P0001 / raise_exception).
select set_config('request.jwt.claims', '{"email":"[email protected]","role":"authenticated"}', true);
do $$ begin
begin
perform * from public.preview_welcome_checkin('BPQR-ATT-5');
raise exception 'non-staff preview allowed';
exception when raise_exception then
if sqlerrm <> 'staff or admin only' then raise; end if;
end;
perform pg_temp.assert_bp(true, 'preview is staff/admin only');
end; $$;
-- The anonymous role cannot preview either.
select set_config('request.jwt.claims', '{"role":"anon"}', true);
set local role anon;
do $$ begin
begin
perform * from public.preview_welcome_checkin('BPQR-ATT-5');
raise exception 'anon preview allowed';
exception when insufficient_privilege then
null;
end;
perform pg_temp.assert_bp(true, 'anon cannot preview a check-in');
end; $$;
reset role;
-- -----------------------------------------------------------------------------
-- 3. PRINT STATION PROVISIONING AND PERMISSIONS
-- -----------------------------------------------------------------------------