feat: add admin raffle with confetti and top-3/staff exclusion

This commit is contained in:
Lago committed 2026-10-15 21:39:57 +02:00
1 parent 5117a25372
commit 3e2f8ff0ed
14 files changed
+680 -2

No files matched your search

+25
View File
@@ -394,6 +394,31 @@ All are `security definer` so they can read `contacts` / `registrations` /
|---|---|---|
| `_assign_service_session_speakers(p_session_id, p_event_id)` | `integer` | Links **every registered staff member** of the event as a speaker of the given session (`on conflict do nothing`). Returns the number of rows affected. Called by both Sessionize sync RPCs for `service_session` sessions — a service session has no individual speaker, so the whole staff team "owns" it. |
## Raffle
Source: [20261015180640_raffle.sql](../../supabase/migrations/20261015180640_raffle.sql).
The admin **Raffle** view draws eligible attendees one at a time for the active
event. Winner selection is authoritative **server-side** (random), so the client
roulette animation only has to decelerate onto the returned name.
- `get_raffle_pool()` → `contact_email, full_name, points` — the eligible
attendees: non-staff, non-Admin (`is_admin` or `@appe.at`), **not** in the
leaderboard **top 3** (`get_leaderboard() limit 3`), and **not** already drawn
in the current run. Returns `[]` for non-admins (guarded by `is_admin()`).
- `draw_raffle_winner()` → `contact_email, full_name, points, draw_number` —
**admin-only.** Picks one random eligible attendee, records them in
`raffle_draws` with the next sequential `draw_number`, and returns the winner.
Raises `No eligible attendees left to draw` when the pool is empty.
- `reset_raffle()` → `void` — **admin-only.** Deletes the current run's winners
for the active event so a new run can begin.
The `raffle_draws` table is keyed by `(event_id, contact_email)` (so an attendee
can win at most once per run), cascades on event/contact deletion, and is
admin-readable via RLS. All three functions are `security definer` with an empty
`search_path`, revoke execution from `PUBLIC` / `anon`, and grant it back only to
`authenticated` (the admin check is enforced inside each function).
## Error handling
RPCs raise Postgres exceptions with human-readable messages (e.g. `you cannot
+21
View File
@@ -1,3 +1,24 @@
# Raffle Regression
After applying `20261015180640_raffle`, run:
```sh
docker exec -i supabase_db_Convivo psql -X -U postgres -d postgres \
-v ON_ERROR_STOP=1 < supabase/tests/raffle_tests.sql
CONVIVO_ADMIN_URL=http://127.0.0.1:3001 npm test --prefix e2e -- raffle.spec.ts --project=chromium
```
The SQL fixture is rollback-only: fifteen assertions cover the eligible pool
(excluding staff, Admin, the `@appe.at` domain and the leaderboard top 3),
sequential draw numbers, drawn attendees leaving the pool, the empty-pool
over-draw error, winner persistence, run reset, and admin/non-admin/anon
authorization. The browser suite is API-mocked and covers the default five
picks, the decelerating roulette landing on a winner, drawing until the pick
count, retry after a failed draw, starting a new run, a configurable pick
count, and the mobile layout. No real LLM, email or points change is involved.
See [RPC rules](./rpcs.md#raffle) and the [Raffle view](../frontend/admin-app.md).
# Leaderboard Regression
After applying `20261015164546_leaderboard_staff_admin_exclusion`, run: