From 567d7e5d40b528541071611d47b691c57d596b9b Mon Sep 17 00:00:00 2001 From: Jose Lago Date: Wed, 9 Sep 2026 13:09:04 +0200 Subject: [PATCH] Force admin registrations to staff type (no exception) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a BEFORE INSERT OR UPDATE trigger on public.registrations: if the registrant is an admin (is_admin flag OR @appe.at domain — same rule as is_admin()), the registration type is forced to 'staff' (staff is merged into admin in this app). No exception. Enforced at the DB transaction level, so it covers every write path — the Pretix sync RPC, Sessionize sync, manual admin edits, direct Postgres. Backfilled the 2 existing admin registrations (lago@appe.at, markus@appe.at were 'attendee' -> now 'staff'). Verified: setting an admin reg to 'attendee' is immediately forced back to 'staff'. Co-authored-by: Stephan Charles Co-authored-by: Amelia Hernandez Co-authored-by: Markus Franz Co-authored-by: Sabrina Hota Co-authored-by: Nilüfer Doğan --- ...0260909030000_admin_registration_staff.sql | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 supabase/migrations/20260909030000_admin_registration_staff.sql diff --git a/supabase/migrations/20260909030000_admin_registration_staff.sql b/supabase/migrations/20260909030000_admin_registration_staff.sql new file mode 100644 index 0000000..077641d --- /dev/null +++ b/supabase/migrations/20260909030000_admin_registration_staff.sql @@ -0,0 +1,47 @@ +-- ============================================================================= +-- Convivo — admin registrations are always `staff` (no exception) +-- +-- Business rule: if a contact is an admin (is_admin flag OR @appe.at domain — +-- the same rule as public.is_admin()), then their registration for ANY event +-- must always be type `staff` (staff is merged into admin in this app). No +-- exception. +-- +-- Enforced at the DB transaction level via a BEFORE INSERT OR UPDATE trigger on +-- public.registrations, so it applies to every write path — the Pretix sync +-- RPC, the Sessionize sync, manual admin edits, direct Postgres, etc. +-- +-- Also backfills the existing rows so current admin registrations are corrected +-- immediately. +-- ============================================================================= + +create or replace function public._admin_registration_staff() +returns trigger +language plpgsql security definer set search_path = public as $$ +begin + -- If the registrant is an admin (flag or @appe.at domain), force the + -- registration type to `staff`. No exception. + if exists ( + select 1 from public.contacts + where email = new.contact_email + and (is_admin or email like '%@appe.at') + ) then + new.type := 'staff'::public.registration_type; + end if; + return new; +end; +$$; + +drop trigger if exists trg_registrations_admin_staff on public.registrations; +create trigger trg_registrations_admin_staff + before insert or update on public.registrations + for each row execute function public._admin_registration_staff(); + +-- Backfill: correct any existing admin registrations (idempotent). +update public.registrations r +set type = 'staff'::public.registration_type +where r.type <> 'staff'::public.registration_type + and exists ( + select 1 from public.contacts c + where c.email = r.contact_email + and (c.is_admin or c.email like '%@appe.at') + );