Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -70,25 +70,41 @@ alter table public.invoices enable row level security;
|
||||
alter table public.subscriptions enable row level security;
|
||||
|
||||
-- Proposals RLS
|
||||
drop policy if exists "Users can view their own proposals" on public.proposals;
|
||||
create policy "Users can view their own proposals" on public.proposals for select using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can insert their own proposals" on public.proposals;
|
||||
create policy "Users can insert their own proposals" on public.proposals for insert with check (auth.uid() = user_id);
|
||||
drop policy if exists "Users can update their own proposals" on public.proposals;
|
||||
create policy "Users can update their own proposals" on public.proposals for update using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can delete their own proposals" on public.proposals;
|
||||
create policy "Users can delete their own proposals" on public.proposals for delete using (auth.uid() = user_id);
|
||||
|
||||
-- Contracts RLS
|
||||
drop policy if exists "Users can view their own contracts" on public.contracts;
|
||||
create policy "Users can view their own contracts" on public.contracts for select using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can insert their own contracts" on public.contracts;
|
||||
create policy "Users can insert their own contracts" on public.contracts for insert with check (auth.uid() = user_id);
|
||||
drop policy if exists "Users can update their own contracts" on public.contracts;
|
||||
create policy "Users can update their own contracts" on public.contracts for update using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can delete their own contracts" on public.contracts;
|
||||
create policy "Users can delete their own contracts" on public.contracts for delete using (auth.uid() = user_id);
|
||||
|
||||
-- Invoices RLS
|
||||
drop policy if exists "Users can view their own invoices" on public.invoices;
|
||||
create policy "Users can view their own invoices" on public.invoices for select using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can insert their own invoices" on public.invoices;
|
||||
create policy "Users can insert their own invoices" on public.invoices for insert with check (auth.uid() = user_id);
|
||||
drop policy if exists "Users can update their own invoices" on public.invoices;
|
||||
create policy "Users can update their own invoices" on public.invoices for update using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can delete their own invoices" on public.invoices;
|
||||
create policy "Users can delete their own invoices" on public.invoices for delete using (auth.uid() = user_id);
|
||||
|
||||
-- Subscriptions RLS
|
||||
drop policy if exists "Users can view their own subscriptions" on public.subscriptions;
|
||||
create policy "Users can view their own subscriptions" on public.subscriptions for select using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can insert their own subscriptions" on public.subscriptions;
|
||||
create policy "Users can insert their own subscriptions" on public.subscriptions for insert with check (auth.uid() = user_id);
|
||||
drop policy if exists "Users can update their own subscriptions" on public.subscriptions;
|
||||
create policy "Users can update their own subscriptions" on public.subscriptions for update using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can delete their own subscriptions" on public.subscriptions;
|
||||
create policy "Users can delete their own subscriptions" on public.subscriptions for delete using (auth.uid() = user_id);
|
||||
|
||||
@@ -24,7 +24,11 @@ create table if not exists public.client_activities (
|
||||
alter table public.client_activities enable row level security;
|
||||
|
||||
-- Client Activities RLS
|
||||
drop policy if exists "Users can view their own client activities" on public.client_activities;
|
||||
create policy "Users can view their own client activities" on public.client_activities for select using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can insert their own client activities" on public.client_activities;
|
||||
create policy "Users can insert their own client activities" on public.client_activities for insert with check (auth.uid() = user_id);
|
||||
drop policy if exists "Users can update their own client activities" on public.client_activities;
|
||||
create policy "Users can update their own client activities" on public.client_activities for update using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can delete their own client activities" on public.client_activities;
|
||||
create policy "Users can delete their own client activities" on public.client_activities for delete using (auth.uid() = user_id);
|
||||
|
||||
@@ -16,9 +16,13 @@ create table if not exists public.document_embeddings (
|
||||
-- Enable RLS
|
||||
alter table public.document_embeddings enable row level security;
|
||||
|
||||
drop policy if exists "Users can view their own embeddings" on public.document_embeddings;
|
||||
create policy "Users can view their own embeddings" on public.document_embeddings for select using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can insert their own embeddings" on public.document_embeddings;
|
||||
create policy "Users can insert their own embeddings" on public.document_embeddings for insert with check (auth.uid() = user_id);
|
||||
drop policy if exists "Users can update their own embeddings" on public.document_embeddings;
|
||||
create policy "Users can update their own embeddings" on public.document_embeddings for update using (auth.uid() = user_id);
|
||||
drop policy if exists "Users can delete their own embeddings" on public.document_embeddings;
|
||||
create policy "Users can delete their own embeddings" on public.document_embeddings for delete using (auth.uid() = user_id);
|
||||
|
||||
-- Create a function to similarity search for embeddings
|
||||
|
||||
@@ -23,6 +23,7 @@ CREATE TABLE IF NOT EXISTS public.project_revisions (
|
||||
);
|
||||
|
||||
-- Trigger to set updated_at
|
||||
DROP TRIGGER IF EXISTS set_project_revisions_updated_at ON public.project_revisions;
|
||||
CREATE TRIGGER set_project_revisions_updated_at
|
||||
BEFORE UPDATE ON public.project_revisions
|
||||
FOR EACH ROW
|
||||
@@ -35,18 +36,21 @@ ALTER TABLE public.project_revisions ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- PROFILES
|
||||
-- Clients can read their own profile
|
||||
DROP POLICY IF EXISTS "Clients can view own profile" ON public.profiles;
|
||||
CREATE POLICY "Clients can view own profile"
|
||||
ON public.profiles FOR SELECT
|
||||
USING (auth.uid() = id);
|
||||
|
||||
-- CLIENTS
|
||||
-- Clients can read their own client record
|
||||
DROP POLICY IF EXISTS "Clients can view own client record" ON public.clients;
|
||||
CREATE POLICY "Clients can view own client record"
|
||||
ON public.clients FOR SELECT
|
||||
USING (client_auth_id = auth.uid());
|
||||
|
||||
-- PROJECTS
|
||||
-- Clients can view projects where client_id matches their client record
|
||||
DROP POLICY IF EXISTS "Clients can view own projects" ON public.projects;
|
||||
CREATE POLICY "Clients can view own projects"
|
||||
ON public.projects FOR SELECT
|
||||
USING (
|
||||
@@ -57,6 +61,7 @@ USING (
|
||||
|
||||
-- TASKS
|
||||
-- Clients can view tasks linked to their projects IF is_public_to_client is true
|
||||
DROP POLICY IF EXISTS "Clients can view public tasks of their projects" ON public.tasks;
|
||||
CREATE POLICY "Clients can view public tasks of their projects"
|
||||
ON public.tasks FOR SELECT
|
||||
USING (
|
||||
@@ -70,6 +75,7 @@ USING (
|
||||
|
||||
-- PROJECT PLANNING SECTIONS (Milestones, Roadmap, etc.)
|
||||
-- Clients can view planning sections of their projects
|
||||
DROP POLICY IF EXISTS "Clients can view planning sections of their projects" ON public.project_planning_sections;
|
||||
CREATE POLICY "Clients can view planning sections of their projects"
|
||||
ON public.project_planning_sections FOR SELECT
|
||||
USING (
|
||||
@@ -82,6 +88,7 @@ USING (
|
||||
|
||||
-- PROJECT REVISIONS
|
||||
-- Freelancers can manage all revisions for their projects
|
||||
DROP POLICY IF EXISTS "Freelancers can manage revisions" ON public.project_revisions;
|
||||
CREATE POLICY "Freelancers can manage revisions"
|
||||
ON public.project_revisions FOR ALL
|
||||
USING (
|
||||
@@ -91,6 +98,7 @@ USING (
|
||||
);
|
||||
|
||||
-- Clients can insert revisions for their projects
|
||||
DROP POLICY IF EXISTS "Clients can insert revisions" ON public.project_revisions;
|
||||
CREATE POLICY "Clients can insert revisions"
|
||||
ON public.project_revisions FOR INSERT
|
||||
WITH CHECK (
|
||||
@@ -101,6 +109,7 @@ WITH CHECK (
|
||||
);
|
||||
|
||||
-- Clients can view their own revisions
|
||||
DROP POLICY IF EXISTS "Clients can view own revisions" ON public.project_revisions;
|
||||
CREATE POLICY "Clients can view own revisions"
|
||||
ON public.project_revisions FOR SELECT
|
||||
USING (
|
||||
|
||||
Reference in New Issue
Block a user