The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
remove param routing on delete policies (#40649)
Francesco Sansalvadore69c54c2eaec6
diff --git a/apps/studio/components/interfaces/Auth/Policies/Policies.tsx b/apps/studio/components/interfaces/Auth/Policies/Policies.tsxindex d06c4508d7d..8be311b6446 100644--- a/apps/studio/components/interfaces/Auth/Policies/Policies.tsx+++ b/apps/studio/components/interfaces/Auth/Policies/Policies.tsx@@ -1,4 +1,5 @@import type { PostgresPolicy } from '@supabase/postgres-meta'+import { isEmpty } from 'lodash'import Link from 'next/link'import { useCallback, useState } from 'react'import { toast } from 'sonner'@@ -10,6 +11,7 @@ import {} from 'components/interfaces/Auth/Policies/PolicyTableRow'import { ProtectedSchemaWarning } from 'components/interfaces/Database/ProtectedSchemaWarning'import { NoSearchResults } from 'components/ui/NoSearchResults'+import { useDatabasePolicyDeleteMutation } from 'data/database-policies/database-policy-delete-mutation'import { useTableUpdateMutation } from 'data/tables/table-update-mutation'import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { Button, Card, CardContent } from 'ui'@@ -47,6 +49,8 @@ export const Policies = ({name: stringrls_enabled: boolean}>()+ const [selectedPolicyToDelete, setSelectedPolicyToDelete] = useState<any>({})+const { mutate: updateTable } = useTableUpdateMutation({onError: (error) => {toast.error(`Failed to toggle RLS: ${error.message}`)@@ -56,7 +60,17 @@ export const Policies = ({},})+ const { mutate: deleteDatabasePolicy } = useDatabasePolicyDeleteMutation({+ onSuccess: () => {+ toast.success('Successfully deleted policy!')+ },+ onSettled: () => {+ closeConfirmModal()+ },+ })+const closeConfirmModal = useCallback(() => {+ setSelectedPolicyToDelete({})setSelectedTableToToggleRLS(undefined)}, [])@@ -74,6 +88,10 @@ export const Policies = ({[onSelectEditPolicyAI])+ const onSelectDeletePolicy = useCallback((policy: PostgresPolicy) => {+ setSelectedPolicyToDelete(policy)+ }, [])+// Methods that involve some APIconst onToggleRLS = async () => {if (!selectedTableToToggleRLS) return console.error('Table is required')@@ -93,6 +111,15 @@ export const Policies = ({})}+ const onDeletePolicy = async () => {+ if (!project) return console.error('Project is required')+ deleteDatabasePolicy({+ projectRef: project.ref,+ connectionString: project.connectionString,+ originalPolicy: selectedPolicyToDelete,+ })+ }+const handleCreatePolicy = useCallback((tableData: PolicyTableRowProps['table']) => {onSelectCreatePolicy(tableData.name)@@ -134,6 +161,7 @@ export const Policies = ({onSelectToggleRLS={onSelectToggleRLS}onSelectCreatePolicy={handleCreatePolicy}onSelectEditPolicy={onSelectEditPolicy}+ onSelectDeletePolicy={onSelectDeletePolicy}/></section>)@@ -147,6 +175,17 @@ export const Policies = ({) : null}</div>+ <ConfirmModal+ danger+ visible={!isEmpty(selectedPolicyToDelete)}+ title="Confirm to delete policy"+ description={`This is permanent! Are you sure you want to delete the policy "${selectedPolicyToDelete.name}"`}+ buttonLabel="Delete"+ buttonLoadingLabel="Deleting"+ onSelectCancel={closeConfirmModal}+ onSelectConfirm={onDeletePolicy}+ />+<ConfirmModaldanger={selectedTableToToggleRLS?.rls_enabled}visible={selectedTableToToggleRLS !== undefined}diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsxindex 1573edb0ad4..979b3061fb9 100644--- a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx@@ -37,6 +37,7 @@ export interface PolicyTableRowProps {onSelectToggleRLS: (table: PolicyTable) => voidonSelectCreatePolicy: (table: PolicyTable) => voidonSelectEditPolicy: (policy: PostgresPolicy) => void+ onSelectDeletePolicy: (policy: PostgresPolicy) => void}const PolicyTableRowComponent = ({@@ -45,6 +46,7 @@ const PolicyTableRowComponent = ({onSelectToggleRLS = noop,onSelectCreatePolicy = noop,onSelectEditPolicy = noop,+ onSelectDeletePolicy = noop,}: PolicyTableRowProps) => {const { ref } = useParams()const { data: project } = useSelectedProjectQuery()@@ -56,17 +58,6 @@ const PolicyTableRowComponent = ({[getPoliciesForTable, table.schema, table.name])- const deletingPolicyIdRef = useRef<string | null>(null)-- const { setValue: setPolicyToDelete, value: policyToDelete } = useQueryStateWithSelect({- urlKey: 'delete',- select: (id: string) =>- id ? policies?.find((policy) => policy.id.toString() === id) : undefined,- enabled: !!policies,- onError: (_error, selectedId) =>- handleErrorOnDelete(deletingPolicyIdRef, selectedId, `Policy not found`),- })-// [Joshen] Changes here are so that warnings are more accurate and granular instead of purely relying if RLS is disabled or enabled// The following scenarios are technically okay if the table has RLS disabled, in which it won't be publicly readable / writable// - If the schema is not exposed through the API via Postgrest@@ -97,141 +88,96 @@ const PolicyTableRowComponent = ({const showPolicies = !isPoliciesLoading && !isPoliciesError- const { mutate: deleteDatabasePolicy } = useDatabasePolicyDeleteMutation({- onSuccess: () => {- toast.success('Successfully deleted policy!')- },- onSettled: () => {- closeConfirmModal()- },- onError: () => {- deletingPolicyIdRef.current = null- },- })-- const closeConfirmModal = useCallback(() => {- setPolicyToDelete(null)- }, [])-- const onSelectDeletePolicy = useCallback((policy: PostgresPolicy) => {- setPolicyToDelete(policy.id.toString())- }, [])-- const onDeletePolicy = async () => {- if (!project) return console.error('Project is required')- if (!policyToDelete) return console.error('Policy is required')-- deletingPolicyIdRef.current = policyToDelete.id.toString()- deleteDatabasePolicy({- projectRef: project.ref,- connectionString: project.connectionString,- originalPolicy: policyToDelete,- })- }-return (- <>- <Card className={cn(isPubliclyReadableWritable && 'border-warning-500')}>- <CardHeader- className={cn(- 'py-3 px-4',- (isPubliclyReadableWritable || rlsEnabledNoPolicies || !isTableExposedThroughAPI) &&- 'border-b-0'- )}+ <Card className={cn(isPubliclyReadableWritable && 'border-warning-500')}>+ <CardHeader+ className={cn(+ 'py-3 px-4',+ (isPubliclyReadableWritable || rlsEnabledNoPolicies || !isTableExposedThroughAPI) &&+ 'border-b-0'+ )}+ >+ <PolicyTableRowHeader+ table={table}+ isLocked={isLocked}+ onSelectToggleRLS={onSelectToggleRLS}+ onSelectCreatePolicy={onSelectCreatePolicy}+ />+ </CardHeader>++ {!isTableExposedThroughAPI && (+ <Admonition+ showIcon={false}+ type="warning"+ className="mb-0 border-0 border-y rounded-none [&>div]:text-foreground-light h-[50px] py-0 flex items-center"+ >+ No data will be selectable via Supabase APIs as this schema is not exposed. You may+ configure this in your project's{' '}+ <InlineLink href={`/project/${ref}/settings/api`}>API settings</InlineLink>.+ </Admonition>+ )}++ {(isPubliclyReadableWritable || rlsEnabledNoPolicies) && isTableExposedThroughAPI && (+ <Alert_Shadcn_+ className="border-0 rounded-none mb-0 border-y h-[50px] py-0 flex items-center"+ variant={isPubliclyReadableWritable ? 'warning' : 'default'}>- <PolicyTableRowHeader- table={table}- isLocked={isLocked}- onSelectToggleRLS={onSelectToggleRLS}- onSelectCreatePolicy={onSelectCreatePolicy}+ <AlertDescription_Shadcn_>+ {isPubliclyReadableWritable+ ? "Anyone with your project's anonymous key can read, modify, or delete your data."+ : 'No data will be selectable via Supabase APIs because RLS is enabled but no policies have been created yet.'}+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ )}++ {isPoliciesLoading && (+ <CardContent>+ <ShimmeringLoader />+ </CardContent>+ )}++ {isPoliciesError && (+ <CardContent>+ <AlertError+ className="border-0 rounded-none"+ error={policiesError}+ subject="Failed to retrieve policies"/>- </CardHeader>-- {!isTableExposedThroughAPI && (- <Admonition- showIcon={false}- type="warning"- className="mb-0 border-0 border-y rounded-none [&>div]:text-foreground-light h-[50px] py-0 flex items-center"- >- No data will be selectable via Supabase APIs as this schema is not exposed. You may- configure this in your project's{' '}- <InlineLink href={`/project/${ref}/settings/api`}>API settings</InlineLink>.- </Admonition>- )}-- {(isPubliclyReadableWritable || rlsEnabledNoPolicies) && isTableExposedThroughAPI && (- <Alert_Shadcn_- className="border-0 rounded-none mb-0 border-y h-[50px] py-0 flex items-center"- variant={isPubliclyReadableWritable ? 'warning' : 'default'}- >- <AlertDescription_Shadcn_>- {isPubliclyReadableWritable- ? "Anyone with your project's anonymous key can read, modify, or delete your data."- : 'No data will be selectable via Supabase APIs because RLS is enabled but no policies have been created yet.'}- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- )}-- {isPoliciesLoading && (- <CardContent>- <ShimmeringLoader />- </CardContent>- )}-- {isPoliciesError && (- <CardContent>- <AlertError- className="border-0 rounded-none"- error={policiesError}- subject="Failed to retrieve policies"- />- </CardContent>- )}-- {showPolicies && (- <CardContent className="p-0">- {policies.length === 0 ? (- <p className="text-foreground-lighter text-sm p-4">No policies created yet</p>- ) : (- <Table className="table-fixed">- <TableHeader>- <TableRow>- <TableHead className="w-[40%]">Name</TableHead>- <TableHead className="w-[20%]">Command</TableHead>- <TableHead className="w-[30%]">Applied to</TableHead>- <TableHead className="text-right">- <span className="sr-only">Actions</span>- </TableHead>- </TableRow>- </TableHeader>- <TableBody>- {policies.map((policy) => (- <PolicyRow- key={policy.id}- policy={policy}- isLocked={isTableLocked}- onSelectEditPolicy={onSelectEditPolicy}- onSelectDeletePolicy={onSelectDeletePolicy}- />- ))}- </TableBody>- </Table>- )}- </CardContent>- )}- </Card>-- <ConfirmModal- danger- visible={!!policyToDelete}- title="Confirm to delete policy"- description={`This is permanent! Are you sure you want to delete the policy "${policyToDelete?.name}"`}- buttonLabel="Delete"- buttonLoadingLabel="Deleting"- onSelectCancel={closeConfirmModal}- onSelectConfirm={onDeletePolicy}- />- </>+ </CardContent>+ )}++ {showPolicies && (+ <CardContent className="p-0">+ {policies.length === 0 ? (+ <p className="text-foreground-lighter text-sm p-4">No policies created yet</p>+ ) : (+ <Table className="table-fixed">+ <TableHeader>+ <TableRow>+ <TableHead className="w-[40%]">Name</TableHead>+ <TableHead className="w-[20%]">Command</TableHead>+ <TableHead className="w-[30%]">Applied to</TableHead>+ <TableHead className="text-right">+ <span className="sr-only">Actions</span>+ </TableHead>+ </TableRow>+ </TableHeader>+ <TableBody>+ {policies.map((policy) => (+ <PolicyRow+ key={policy.id}+ policy={policy}+ isLocked={isTableLocked}+ onSelectEditPolicy={onSelectEditPolicy}+ onSelectDeletePolicy={onSelectDeletePolicy}+ />+ ))}+ </TableBody>+ </Table>+ )}+ </CardContent>+ )}+ </Card>)}