Redesign Phases 3-6: multi-event model, APPE Admin, Convivo App behaviors, APPE branding

- Phase 3: new migration 20260824000000_redesign.sql (contacts/events/registrations/sponsors, slot types, session speakers + feedback/material), seed rewrite
- Phase 4: APPE Admin rebrand + Contacts/Registrations/Sponsors/Schedule/Activity/Events views
- Phase 5: Convivo App (24h login, 5s polling, QR type badge, red dot, speaker material)
- Phase 6: APPE favicon + PWA icons for both apps
- Docs: schema/rpcs/rls/seed/screens/api-client/admin-app/architecture/next-steps/README/roadmap updated
This commit is contained in:
Lago committed 2026-08-23 02:53:16 +02:00
1 parent 5adb5785aa
commit 22f5f1d317
64 files changed
+4593 -1371

No files matched your search

+103 -61
View File
@@ -1,12 +1,12 @@
# Row Level Security (RLS)
RLS is the security boundary. It is **enabled on all 9 tables**, and every policy
is scoped to the `authenticated` role. The `anon` role has `GRANT select` at the
Postgres level, but RLS blocks it from reading anything — so an unauthenticated
request sees no rows.
RLS is the security boundary. It is **enabled on all 13 tables**, and every
policy is scoped to the `authenticated` role. The `anon` role has `GRANT select`
at the Postgres level, but RLS blocks it from reading anything — so an
unauthenticated request sees no rows.
Source of truth:
[`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql)
[`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql)
(RLS section).
## Which key does the app use?
@@ -26,91 +26,132 @@ Source of truth:
## Role helpers
Two `security definer` functions drive role checks (see [rpcs.md](./rpcs.md#role-helper-functions)):
- `is_admin()` — current user's profile has `role = 'admin'`
- `is_staff_or_admin()` — current user's profile has `role in ('staff','admin')`
`security definer` functions drive role checks (see
[rpcs.md](./rpcs.md#role-helper-functions)):
- `current_email()` — `auth.jwt() ->> 'email'` (the identity; `contacts` is keyed
by email)
- `is_admin()` — current contact has `is_admin = true`
- `is_staff_or_admin()` — = `is_admin()` (staff is merged into admin)
- `is_speaker_or_admin()` — admin, or a speaker of an active-event session, or a
`speaker`-type registration
## Policies by table
| Table | SELECT | INSERT | UPDATE | DELETE |
|---|---|---|---|---|
| `profiles` | own **or** admin | — | admin only | admin only |
| `contacts` | own **or** admin | — | admin only | admin only |
| `events` | all authenticated | admin only | admin only | admin only |
| `registrations` | own **or** admin | admin only | admin only | admin only |
| `sponsors` | admin **or** `paid` | admin only | admin only | admin only |
| `slots` | all authenticated | admin only | admin only | admin only |
| `sessions` | all authenticated | admin only | admin only | admin only |
| `preferences` | own **or** admin | — | — | — |
| `session_speakers` | all authenticated | admin only | admin only | admin only |
| `preferences` | own | — | — | — |
| `connections` | rows you're in **or** admin | — | — | — |
| `checkins` | own **or** staff/admin | — | — | — |
| `checkins` | own **or** admin | — | — | — |
| `feedback` | own **or** admin | — | — | — |
| `leaderboard` | all authenticated | — | — | — |
| `points_log` | own **or** admin | — | — | — |
> **Phase 2 addition** ([`20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql)):
> admin-only `select` policies were added to `preferences`, `connections`, and
> `feedback` so the Admin console can read the full activity. The per-user
> policies above are unchanged — these are additive `OR is_admin()` reads.
**"—" (no policy)** means normal users have **no direct write access** — those
tables are written only by the `security definer` RPCs, which bypass RLS. This is
deliberate: a client cannot `UPDATE profiles SET points = 9999` or insert its own
check-in. See [rpcs.md](./rpcs.md).
deliberate: a client cannot `UPDATE registrations SET points = 9999` or insert its
own check-in. See [rpcs.md](./rpcs.md).
> **Admin reads the full activity.** The `connections`, `checkins`, and `feedback`
> select policies include `or public.is_admin()`, so the APPE Admin console's
> Activity view sees every row (an admin is "involved" in none of them, so a
> pure "involved/own" policy would show 0).
### The exact policies
```sql
-- profiles: read own or admin; write admin only
create policy "profiles_select_own_or_admin" on public.profiles for select to authenticated
using (id = auth.uid() or public.is_admin());
create policy "profiles_update_admin" on public.profiles for update to authenticated
-- contacts: read own or admin; write admin only
create policy "contacts_select_own_or_admin" on public.contacts for select to authenticated
using (email = public.current_email() or public.is_admin());
create policy "contacts_admin_update" on public.contacts for update to authenticated
using (public.is_admin()) with check (public.is_admin());
create policy "profiles_delete_admin" on public.profiles for delete to authenticated
create policy "contacts_admin_delete" on public.contacts for delete to authenticated
using (public.is_admin());
-- slots / sessions: readable by any authenticated user (public agenda); admin writes
-- events: readable by all authenticated; writable by admin
create policy "events_select_all" on public.events for select to authenticated using (true);
create policy "events_admin_insert" on public.events for insert to authenticated with check (public.is_admin());
create policy "events_admin_update" on public.events for update to authenticated
using (public.is_admin()) with check (public.is_admin());
create policy "events_admin_delete" on public.events for delete to authenticated using (public.is_admin());
-- registrations: own or admin
create policy "registrations_select_own_or_admin" on public.registrations for select to authenticated
using (contact_email = public.current_email() or public.is_admin());
-- (admin-only insert/update/delete)
-- sponsors: admin sees all; non-admin sees only paid sponsors
create policy "sponsors_select" on public.sponsors for select to authenticated
using (public.is_admin() or paid);
-- (admin-only insert/update/delete)
-- slots / sessions / session_speakers: readable by any authenticated user; admin writes
create policy "slots_select_all" on public.slots for select to authenticated using (true);
create policy "slots_admin_insert" on public.slots for insert to authenticated with check (public.is_admin());
create policy "slots_admin_update" on public.slots for update to authenticated using (public.is_admin()) with check (public.is_admin());
create policy "slots_admin_delete" on public.slots for delete to authenticated using (public.is_admin());
-- (sessions: identical four policies)
create policy "sessions_select_all" on public.sessions for select to authenticated using (true);
create policy "session_speakers_select_all" on public.session_speakers for select to authenticated using (true);
-- (each has admin-only insert/update/delete)
-- preferences: read own
create policy "prefs_select_own" on public.preferences for select to authenticated
using (profile_id = auth.uid());
using (contact_email = public.current_email());
-- connections: read rows you're involved in
create policy "conn_select_involved" on public.connections for select to authenticated
using (from_id = auth.uid() or to_id = auth.uid());
-- connections: read rows you're part of (or all if admin)
create policy "conn_select_involved_or_admin" on public.connections for select to authenticated
using (from_email = public.current_email() or to_email = public.current_email() or public.is_admin());
-- checkins: read own or staff/admin
create policy "checkins_select_own_or_staff" on public.checkins for select to authenticated
using (profile_id = auth.uid() or public.is_staff_or_admin());
-- checkins: read own, or all if admin
create policy "checkins_select_own_or_admin" on public.checkins for select to authenticated
using (contact_email = public.current_email() or public.is_admin());
-- feedback: read own
create policy "feedback_select_own" on public.feedback for select to authenticated
using (profile_id = auth.uid());
-- feedback: read own, or all if admin
create policy "feedback_select_own_or_admin" on public.feedback for select to authenticated
using (contact_email = public.current_email() or public.is_admin());
-- leaderboard: readable by any authenticated user
-- leaderboard: public to all authenticated (Realtime source)
create policy "leaderboard_select_all" on public.leaderboard for select to authenticated using (true);
-- points_log: read own or admin
create policy "points_log_select_own_or_admin" on public.points_log for select to authenticated
using (profile_id = auth.uid() or public.is_admin());
-- Phase 2 (20260823000000_admin_app.sql): additive admin-only reads for the
-- Admin console. These OR with the per-user policies above.
create policy "prefs_select_admin" on public.preferences for select to authenticated using (public.is_admin());
create policy "conn_select_admin" on public.connections for select to authenticated using (public.is_admin());
create policy "feedback_select_admin" on public.feedback for select to authenticated using (public.is_admin());
using (contact_email = public.current_email() or public.is_admin());
```
## Storage — `materials` bucket
The `materials` bucket (public read) stores session material. Policies on
`storage.objects`:
```sql
create policy "materials_read" on storage.objects for select to authenticated
using (bucket_id = 'materials');
create policy "materials_write" on storage.objects for insert to authenticated
with check (bucket_id = 'materials' and public.is_speaker_or_admin());
create policy "materials_update" on storage.objects for update to authenticated
using (bucket_id = 'materials' and public.is_speaker_or_admin());
create policy "materials_delete" on storage.objects for delete to authenticated
using (bucket_id = 'materials' and public.is_speaker_or_admin());
```
Speakers + admins can write; any authenticated attendee can read (download).
Because the `sessions` table is admin-write only, a speaker attaches their
uploaded file via the `set_session_material` RPC (see
[rpcs.md](./rpcs.md#set_session_materialp_session_id-p_material_path--sessions)).
## GRANTs
The new Supabase CLI does **not** auto-expose new tables to the Data API roles, so
the migration grants explicitly (RLS still governs what each role can actually see):
the migration grants explicitly (RLS still governs what each role can actually
see):
```sql
grant usage on schema public to anon, authenticated, service_role;
grant select on <all 9 tables> to anon, authenticated, service_role;
grant insert, update, delete on <all 9 tables> to authenticated, service_role;
grant select on <all 13 tables> to anon, authenticated, service_role;
grant insert, update, delete on <all 13 tables> to authenticated, service_role;
grant execute on function <all public RPCs + helpers> to authenticated;
```
@@ -119,20 +160,21 @@ full DML at the Postgres level, but **RLS narrows it** to the policies above.
## Net effect by role
- **Attendee** — sees their own profile/prefs/connections/feedback, the full
agenda, and the leaderboard; can only act through the RPCs (which re-check role
internally, e.g. only staff can call `checkin_attendee`).
- **Staff** — everything an attendee can do, plus can read all `checkins` and call
the check-in RPC.
- **Admin** — full read on everything (including all `preferences`,
`connections`, and `feedback`), and the only role with **direct** write access
to `profiles` / `slots` / `sessions`. This is exactly what the Admin console
(Phase 2, [`../frontend/admin-app.md`](../frontend/admin-app.md)) uses.
- **Attendee** — sees their own contact/registration/prefs/connections/feedback,
the full agenda, the public contact directory, and the leaderboard; can only act
through the RPCs (which re-check role internally, e.g. only staff can call
`checkin_attendee`).
- **Staff (= admin)** — everything an attendee can do, plus can read all
`checkins` / `connections` / `feedback` and call the check-in RPC.
- **Admin** — full read on everything, and the only role with **direct** write
access to `contacts` / `events` / `registrations` / `sponsors` / `slots` /
`sessions` / `session_speakers`. This is exactly what the APPE Admin console
([../frontend/admin-app.md](../frontend/admin-app.md)) uses.
## Things to revisit later
- `slots` / `sessions` are readable by *any* authenticated user (fine — it's a
public agenda). If you ever want the agenda hidden until the event, that's a
one-line policy change.
- `slots` / `sessions` / `session_speakers` are readable by *any* authenticated
user (fine — it's a public agenda). If you ever want the agenda hidden until the
event, that's a one-line policy change.
- `leaderboard` exposes every attendee's name + points to any authenticated user.
That's the intended product behavior (a public leaderboard).