Force admin registrations to staff type (no exception)
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 ([email protected], [email protected] were 'attendee' -> now 'staff'). Verified: setting an admin reg to 'attendee' is immediately forced back to 'staff'. 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
265e38aade
commit
567d7e5d40
1 file changed
+47
@@ -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')
|
||||||
|
);
|
||||||
Reference in new issue
Block a user