forked from fahrPool/fahrPool
feat: add auftrag-fotos storage bucket with RLS policies
This commit is contained in:
parent
e52a499b71
commit
4407c6de0c
|
|
@ -0,0 +1,44 @@
|
|||
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');
|
||||
Loading…
Reference in New Issue