The front-desk check-in set checked_in and printed badges but awarded nothing, so the +10 depended on which check-in a person happened to get. Every award path was reviewed: - welcome_checkin awards +10 (category checkin) on a genuine first check-in and returns points + points_awarded; checkin_attendee and preview_welcome_checkin return points_awarded too. - set_registration_checked_in(false) deleted all checkin points while keeping the checkins rows, and switching back on awarded nothing -- one mistaken toggle destroyed those points permanently. ON now recomputes from the rows that still exist and awards only the shortfall: reversible, still unfarmable. - The staff/Admin/@appe.at exclusion stays (product decision) but is no longer silent: three-way points sheets in the scanner, "no points" with a tooltip in Registrations, and the Contacts points modal refuses to apply rather than letting adjust_points (void) no-op quietly. Also in this change: - admin silent refresh (5s poll + 500ms after writes) across all data views; Registrations patches in place so rows never slide under the cursor - Settings "Validate AI connection" via a new sidecar POST /llm-test verdict endpoint (never leaks the key, distinguishes "no usage block" from "off") - new Sessions view between Schedule and Activity: speakers, attendance, ratings, attendee filter, and one button that summarises every session with feedback (one request each, concurrency 3, UI blocked until all settle) - provider requests disable thinking through one shared body builder sending both reasoning_effort:"none" and chat_template_kwargs.enable_thinking SQL: 113 / 57 / 24 assertions (set_registration_checked_in section 3 was rewritten, it asserted the bug). Sidecar 34 unit tests. Full e2e 202 passed, 0 failed. Migration applied locally only -- not deployed. 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]>
238 lines
12 KiB
PL/PgSQL
238 lines
12 KiB
PL/PgSQL
-- set_registration_checked_in: admin flips checked_in. Un-checking removes the
|
|
-- attendee's check-in points (and only those); re-checking restores the points
|
|
-- that the surviving check-in rows justify, without letting repeated clicks
|
|
-- farm points. Run inside a transaction that is rolled back, like other suites.
|
|
\set ON_ERROR_STOP on
|
|
begin;
|
|
|
|
create temporary table scr_results (name text);
|
|
grant insert, select on scr_results to authenticated, anon;
|
|
create function pg_temp.assert_scr(p_condition boolean, p_name text) returns void
|
|
language plpgsql as $$
|
|
begin
|
|
if p_condition is distinct from true then raise exception 'FAIL: %', p_name; end if;
|
|
insert into scr_results values (p_name);
|
|
end;
|
|
$$;
|
|
|
|
-- -----------------------------------------------------------------------------
|
|
-- Fixtures: one active event, an admin, a plain attendee with a mix of points.
|
|
-- -----------------------------------------------------------------------------
|
|
update public.events set is_active = false where is_active;
|
|
insert into public.events (id, name, start_date, end_date, is_active)
|
|
values ('c7e10000-0000-0000-0000-000000000001', 'SCR regression', current_date, current_date, true);
|
|
|
|
insert into public.contacts (email, full_name, is_admin)
|
|
values ('[email protected]', 'SCR Admin', true),
|
|
('[email protected]', 'SCR User', false),
|
|
('[email protected]', 'SCR Other', false);
|
|
|
|
insert into public.registrations (id, event_id, contact_email, type, qr_token, checked_in, points)
|
|
values ('c7e10000-0000-0000-0000-000000000011', 'c7e10000-0000-0000-0000-000000000001', '[email protected]', 'attendee', 'SCRQR-1', true, 40),
|
|
('c7e10000-0000-0000-0000-000000000012', 'c7e10000-0000-0000-0000-000000000001', '[email protected]', 'attendee', 'SCRQR-2', true, 25);
|
|
|
|
-- 40 pts = 3x checkin (10+10+10) + connection 10 + feedback 10.
|
|
insert into public.points_log (event_id, contact_email, delta, category)
|
|
values ('c7e10000-0000-0000-0000-000000000001', '[email protected]', 10, 'checkin'),
|
|
('c7e10000-0000-0000-0000-000000000001', '[email protected]', 10, 'checkin'),
|
|
('c7e10000-0000-0000-0000-000000000001', '[email protected]', 10, 'checkin'),
|
|
('c7e10000-0000-0000-0000-000000000001', '[email protected]', 10, 'connection'),
|
|
('c7e10000-0000-0000-0000-000000000001', '[email protected]', 10, 'feedback');
|
|
-- Other attendee: only connection points, no checkin rows.
|
|
insert into public.points_log (event_id, contact_email, delta, category)
|
|
values ('c7e10000-0000-0000-0000-000000000001', '[email protected]', 25, 'connection');
|
|
|
|
-- Leaderboard mirrors the starting points (trigger keeps it in sync).
|
|
select pg_temp.assert_scr(
|
|
(select points = 40 from public.leaderboard
|
|
where event_id = 'c7e10000-0000-0000-0000-000000000001' and contact_email = '[email protected]'),
|
|
'leaderboard starts at 40');
|
|
|
|
-- -----------------------------------------------------------------------------
|
|
-- 1. Admin un-checks: check-in points removed, other categories untouched.
|
|
-- -----------------------------------------------------------------------------
|
|
select set_config('request.jwt.claims', '{"email":"[email protected]","role":"authenticated"}', true);
|
|
|
|
create temporary table scr_off as
|
|
select * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000011', false);
|
|
select pg_temp.assert_scr(
|
|
(select checked_in = false and points_removed = 30 from scr_off),
|
|
'un-check-in reports 30 points removed');
|
|
select pg_temp.assert_scr(
|
|
(select checked_in = false from public.registrations where qr_token = 'SCRQR-1'),
|
|
'registration is unchecked');
|
|
select pg_temp.assert_scr(
|
|
(select points = 10 from public.registrations where qr_token = 'SCRQR-1'),
|
|
'registration keeps non-checkin points');
|
|
select pg_temp.assert_scr(
|
|
(select count(*) = 0 from public.points_log
|
|
where contact_email = '[email protected]' and category = 'checkin'),
|
|
'checkin rows deleted from the audit log');
|
|
select pg_temp.assert_scr(
|
|
(select count(*) = 2 from public.points_log
|
|
where contact_email = '[email protected]' and category in ('connection', 'feedback')),
|
|
'other categories keep their audit rows');
|
|
select pg_temp.assert_scr(
|
|
(select count(*) = 1 and coalesce(min(delta), 0) = -30 from public.points_log
|
|
where contact_email = '[email protected]' and category = 'admin'),
|
|
'reversal recorded as a single -30 admin row');
|
|
select pg_temp.assert_scr(
|
|
(select points = 10 from public.leaderboard
|
|
where event_id = 'c7e10000-0000-0000-0000-000000000001' and contact_email = '[email protected]'),
|
|
'leaderboard synced down to 10');
|
|
|
|
-- -----------------------------------------------------------------------------
|
|
-- 2. Un-checking someone with no checkin points: no-op, zero removed.
|
|
-- -----------------------------------------------------------------------------
|
|
create temporary table scr_off2 as
|
|
select * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000012', false);
|
|
select pg_temp.assert_scr(
|
|
(select checked_in = false and points_removed = 0 from scr_off2),
|
|
'un-check-in without checkin points removes nothing');
|
|
select pg_temp.assert_scr(
|
|
(select points = 25 from public.registrations where qr_token = 'SCRQR-2'),
|
|
'other attendee keeps their points');
|
|
|
|
-- -----------------------------------------------------------------------------
|
|
-- 3. Re-checking RESTORES the points the surviving check-in rows justify.
|
|
-- Section 1 deleted the audit rows but the attendance records remain, so the
|
|
-- old behaviour (award nothing, permanently) left this person 30 points short
|
|
-- with no way back. Toggling on now recomputes from the rows: 10 per session
|
|
-- check-in + 10 for the front desk.
|
|
-- -----------------------------------------------------------------------------
|
|
-- Real attendance for scr-user: two sessions. Negative slot ids keep these
|
|
-- fixtures out of every real event's schedule.
|
|
insert into public.slots (id, event_id, name, slot_date, start_time, end_time, type)
|
|
values (-152001, 'c7e10000-0000-0000-0000-000000000001', 'SCR Talk A', current_date, '09:00', '10:00', 'session');
|
|
insert into public.sessions (id, event_id, slot_id, title)
|
|
values ('c7e10000-0000-0000-0000-0000000000a1', 'c7e10000-0000-0000-0000-000000000001', -152001, 'SCR Session one'),
|
|
('c7e10000-0000-0000-0000-0000000000a2', 'c7e10000-0000-0000-0000-000000000001', -152001, 'SCR Session two');
|
|
insert into public.checkins (event_id, contact_email, session_id, staff_email)
|
|
values ('c7e10000-0000-0000-0000-000000000001', '[email protected]', 'c7e10000-0000-0000-0000-0000000000a1', '[email protected]'),
|
|
('c7e10000-0000-0000-0000-000000000001', '[email protected]', 'c7e10000-0000-0000-0000-0000000000a2', '[email protected]');
|
|
|
|
create temporary table scr_on as
|
|
select * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000011', true);
|
|
select pg_temp.assert_scr(
|
|
(select checked_in = true and points_removed = 0 and points_added = 30 from scr_on),
|
|
're-check-in restores 30 points (2 sessions + front desk)');
|
|
select pg_temp.assert_scr(
|
|
(select points = 40 from public.registrations where qr_token = 'SCRQR-1'),
|
|
'points back to the pre-uncheck total after re-check-in');
|
|
select pg_temp.assert_scr(
|
|
(select points = 40 from public.leaderboard
|
|
where event_id = 'c7e10000-0000-0000-0000-000000000001' and contact_email = '[email protected]'),
|
|
'leaderboard synced back up to 40');
|
|
|
|
-- Toggling on again is idempotent: the award already matches what the rows
|
|
-- justify, so repeated clicks cannot farm points.
|
|
create temporary table scr_on2 as
|
|
select * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000011', true);
|
|
select pg_temp.assert_scr(
|
|
(select points_added = 0 from scr_on2),
|
|
'second re-check-in awards nothing (not farmable)');
|
|
select pg_temp.assert_scr(
|
|
(select points = 40 from public.registrations where qr_token = 'SCRQR-1'),
|
|
'points unchanged by a repeat toggle on');
|
|
|
|
-- Full round trip is symmetric: off removes exactly what on gives back.
|
|
create temporary table scr_off3 as
|
|
select * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000011', false);
|
|
select pg_temp.assert_scr(
|
|
(select points_removed = 30 from scr_off3),
|
|
'un-check-in again removes the same 30');
|
|
create temporary table scr_on4 as
|
|
select * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000011', true);
|
|
select pg_temp.assert_scr(
|
|
(select points_added = 30 from scr_on4),
|
|
'and toggling on restores it once more');
|
|
|
|
-- Someone with attendance but no session check-ins at all earns only the
|
|
-- front-desk +10 on the way back on (SCRQR-2 has connection points, no rows).
|
|
create temporary table scr_on3 as
|
|
select * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000012', true);
|
|
select pg_temp.assert_scr(
|
|
(select points_added = 10 from scr_on3),
|
|
'front-desk-only restore awards 10');
|
|
select pg_temp.assert_scr(
|
|
(select points = 35 from public.registrations where qr_token = 'SCRQR-2'),
|
|
'front-desk +10 lands on top of connection points');
|
|
|
|
-- -----------------------------------------------------------------------------
|
|
-- 3b. Staff and Admin-domain contacts stay at zero in both directions.
|
|
-- -----------------------------------------------------------------------------
|
|
insert into public.contacts (email, full_name, is_admin)
|
|
values ('[email protected]', 'SCR Staff', false);
|
|
insert into public.registrations (id, event_id, contact_email, type, qr_token, checked_in, points)
|
|
values ('c7e10000-0000-0000-0000-000000000013', 'c7e10000-0000-0000-0000-000000000001',
|
|
'[email protected]', 'staff', 'SCRQR-3', true, 0);
|
|
insert into public.checkins (event_id, contact_email, session_id, staff_email)
|
|
values ('c7e10000-0000-0000-0000-000000000001', '[email protected]', 'c7e10000-0000-0000-0000-0000000000a1', '[email protected]');
|
|
create temporary table scr_staff_off as
|
|
select * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000013', false);
|
|
create temporary table scr_staff_on as
|
|
select * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000013', true);
|
|
select pg_temp.assert_scr(
|
|
((select points_removed = 0 from scr_staff_off) and (select points_added = 0 from scr_staff_on)),
|
|
'staff toggle moves no points in either direction');
|
|
select pg_temp.assert_scr(
|
|
(select points = 0 from public.registrations where qr_token = 'SCRQR-3'),
|
|
'staff registration stays at zero');
|
|
|
|
-- -----------------------------------------------------------------------------
|
|
-- 4. Unknown registration id is rejected.
|
|
-- -----------------------------------------------------------------------------
|
|
do $$ begin
|
|
begin
|
|
perform * from public.set_registration_checked_in('c7e10000-0000-0000-0000-00000000dead', true);
|
|
raise exception 'missing registration allowed';
|
|
exception when raise_exception then
|
|
if sqlerrm <> 'registration not found' then raise; end if;
|
|
end;
|
|
perform pg_temp.assert_scr(true, 'unknown registration rejected');
|
|
end; $$;
|
|
|
|
-- -----------------------------------------------------------------------------
|
|
-- 5. Non-admin cannot call it (plain RAISE EXCEPTION → raise_exception).
|
|
-- -----------------------------------------------------------------------------
|
|
select set_config('request.jwt.claims', '{"email":"[email protected]","role":"authenticated"}', true);
|
|
do $$ begin
|
|
begin
|
|
perform * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000011', false);
|
|
raise exception 'non-admin un-check-in allowed';
|
|
exception when raise_exception then
|
|
if sqlerrm <> 'admin only' then raise; end if;
|
|
end;
|
|
perform pg_temp.assert_scr(true, 'un-check-in is admin only');
|
|
end; $$;
|
|
|
|
-- -----------------------------------------------------------------------------
|
|
-- 6. The anonymous role cannot execute it at all.
|
|
-- -----------------------------------------------------------------------------
|
|
select set_config('request.jwt.claims', '{"role":"anon"}', true);
|
|
set local role anon;
|
|
do $$ begin
|
|
begin
|
|
perform * from public.set_registration_checked_in(
|
|
'c7e10000-0000-0000-0000-000000000011', false);
|
|
raise exception 'anon un-check-in allowed';
|
|
exception when insufficient_privilege then
|
|
null;
|
|
end;
|
|
perform pg_temp.assert_scr(true, 'anon cannot flip check-in');
|
|
end; $$;
|
|
reset role;
|
|
|
|
select count(*) as passed_assertions from scr_results;
|
|
rollback;
|