From d4e4637e7ce61bc5e4cc29ab6eea455fdb0317a2 Mon Sep 17 00:00:00 2001 From: Jose Lago Date: Wed, 21 Oct 2026 18:57:15 +0200 Subject: [PATCH] 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. --- apps/admin/src/lib/api.ts | 9 +- apps/admin/src/views/Schedule.tsx | 16 +- apps/convivo/src/components/SessionDetail.tsx | 36 ++++- apps/convivo/src/lib/api.ts | 26 +++- apps/convivo/src/screens/SpeakerPortal.tsx | 4 +- apps/convivo/src/styles.css | 2 +- docs/backend/rls.md | 14 +- docs/backend/schema.md | 11 +- docs/frontend/api-client.md | 6 +- docs/frontend/screens.md | 11 +- docs/next-steps.md | 24 +++ .../20261021180000_material_time_lock.sql | 67 +++++++++ supabase/tests/material_time_lock_tests.sql | 138 ++++++++++++++++++ 13 files changed, 334 insertions(+), 30 deletions(-) create mode 100644 supabase/migrations/20261021180000_material_time_lock.sql create mode 100644 supabase/tests/material_time_lock_tests.sql diff --git a/apps/admin/src/lib/api.ts b/apps/admin/src/lib/api.ts index 0b2988b..9752bc1 100644 --- a/apps/admin/src/lib/api.ts +++ b/apps/admin/src/lib/api.ts @@ -538,9 +538,12 @@ export async function removeSessionMaterial(sessionId: string): Promise { if (error) throw new ApiError(error.message); } -export function sessionMaterialUrl(path: string): string { - const { data } = supabase.storage.from('materials').getPublicUrl(path); - return data.publicUrl; +/** Open a session material in a new tab via a short-lived signed URL. The + * materials bucket is private; storage RLS always allows admins. */ +export async function openSessionMaterial(path: string): Promise { + const { data, error } = await supabase.storage.from('materials').createSignedUrl(path, 600); + if (error) throw new ApiError(error.message); + window.open(data.signedUrl, '_blank'); } async function feedbackSidecarFetch(path: string, init?: RequestInit): Promise { diff --git a/apps/admin/src/views/Schedule.tsx b/apps/admin/src/views/Schedule.tsx index ffc680a..142fe81 100644 --- a/apps/admin/src/views/Schedule.tsx +++ b/apps/admin/src/views/Schedule.tsx @@ -8,7 +8,7 @@ import { getSessions, getSlots, removeSessionMaterial, - sessionMaterialUrl, + openSessionMaterial, setSessionSpeakers, uploadSessionMaterial, } from '../lib/api'; @@ -573,9 +573,19 @@ function SessionModal({ {session.material_path ? (
- + + ) : ( +
+
๐Ÿ“Ž Material uploaded
+
+ The speaker has uploaded material for this session. + The download unlocks when the session ends at {fmtTime(slot.end_time)}. +
+
+ ) )} {/* Speakers can remove their own material to re-upload. */} {isSpeaker && session.material_path && ( diff --git a/apps/convivo/src/lib/api.ts b/apps/convivo/src/lib/api.ts index 68f5b9f..7519aab 100644 --- a/apps/convivo/src/lib/api.ts +++ b/apps/convivo/src/lib/api.ts @@ -236,10 +236,28 @@ export async function getMyPointsLog(email: string): Promise { return data as PointsLogRow[]; } -/** Public URL for a session material stored in the `materials` bucket. */ -export function sessionMaterialUrl(path: string): string { - const { data } = supabase.storage.from('materials').getPublicUrl(path); - return data.publicUrl; +/** Filename of a material object path (`sessions//-`). */ +export function materialFilename(path: string): string { + const base = path.slice(path.lastIndexOf('/') + 1); + return base.replace(/^\d+-/, ''); +} + +/** Download a session material through authenticated storage. The materials + * bucket is private and server-side RLS only releases the file to the + * session's own speakers/admins at any time, and to everyone else once the + * session's scheduled end has passed โ€” so this legitimately fails before the + * end for plain attendees even if the UI clock disagrees. */ +export async function downloadSessionMaterial(path: string): Promise { + const { data, error } = await supabase.storage.from('materials').download(path); + if (error) throw new ApiError('Download failed โ€” material unlocks when the session ends.'); + const url = URL.createObjectURL(data); + const a = document.createElement('a'); + a.href = url; + a.download = materialFilename(path); + document.body.appendChild(a); + a.click(); + a.remove(); + URL.revokeObjectURL(url); } /** Session ids the signed-in contact is a speaker of (for material upload). */ diff --git a/apps/convivo/src/screens/SpeakerPortal.tsx b/apps/convivo/src/screens/SpeakerPortal.tsx index 429f2ed..393dbc3 100644 --- a/apps/convivo/src/screens/SpeakerPortal.tsx +++ b/apps/convivo/src/screens/SpeakerPortal.tsx @@ -3,7 +3,7 @@ import type { Session } from '@supabase/supabase-js'; import { LoaderCircle, Paperclip } from 'lucide-react'; import { supabase } from '../lib/supabase'; import { getSpeakerPortalSessions, speakerPortalSession, type SpeakerSession } from '../lib/speakerPortal'; -import { removeSessionMaterial, sessionMaterialUrl, uploadSessionMaterial } from '../lib/api'; +import { downloadSessionMaterial, removeSessionMaterial, uploadSessionMaterial } from '../lib/api'; const MAX_FILE_SIZE = 50 * 1024 * 1024; const FILE_TYPES = '.pdf,.ppt,.pptx,.odp,.zip,.txt'; @@ -110,7 +110,7 @@ export function SpeakerPortal() {

{talk.event_name} ยท {talk.is_active ? 'Active event' : 'Inactive event'}

{talk.title}

{talk.slot_date} ยท {talk.start_time.slice(0, 5)} - {talk.end_time.slice(0, 5)}{talk.room && ` ยท ${talk.room}`}

- {talk.material_path ? Download material :

No material uploaded

} + {talk.material_path ? :

No material uploaded

}