Registration optionset + speaker auto-promote + welcome check-in
- registrations.type is now a Postgres ENUM (registration_type) - session_speakers trigger auto-promotes attendee -> speaker (never overrides staff/sponsor) - new welcome_checkin RPC: staff marks an attendee present at the event - admin Registrations: QR token is final (no reset); failed sponsor change opens in-place sponsor lookup - Convivo Home: Now/Next cards always render; red pending-material pill + popup for speakers - Convivo Agenda: speakers can delete their material to re-upload - Convivo Scan: staff Session/Welcome check-in toggle (uiverse switch) - seed: staff (Bruno/Rita) get a password so staff QR login works after reset 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:
1 parent
adcbb507e9
commit
ffb270c140
16 files changed
+730
-142
No files matched your search
+164
@@ -0,0 +1,164 @@
|
||||
-- =============================================================================
|
||||
-- Convivo — Registration type optionset + speaker auto-promote + welcome check-in
|
||||
--
|
||||
-- 1. `registrations.type` becomes a Postgres ENUM (`registration_type`) — a true
|
||||
-- optionset of the four ticket types, enforced at the database level.
|
||||
-- 2. A trigger auto-promotes a contact's registration from 'attendee' to
|
||||
-- 'speaker' when they're added to `session_speakers` (never overrides
|
||||
-- staff/sponsor — those are explicit ticket types).
|
||||
-- 3. New `welcome_checkin` RPC: staff scan an attendee's lanyard to mark them
|
||||
-- checked in to the EVENT (registrations.checked_in = true). Distinct from
|
||||
-- `checkin_attendee`, which checks someone into a specific session.
|
||||
-- =============================================================================
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 1. REGISTRATION TYPE OPTIONSET (Postgres ENUM)
|
||||
-- -----------------------------------------------------------------------------
|
||||
do $$
|
||||
begin
|
||||
if not exists (select 1 from pg_type where typname = 'registration_type') then
|
||||
create type public.registration_type as enum ('attendee', 'speaker', 'staff', 'sponsor');
|
||||
end if;
|
||||
end $$;
|
||||
|
||||
-- Convert the column to the enum. Existing values ('attendee'/'speaker'/'staff'/
|
||||
-- 'sponsor') all map cleanly. The `type` column name is quoted to avoid any
|
||||
-- keyword ambiguity in the ALTER; the USING clause does the explicit text→enum
|
||||
-- cast (Postgres won't cast text to an enum implicitly). The old text CHECK
|
||||
-- constraint and text default can't be auto-cast, so drop both first, convert,
|
||||
-- then set the enum default.
|
||||
alter table public.registrations drop constraint if exists registrations_type_check;
|
||||
alter table public.registrations alter column "type" drop default;
|
||||
alter table public.registrations
|
||||
alter column "type" type public.registration_type using "type"::public.registration_type;
|
||||
alter table public.registrations
|
||||
alter column "type" set default 'attendee'::public.registration_type;
|
||||
|
||||
-- The admin RPCs take `p_type text` and write it to the (now enum) column.
|
||||
-- Re-create them with an explicit cast so the text param maps to the enum.
|
||||
create or replace function public.create_registration(p_contact_email text, p_type text)
|
||||
returns public.registrations
|
||||
language plpgsql security definer set search_path = public as $$
|
||||
declare
|
||||
v_email text := public.current_email();
|
||||
v_event_id uuid;
|
||||
v_reg public.registrations;
|
||||
begin
|
||||
if v_email is null then raise exception 'not authenticated'; end if;
|
||||
if not public.is_admin() then raise exception 'admin only'; end if;
|
||||
if not exists (select 1 from public.contacts where email = p_contact_email) then
|
||||
raise exception 'contact not found';
|
||||
end if;
|
||||
if p_type is null or p_type not in ('attendee', 'speaker', 'staff', 'sponsor') then
|
||||
raise exception 'invalid registration type';
|
||||
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;
|
||||
if p_type = 'sponsor' and not exists (
|
||||
select 1 from public.sponsors where event_id = v_event_id and contact_email = p_contact_email
|
||||
) then
|
||||
raise exception 'a sponsor registration requires a sponsor lookup';
|
||||
end if;
|
||||
insert into public.registrations (event_id, contact_email, type)
|
||||
values (v_event_id, p_contact_email, p_type::public.registration_type)
|
||||
on conflict (event_id, contact_email) do update set type = excluded.type
|
||||
returning * into v_reg;
|
||||
return v_reg;
|
||||
end;
|
||||
$$;
|
||||
|
||||
create or replace function public.set_registration_type(p_contact_email text, p_type text)
|
||||
returns public.registrations
|
||||
language plpgsql security definer set search_path = public as $$
|
||||
declare
|
||||
v_email text := public.current_email();
|
||||
v_event_id uuid;
|
||||
v_reg public.registrations;
|
||||
begin
|
||||
if v_email is null then raise exception 'not authenticated'; end if;
|
||||
if not public.is_admin() then raise exception 'admin only'; end if;
|
||||
if p_type is null or p_type not in ('attendee', 'speaker', 'staff', 'sponsor') then
|
||||
raise exception 'invalid registration type';
|
||||
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;
|
||||
if p_type = 'sponsor' and not exists (
|
||||
select 1 from public.sponsors where event_id = v_event_id and contact_email = p_contact_email
|
||||
) then
|
||||
raise exception 'a sponsor registration requires a sponsor lookup';
|
||||
end if;
|
||||
update public.registrations set type = p_type::public.registration_type
|
||||
where event_id = v_event_id and contact_email = p_contact_email
|
||||
returning * into v_reg;
|
||||
if not found then raise exception 'registration not found'; end if;
|
||||
return v_reg;
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 2. SPEAKER AUTO-PROMOTE TRIGGER
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- When a contact is added as a speaker of a session, promote their active-event
|
||||
-- registration from 'attendee' to 'speaker'. This is one-way: removing a speaker
|
||||
-- never demotes them, and it never overrides an explicit staff/sponsor ticket.
|
||||
create or replace function public._trg_speaker_promote() returns trigger
|
||||
language plpgsql security definer set search_path = public as $$
|
||||
declare
|
||||
v_event_id uuid;
|
||||
begin
|
||||
if tg_op = 'INSERT' then
|
||||
select s.event_id into v_event_id
|
||||
from public.sessions s where s.id = new.session_id;
|
||||
if v_event_id is not null then
|
||||
update public.registrations
|
||||
set "type" = 'speaker'
|
||||
where event_id = v_event_id
|
||||
and contact_email = new.contact_email
|
||||
and "type" = 'attendee';
|
||||
end if;
|
||||
end if;
|
||||
return new;
|
||||
end;
|
||||
$$;
|
||||
|
||||
drop trigger if exists session_speakers_speaker_promote on public.session_speakers;
|
||||
create trigger session_speakers_speaker_promote
|
||||
after insert on public.session_speakers
|
||||
for each row execute function public._trg_speaker_promote();
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 3. WELCOME CHECK-IN (staff marks an attendee present at the event)
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- Resolves the scanned lanyard QR to the attendee's active-event registration and
|
||||
-- marks them checked in to the event. No points are awarded (that's the session
|
||||
-- check-in's job); this just records that the person is on site.
|
||||
create or replace function public.welcome_checkin(p_attendee_qr text)
|
||||
returns table (attendee_email text, attendee_name text, already boolean)
|
||||
language plpgsql 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;
|
||||
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 into v_attendee, v_name
|
||||
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;
|
||||
update public.registrations set checked_in = true
|
||||
where event_id = v_event_id and contact_email = v_attendee;
|
||||
return query select v_attendee, v_name, coalesce(v_checked, false);
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.welcome_checkin(text) to authenticated;
|
||||
+16
-12
@@ -58,8 +58,8 @@ on conflict (id) do nothing;
|
||||
-- Staff (Bruno/Rita) keep their QR token as the auth password for the attendee app.
|
||||
insert into public.contacts (email, full_name, linkedin_url, show_email, show_linkedin, is_admin, password) values
|
||||
('[email protected]', 'Ana Silva', 'https://linkedin.com/in/anasilva', true, true, false, null),
|
||||
('[email protected]', 'Bruno Costa', 'https://linkedin.com/in/brunocosta', false, true, true, null),
|
||||
('[email protected]', 'Rita Lopes', null, false, false, true, null),
|
||||
('[email protected]', 'Bruno Costa', 'https://linkedin.com/in/brunocosta', false, true, true, 'appe-admin-2026'),
|
||||
('[email protected]', 'Rita Lopes', null, false, false, true, 'appe-admin-2026'),
|
||||
('[email protected]','Tomás Ribeiro', null, false, false, false, null),
|
||||
('[email protected]', 'Sofia Almeida', null, false, false, false, null),
|
||||
('[email protected]', 'Marco Chen', null, false, false, false, null),
|
||||
@@ -85,19 +85,23 @@ on conflict (id) do nothing;
|
||||
-- (per event, generated by Pretix) and doubles as the auth password.
|
||||
-- Ana is checked in (has check-ins below).
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- Note: everyone who speaks in a session is typed 'speaker' (the
|
||||
-- session_speakers_speaker_promote trigger auto-promotes 'attendee' → 'speaker'
|
||||
-- on insert, so the seed states the final type explicitly). Only Bruno, Rita and
|
||||
-- the admin are 'staff' (the trigger never overrides an explicit staff/sponsor).
|
||||
insert into public.registrations (event_id, contact_email, type, checked_in, points, qr_token) values
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', true, 40, 'CVV-ANA-4821'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'speaker', true, 40, 'CVV-ANA-4821'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'staff', false, 140, 'CVV-BRU-1177'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'staff', false, 95, 'CVV-RIT-9034'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]','attendee', false, 88, 'CVV-TOM-5566'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 76, 'CVV-SOF-2299'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 70, 'CVV-MRC-7712'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 64, 'CVV-JUL-3345'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 58, 'CVV-PED-8801'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 52, 'CVV-CAR-6623'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 35, 'CVV-DIE-4458'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 28, 'CVV-MNA-2210'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 15, 'CVV-LUC-9987'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]','speaker', false, 88, 'CVV-TOM-5566'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'speaker', false, 76, 'CVV-SOF-2299'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'speaker', false, 70, 'CVV-MRC-7712'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'speaker', false, 64, 'CVV-JUL-3345'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'speaker', false, 58, 'CVV-PED-8801'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'speaker', false, 52, 'CVV-CAR-6623'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'speaker', false, 35, 'CVV-DIE-4458'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'speaker', false, 28, 'CVV-MNA-2210'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'speaker', false, 15, 'CVV-LUC-9987'),
|
||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'staff', false, 0, 'CVV-ADM-0001')
|
||||
on conflict (event_id, contact_email) do nothing;
|
||||
|
||||
|
||||
Reference in new issue
Block a user