1
0
Fork 0
fahrPool/supabase/migrations/20260705150911_auftrag_foto...

45 lines
1.7 KiB
SQL

insert into storage.buckets (id, name, public)
values ('auftrag-fotos', 'auftrag-fotos', false)
on conflict (id) do nothing;
create policy "Fahrer liest Fotos des eigenen zugewiesenen Auftrags"
on storage.objects for select
using (
bucket_id = 'auftrag-fotos'
and exists (
select 1 from public.auftraege
where id = (storage.foldername(name))[1]::uuid
and zugewiesen_an = auth.uid()
)
);
create policy "Disponent Admin Readonly lesen alle Auftragsfotos im Storage"
on storage.objects for select
using (bucket_id = 'auftrag-fotos' and public.user_role() in ('admin', 'disponent', 'readonly'));
-- public.user_role() = 'fahrer' ist zwingend (gleiches Muster wie die
-- analoge Luecke bei der auftraege-UPDATE-Policy aus Task 2 und der
-- auftrag_fotos-INSERT-Policy aus Task 3): ohne dieses Praedikat wuerde
-- die Policy fuer jede eingeloggte Rolle gelten, sobald deren auth.uid()
-- zufaellig mit zugewiesen_an eines Auftrags uebereinstimmt.
create policy "Fahrer laedt Fotos fuer eigenen zugewiesenen offenen Auftrag hoch"
on storage.objects for insert
with check (
bucket_id = 'auftrag-fotos'
and public.user_role() = 'fahrer'
and exists (
select 1 from public.auftraege
where id = (storage.foldername(name))[1]::uuid
and zugewiesen_an = auth.uid()
and status = 'zugewiesen'
)
);
create policy "Admin aktualisiert Auftragsfotos im Storage"
on storage.objects for update
using (bucket_id = 'auftrag-fotos' and public.user_role() = 'admin');
create policy "Admin loescht Auftragsfotos im Storage"
on storage.objects for delete
using (bucket_id = 'auftrag-fotos' and public.user_role() = 'admin');