diff --git a/supabase/migrations/20260508170851_6c45a9d4-eaef-454c-8693-7ebd646679a4.sql b/supabase/migrations/20260508170851_6c45a9d4-eaef-454c-8693-7ebd646679a4.sql new file mode 100644 index 0000000..bbf5b70 --- /dev/null +++ b/supabase/migrations/20260508170851_6c45a9d4-eaef-454c-8693-7ebd646679a4.sql @@ -0,0 +1,29 @@ +-- Allow team members (and originating attorney) to view and update their cases +DROP POLICY IF EXISTS cases_select_assigned ON public.cases; +DROP POLICY IF EXISTS cases_update_assigned ON public.cases; + +CREATE POLICY cases_select_assigned ON public.cases +FOR SELECT +USING ( + public.is_admin(auth.uid()) + OR assigned_attorney_id = auth.uid() + OR created_by = auth.uid() + OR originating_attorney_id = auth.uid() + OR EXISTS ( + SELECT 1 FROM public.case_team_members tm + WHERE tm.case_id = cases.id AND tm.user_id = auth.uid() + ) +); + +CREATE POLICY cases_update_assigned ON public.cases +FOR UPDATE +USING ( + public.is_admin(auth.uid()) + OR assigned_attorney_id = auth.uid() + OR created_by = auth.uid() + OR originating_attorney_id = auth.uid() + OR EXISTS ( + SELECT 1 FROM public.case_team_members tm + WHERE tm.case_id = cases.id AND tm.user_id = auth.uid() + ) +); \ No newline at end of file