Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(action-center): keep members from changing a Getting started step back to opened (#1255)

Cihan4d8b4ab84c1e
diff --git a/supabase/migrations/00202_getting_started_steps_update_using.sql b/supabase/migrations/00202_getting_started_steps_update_using.sql
new file mode 100644
index 000000000..5eb73cdf6
--- /dev/null
+++ b/supabase/migrations/00202_getting_started_steps_update_using.sql
@@ -0,0 +1,51 @@
+-- ============================================================================
+-- 00202: only admins and managers change a step that isn't just opened
+-- ============================================================================
+-- Follow-up from #1234's review. 00196's update policy on
+-- getting_started_steps checked the new row (`with check`: any member may
+-- write `opened`, only an admin or a manager `skipped` or `done`), but not
+-- the row being changed (`using`). So through PostgREST any member could
+-- turn a skipped or done step back into opened. The app never does: the
+-- page RPC inserts with `on conflict do nothing`, and skipping or saving the
+-- KPIs is an admin's or a manager's.
+--
+-- `using` now also needs the row to be opened, or the user to be an admin or
+-- a manager. The rest of the policy is 00196's.
+
+drop policy if exists "getting_started_steps: member update" on public.getting_started_steps;
+
+create policy "getting_started_steps: member update"
+ on public.getting_started_steps
+ for update
+ using (
+ brand_id in (
+ select b.id
+ from public.brands b
+ join public.profiles p on p.organization_id = b.organization_id
+ where p.id = auth.uid()
+ )
+ and (
+ state = 'opened'
+ or exists (
+ select 1 from public.profiles p
+ where p.id = auth.uid()
+ and p.role = any (array['admin'::public.user_role, 'manager'::public.user_role])
+ )
+ )
+ )
+ with check (
+ brand_id in (
+ select b.id
+ from public.brands b
+ join public.profiles p on p.organization_id = b.organization_id
+ where p.id = auth.uid()
+ )
+ and (
+ state = 'opened'
+ or exists (
+ select 1 from public.profiles p
+ where p.id = auth.uid()
+ and p.role = any (array['admin'::public.user_role, 'manager'::public.user_role])
+ )
+ )
+ );
diff --git a/supabase/schema.sql b/supabase/schema.sql
index 623ff30cd..c67a84fba 100644
--- a/supabase/schema.sql
+++ b/supabase/schema.sql
@@ -27586,3 +27586,58 @@ create unique index if not exists citation_url_daily_key
on public.citation_url_daily (brand_id, day, model_used, platform, region, topic_id, url_id)
nulls not distinct;
+-- ─────────────────────────────────────────────────────────────────────────
+-- migrations/00202_getting_started_steps_update_using.sql
+-- ─────────────────────────────────────────────────────────────────────────
+-- ============================================================================
+-- 00202: only admins and managers change a step that isn't just opened
+-- ============================================================================
+-- Follow-up from #1234's review. 00196's update policy on
+-- getting_started_steps checked the new row (`with check`: any member may
+-- write `opened`, only an admin or a manager `skipped` or `done`), but not
+-- the row being changed (`using`). So through PostgREST any member could
+-- turn a skipped or done step back into opened. The app never does: the
+-- page RPC inserts with `on conflict do nothing`, and skipping or saving the
+-- KPIs is an admin's or a manager's.
+--
+-- `using` now also needs the row to be opened, or the user to be an admin or
+-- a manager. The rest of the policy is 00196's.
+
+drop policy if exists "getting_started_steps: member update" on public.getting_started_steps;
+
+create policy "getting_started_steps: member update"
+ on public.getting_started_steps
+ for update
+ using (
+ brand_id in (
+ select b.id
+ from public.brands b
+ join public.profiles p on p.organization_id = b.organization_id
+ where p.id = auth.uid()
+ )
+ and (
+ state = 'opened'
+ or exists (
+ select 1 from public.profiles p
+ where p.id = auth.uid()
+ and p.role = any (array['admin'::public.user_role, 'manager'::public.user_role])
+ )
+ )
+ )
+ with check (
+ brand_id in (
+ select b.id
+ from public.brands b
+ join public.profiles p on p.organization_id = b.organization_id
+ where p.id = auth.uid()
+ )
+ and (
+ state = 'opened'
+ or exists (
+ select 1 from public.profiles p
+ where p.id = auth.uid()
+ and p.role = any (array['admin'::public.user_role, 'manager'::public.user_role])
+ )
+ )
+ );
+