mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
Fix editing policy via inline sql, placeholder sql is incorrect (#35038)
This commit is contained in:
1 parent
56f0bb58c5
commit
3bae4ccdd0
3 files changed
+10
-12
No files matched your search
@@ -22,7 +22,7 @@ import {
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from 'ui'
|
||||
import { generatePolicyCreateSQL } from './PolicyTableRow.utils'
|
||||
import { generatePolicyUpdateSQL } from './PolicyTableRow.utils'
|
||||
|
||||
interface PolicyRowProps {
|
||||
policy: PostgresPolicy
|
||||
@@ -118,7 +118,7 @@ const PolicyRow = ({
|
||||
<DropdownMenuItem
|
||||
className="space-x-2"
|
||||
onClick={() => {
|
||||
const sql = generatePolicyCreateSQL(policy)
|
||||
const sql = generatePolicyUpdateSQL(policy)
|
||||
aiSnap.newChat({
|
||||
name: `Update policy ${policy.name}`,
|
||||
open: true,
|
||||
|
||||
+6
-8
@@ -1,22 +1,20 @@
|
||||
import { PostgresPolicy } from '@supabase/postgres-meta'
|
||||
|
||||
export const generatePolicyCreateSQL = (policy: PostgresPolicy) => {
|
||||
export const generatePolicyUpdateSQL = (policy: PostgresPolicy) => {
|
||||
let expression = ''
|
||||
if (policy.definition !== null && policy.definition !== undefined) {
|
||||
expression += `USING (${policy.definition})${
|
||||
expression += `using (${policy.definition})${
|
||||
policy.check === null || policy.check === undefined ? ';' : ''
|
||||
}\n`
|
||||
}
|
||||
if (policy.check !== null && policy.check !== undefined) {
|
||||
expression += `WITH CHECK (${policy.check});\n`
|
||||
expression += `with check (${policy.check});\n`
|
||||
}
|
||||
|
||||
return `
|
||||
ALTER POLICY "${policy.name}"
|
||||
ON "${policy.schema}"."${policy.table}"
|
||||
AS ${policy.action}
|
||||
FOR ${policy.command}
|
||||
TO ${policy.roles.join(', ')}
|
||||
alter policy "${policy.name}"
|
||||
on "${policy.schema}"."${policy.table}"
|
||||
to ${policy.roles.join(', ')}
|
||||
${expression}
|
||||
`.trim()
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { useIsInlineEditorEnabled } from 'components/interfaces/App/FeaturePrevi
|
||||
import Policies from 'components/interfaces/Auth/Policies/Policies'
|
||||
import { getGeneralPolicyTemplates } from 'components/interfaces/Auth/Policies/PolicyEditorModal/PolicyEditorModal.constants'
|
||||
import { PolicyEditorPanel } from 'components/interfaces/Auth/Policies/PolicyEditorPanel'
|
||||
import { generatePolicyCreateSQL } from 'components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils'
|
||||
import { generatePolicyUpdateSQL } from 'components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils'
|
||||
import AuthLayout from 'components/layouts/AuthLayout/AuthLayout'
|
||||
import DefaultLayout from 'components/layouts/DefaultLayout'
|
||||
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
|
||||
@@ -174,7 +174,7 @@ const AuthPoliciesPage: NextPageWithLayout = () => {
|
||||
}}
|
||||
onSelectEditPolicy={(policy) => {
|
||||
if (isInlineEditorEnabled) {
|
||||
const sql = generatePolicyCreateSQL(policy)
|
||||
const sql = generatePolicyUpdateSQL(policy)
|
||||
const templates = getGeneralPolicyTemplates(policy.schema, policy.table)
|
||||
setEditorPanel({
|
||||
open: true,
|
||||
|
||||
Reference in new issue
Block a user