Added correct RLS and month api routes

This commit is contained in:
Alexis
2024-08-23 16:34:47 +02:00
parent db96e66b7a
commit a7cf648f2f
7 changed files with 277 additions and 22 deletions

View File

@@ -192,42 +192,110 @@ create policy "Allow individual update access for GMs" on public.calendars for u
);
-- Month policies
create policy "Allow individual read access for GMs" on public.calendar_months for select using (
create policy "Allow GMs to see their calendar's months"
on public.calendar_months
for select
using (
exists (
select 1 from calendars
where calendars.id = calendar_months.calendar_id
select 1
from public.calendars c
join public.worlds w on w.id = c.world_id
where
c.id = calendar_months.calendar_id
and w.gm_id = auth.uid()
)
);
create policy "Allow individual insert access for GMs" on public.calendar_months for insert with check (
create policy "Allow GMs to add months on their calendars"
on public.calendar_months
for insert
with check (
exists (
select 1 from calendars
where calendars.id = calendar_months.calendar_id
select 1
from public.calendars c
join public.worlds w on w.id = c.world_id
where
c.id = calendar_months.calendar_id
and w.gm_id = auth.uid()
)
);
create policy "Allow individual update access for GMs" on public.calendar_months for update with check (
create policy "Allow GMs to update their calendar's months"
on public.calendar_months
for update
using (
exists (
select 1 from calendars
where calendars.id = calendar_months.calendar_id
select 1
from public.calendars c
join public.worlds w on w.id = c.world_id
where
c.id = calendar_months.calendar_id
and w.gm_id = auth.uid()
)
);
create policy "Allow GMs to delete their calendar's months"
on public.calendar_months
for delete
using (
exists (
select 1
from public.calendars c
join public.worlds w on w.id = c.world_id
where
c.id = calendar_months.calendar_id
and w.gm_id = auth.uid()
)
);
-- Event policies
create policy "Allow individual read access for GMs" on public.calendar_events for select using (
create policy "Allow GMs to see their events"
on public.calendar_events
for select
using (
exists (
select 1 from calendars
where calendars.id = calendar_events.calendar_id
select 1
from public.calendars c
join public.worlds w on w.id = c.world_id
where
c.id = calendar_events.calendar_id
and w.gm_id = auth.uid()
)
);
create policy "Allow individual insert access for GMs" on public.calendar_events for insert with check (
create policy "Allow GMs to add their events"
on public.calendar_events
for insert
with check (
exists (
select 1 from calendars
where calendars.id = calendar_events.calendar_id
select 1
from public.calendars c
join public.worlds w on w.id = c.world_id
where
c.id = calendar_events.calendar_id
and w.gm_id = auth.uid()
)
);
create policy "Allow individual update access for GMs" on public.calendar_events for update with check (
create policy "Allow GMs to update their events"
on public.calendar_events
for update
using (
exists (
select 1 from calendars
where calendars.id = calendar_events.calendar_id
select 1
from public.calendars c
join public.worlds w on w.id = c.world_id
where
c.id = calendar_events.calendar_id
and w.gm_id = auth.uid()
)
);
create policy "Allow GMs to delete their events"
on public.calendar_events
for delete
using (
exists (
select 1
from public.calendars c
join public.worlds w on w.id = c.world_id
where
c.id = calendar_events.calendar_id
and w.gm_id = auth.uid()
)
);