feat(sessions): material downloads unlock when the session ends
Private materials bucket + RLS read gate (admins/own speakers anytime, all attendees after the scheduled slot end, event-local Amsterdam time); always visible uploaded-state, locked download panel, authenticated client downloads, admin signed URLs. 12 new assertions in material_time_lock_tests.sql. 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
7776145a77
commit
a8f3f5b8e1
13 files changed
+334
-30
No files matched your search
+12
-2
@@ -123,12 +123,15 @@ create policy "points_log_select_own_or_admin" on public.points_log for select t
|
||||
|
||||
## Storage — `materials` bucket
|
||||
|
||||
The `materials` bucket (public read) stores session material. Policies on
|
||||
The `materials` bucket is **private** and stores session material. Downloads
|
||||
unlock when the session's scheduled end has passed (event-local Amsterdam
|
||||
time) — until then only the session's own speakers and admins can read the
|
||||
object, so a known path/URL does not release the bytes early. Policies on
|
||||
`storage.objects`:
|
||||
|
||||
```sql
|
||||
create policy "materials_read" on storage.objects for select to authenticated
|
||||
using (bucket_id = 'materials');
|
||||
using (public.can_read_session_material(bucket_id, name));
|
||||
create policy "materials_write" on storage.objects for insert to authenticated
|
||||
with check (bucket_id = 'materials' and public.can_write_session_material(name));
|
||||
create policy "materials_update" on storage.objects for update to authenticated
|
||||
@@ -138,6 +141,13 @@ create policy "materials_delete" on storage.objects for delete to authenticated
|
||||
using (bucket_id = 'materials' and public.can_write_session_material(name));
|
||||
```
|
||||
|
||||
`can_read_session_material` (security definer, `20261021180000_material_time_lock.sql`)
|
||||
parses `sessions/<uuid>/<file>` paths, allows `is_admin()` and
|
||||
`owns_speaker_session(uuid)` at any time, everyone else only once
|
||||
`session_material_unlocked(uuid)` holds (slot `slot_date + end_time <=
|
||||
timezone('Europe/Amsterdam', now())`). Anything malformed or in another bucket
|
||||
is denied by this policy (other buckets keep their own policies).
|
||||
|
||||
Registered speakers can write only their own non-service session paths; admins
|
||||
retain material management access. Any authenticated attendee can read (download).
|
||||
Because the `sessions` table is admin-write only, a speaker attaches their
|
||||
|
||||
@@ -366,7 +366,10 @@ enqueuing, claiming, completing and dead-lettering all go through the RPCs in
|
||||
|
||||
## Storage
|
||||
|
||||
A **`materials`** bucket (public read) stores session material. Speakers + admins
|
||||
can write (see [rls.md](./rls.md#storage--materials-bucket)). A session's
|
||||
`material_path` points at the object; the public URL is
|
||||
`/storage/v1/object/public/materials/{material_path}`.
|
||||
A **`materials`** bucket (**private** since `20261021180000_material_time_lock.sql`)
|
||||
stores session material. Speakers + admins can write (see
|
||||
[rls.md](./rls.md#storage--materials-bucket)). A session's `material_path`
|
||||
points at the object. Files are fetched through **authenticated** storage
|
||||
requests (attendee app) or short-lived signed URLs (admin app); the read policy
|
||||
releases a file to plain attendees only after the session's scheduled end —
|
||||
`/storage/v1/object/public/...` URLs no longer serve materials.
|
||||
@@ -80,8 +80,10 @@ client-side to avoid leaking other people's data:
|
||||
|
||||
- **`groupAgenda(rows)`** — turns the flat `get_agenda()` rows into
|
||||
`{ slot, sessions[] }[]` ordered by slot id. Used by `useEvent()`.
|
||||
- **`sessionMaterialUrl(path)`** — builds the public URL for a session material
|
||||
in the `materials` bucket.
|
||||
- **`downloadSessionMaterial(path)`** — downloads a material file through
|
||||
authenticated storage (private bucket; server-side RLS allows it for the
|
||||
session's speakers/admins anytime, everyone else after the session ended).
|
||||
**`materialFilename(path)`** strips the `sessions/<id>/<ts>-` prefix.
|
||||
|
||||
## Admin Email Entry
|
||||
|
||||
|
||||
@@ -213,9 +213,14 @@ the agenda list, its slot count, and Home's Now/Next cards all agree.
|
||||
and no material is uploaded yet, a **non-dismissible** "📎 Upload your session
|
||||
material" notice with a file input. Uploading stores the file in the
|
||||
`materials` bucket and calls `set_session_material` (via
|
||||
`uploadSessionMaterial`). Once uploaded, the notice is gone and a **📎
|
||||
Download material** button appears (visible to **all** attendees), pinned to
|
||||
the **bottom** of the sheet's button stack (below "Pick this session").
|
||||
`uploadSessionMaterial`). Once uploaded, the notice is gone. Attendees
|
||||
**always see that material exists** (📎 on the agenda card, and in the
|
||||
sheet), but downloads **unlock when the session ends**: before `slot end`
|
||||
non-speakers see a "📎 Material uploaded — unlocks at HH:MM" panel
|
||||
(`material-locked`), after it (or as the session's speaker) a **📎
|
||||
Download material** button (`downloadSessionMaterial`, authenticated
|
||||
storage — the private bucket's RLS enforces the same rule server-side;
|
||||
attendance is irrelevant, only the clock).
|
||||
- **Remove material** — a speaker of the session can also **🗑 Remove material**
|
||||
(to re-upload). This deletes the storage object and clears `material_path` via
|
||||
`set_session_material` (null) — `removeSessionMaterial`.
|
||||
|
||||
@@ -610,6 +610,30 @@ in `transform-excel.test.js`; verified against the real Sessionize demo payload
|
||||
(10/11 sessions get a language, service sessions stay null → now forced
|
||||
English by the RPCs).
|
||||
|
||||
## Material downloads unlock at the session end — ✅ complete (2026-10-21)
|
||||
|
||||
Product rule (Sabrina): uploaded session material must not distract attendees
|
||||
mid-session, but must be available to **everyone** (time-based, attendance not
|
||||
required) once the session's schedule ends — and users must always *see* that
|
||||
a speaker uploaded material even while the download is locked.
|
||||
|
||||
- **Enforced at the storage layer**, not the UI: `20261021180000_material_time_lock.sql`
|
||||
makes the `materials` bucket **private** and replaces `materials_read` with
|
||||
`can_read_session_material(bucket, name)`: admins and the session's own
|
||||
speakers anytime; everyone else only after `slot_date + end_time`
|
||||
(Europe/Amsterdam wall time, matching the client's existing `slotStatus ===
|
||||
'done'` rule). A leaked path/URL releases nothing early.
|
||||
- **Always-visible existence**: the agenda card 📎 pill already renders from
|
||||
`material_path` (unchanged, `get_agenda` still returns it); SessionDetail
|
||||
shows a "📎 Material uploaded — unlocks at HH:MM" panel (`material-locked`)
|
||||
while locked, and a download button once unlocked or for the speaker.
|
||||
- **Clients**: attendee app downloads via authenticated
|
||||
`storage.from('materials').download()` (blob + filename); admin app switched
|
||||
to short-lived `createSignedUrl`. No `getPublicUrl` remains in any app.
|
||||
- **Tests**: `supabase/tests/material_time_lock_tests.sql` — 12 assertions
|
||||
(bucket private, outsider locked/unlocked by time, speaker/admin bypass,
|
||||
malformed/foreign-bucket rejection, event-local boundary, anon exclusion).
|
||||
|
||||
## Known work (open as of 2026-10-19)
|
||||
|
||||
- **E2E seed drift — 42 specs currently red.** The pretix reseed removed the
|
||||
|
||||
Reference in new issue
Block a user