Skip to content

Commit

Permalink
add collaborators for spaes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kluskey committed Sep 29, 2024
1 parent 6208030 commit 725d056
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions mirror-2/supabase/migrations/20240929062844_collaborators.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

-- Create the space_user_collaborators table
create table space_user_collaborators (
id uuid not null primary key,
space_id uuid references spaces(id) on delete cascade not null,
user_id uuid references auth.users(id) on delete cascade not null,
created_at timestamp with time zone not null default now(),
constraint unique_space_user unique(space_id, user_id)
);

-- Enable RLS for space_user_collaborators
alter table space_user_collaborators
enable row level security;

-- Only space owners can add collaborators
create policy "Only space owners can add collaborators"
on space_user_collaborators
for insert
with check (
exists (
select 1 from spaces
where spaces.id = space_id
and spaces.creator_user_id = auth.uid()
)
);

-- Policy for selecting space_user_collaborators
create policy "Users can view where they are a collaborator"
on space_user_collaborators
for select
using (user_id = auth.uid());


-- Policy for collaborators to view spaces
create policy "Collaborators can view spaces"
on spaces
for select
using (
exists (
select 1 from space_user_collaborators
where space_user_collaborators.space_id = spaces.id
and space_user_collaborators.user_id = auth.uid()
)
);

0 comments on commit 725d056

Please sign in to comment.