Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix policies page locked schema notice (#21217)

Joshen Limec77b7f305c3
diff --git a/apps/studio/components/interfaces/Auth/Policies/Policies.tsx b/apps/studio/components/interfaces/Auth/Policies/Policies.tsx
index a7c719afb56..441ad21766d 100644
--- a/apps/studio/components/interfaces/Auth/Policies/Policies.tsx
+++ b/apps/studio/components/interfaces/Auth/Policies/Policies.tsx
@@ -18,6 +18,8 @@ import { useDatabasePolicyCreateMutation } from 'data/database-policies/database
import { useDatabasePolicyDeleteMutation } from 'data/database-policies/database-policy-delete-mutation'
import { useDatabasePolicyUpdateMutation } from 'data/database-policies/database-policy-update-mutation'
import { useTableUpdateMutation } from 'data/tables/table-update-mutation'
+import ProtectedSchemaWarning from 'components/interfaces/Database/ProtectedSchemaWarning'
+import { useTableEditorStateSnapshot } from 'state/table-editor'
interface PoliciesProps {
tables: PostgresTable[]
@@ -35,6 +37,7 @@ const Policies = ({
const router = useRouter()
const { ref } = useParams()
const { project } = useProjectContext()
+ const snap = useTableEditorStateSnapshot()
const isAiAssistantEnabled = useIsRLSAIAssistantEnabled()
@@ -169,55 +172,58 @@ const Policies = ({
return (
<>
- {tables.length > 0 ? (
- tables.map((table: any) => (
- <section key={table.id}>
- <PolicyTableRow
- table={table}
- isLocked={isLocked}
- onSelectToggleRLS={onSelectToggleRLS}
- onSelectCreatePolicy={onSelectCreatePolicy}
- onSelectEditPolicy={onSelectEditPolicy}
- onSelectDeletePolicy={onSelectDeletePolicy}
- />
- </section>
- ))
- ) : hasTables ? (
- <NoSearchResults />
- ) : (
- <div className="flex-grow">
- <ProductEmptyState
- size="large"
- title="Row-Level Security (RLS) Policies"
- ctaButtonLabel="Create a table"
- infoButtonLabel="What is RLS?"
- infoButtonUrl="https://supabase.com/docs/guides/auth/row-level-security"
- onClickCta={() => router.push(`/project/${ref}/editor`)}
- >
- <div className="space-y-4">
- <InformationBox
- title="What are policies?"
- icon={<IconHelpCircle strokeWidth={2} />}
- description={
- <div className="space-y-2">
- <p className="text-sm">
- Policies restrict, on a per-user basis, which rows can be returned by normal
- queries, or inserted, updated, or deleted by data modification commands.
- </p>
- <p className="text-sm">
- This is also known as Row-Level Security (RLS). Each policy is attached to a
- table, and the policy is executed each time its accessed.
- </p>
- </div>
- }
+ <div className="flex flex-col gap-y-4 pb-4">
+ {isLocked && <ProtectedSchemaWarning schema={snap.selectedSchemaName} entity="policies" />}
+ {tables.length > 0 ? (
+ tables.map((table: any) => (
+ <section key={table.id}>
+ <PolicyTableRow
+ table={table}
+ isLocked={isLocked}
+ onSelectToggleRLS={onSelectToggleRLS}
+ onSelectCreatePolicy={onSelectCreatePolicy}
+ onSelectEditPolicy={onSelectEditPolicy}
+ onSelectDeletePolicy={onSelectDeletePolicy}
/>
- <p className="text-sm text-foreground-light">
- Create a table in this schema first before creating a policy.
- </p>
- </div>
- </ProductEmptyState>
- </div>
- )}
+ </section>
+ ))
+ ) : hasTables ? (
+ <NoSearchResults />
+ ) : (
+ <div className="flex-grow">
+ <ProductEmptyState
+ size="large"
+ title="Row-Level Security (RLS) Policies"
+ ctaButtonLabel="Create a table"
+ infoButtonLabel="What is RLS?"
+ infoButtonUrl="https://supabase.com/docs/guides/auth/row-level-security"
+ onClickCta={() => router.push(`/project/${ref}/editor`)}
+ >
+ <div className="space-y-4">
+ <InformationBox
+ title="What are policies?"
+ icon={<IconHelpCircle strokeWidth={2} />}
+ description={
+ <div className="space-y-2">
+ <p className="text-sm">
+ Policies restrict, on a per-user basis, which rows can be returned by normal
+ queries, or inserted, updated, or deleted by data modification commands.
+ </p>
+ <p className="text-sm">
+ This is also known as Row-Level Security (RLS). Each policy is attached to a
+ table, and the policy is executed each time its accessed.
+ </p>
+ </div>
+ }
+ />
+ <p className="text-sm text-foreground-light">
+ Create a table in this schema first before creating a policy.
+ </p>
+ </div>
+ </ProductEmptyState>
+ </div>
+ )}
+ </div>
<PolicyEditorModal
showAssistantPreview
diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRowHeader.tsx b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRowHeader.tsx
index cdde01cf511..be070f56aa8 100644
--- a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRowHeader.tsx
+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRowHeader.tsx
@@ -30,21 +30,22 @@ const PolicyTableRowHeader = ({
return (
<div id={table.id.toString()} className="flex w-full items-center justify-between">
- <div className="flex space-x-4 text-left">
+ <div className="flex gap-x-4 text-left">
<Link href={`/project/${ref}/editor/${table.id}`}>
<h4 className="m-0">{table.name}</h4>
</Link>
- {isLocked ? (
- <Badge color="scale">
- <span className="flex gap-2 items-center text-xs uppercase text-foreground-lighter">
- <IconLock width={12} /> Locked
- </span>
- </Badge>
- ) : (
+ <div className="flex items-center gap-x-2">
+ {isLocked && (
+ <Badge color="scale">
+ <span className="flex gap-2 items-center text-xs uppercase text-foreground-lighter">
+ <IconLock width={12} /> Locked
+ </span>
+ </Badge>
+ )}
<Badge color={table.rls_enabled ? 'green' : 'yellow'}>
{table.rls_enabled ? 'RLS enabled' : 'RLS disabled'}
</Badge>
- )}
+ </div>
</div>
{!isLocked && (
<div className="flex-1">
diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx
index cd154e38c69..c32cd761129 100644
--- a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx
+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx
@@ -36,6 +36,7 @@ const PolicyTableRow = ({
return (
<Panel
+ className="!m-0"
title={
<PolicyTableRowHeader
table={table}