Skip to content

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

Hide RLS disabled CTA in table editor header if no lints (#41517)

Joshen Lima88c88fa3641
diff --git a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
index 1d88dcdf0d5..454d3fcf907 100644
--- a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
+++ b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
@@ -35,11 +35,9 @@ import {
Form_Shadcn_,
Input_Shadcn_,
PrePostTab,
- Separator,
Skeleton,
Switch,
WarningIcon,
- cn,
} from 'ui'
import { GenericSkeletonLoader } from 'ui-patterns'
import { Admonition } from 'ui-patterns/admonition'
diff --git a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
index fc77f12c9c4..0c91f6e92a0 100644
--- a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
@@ -161,6 +161,14 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsProp
// This will change when we allow autogenerated API docs for schemas other than `public`
const doesHaveAutoGeneratedAPIDocs = table.schema === 'public'
+ const { hasLint: tableHasLints } = getEntityLintDetails(
+ table.name,
+ 'rls_disabled_in_public',
+ ['ERROR'],
+ lints,
+ table.schema
+ )
+
const { hasLint: viewHasLints, matchingLint: matchingViewLint } = getEntityLintDetails(
table.name,
'security_definer_view',
@@ -301,7 +309,7 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsProp
</Button>
)}
</>
- ) : (
+ ) : tableHasLints ? (
<Popover_Shadcn_ modal={false} open={showWarning} onOpenChange={setShowWarning}>
<PopoverTrigger_Shadcn_ asChild>
<Button type="danger" icon={<Lock strokeWidth={1.5} />}>
@@ -338,7 +346,7 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsProp
</div>
</PopoverContent_Shadcn_>
</Popover_Shadcn_>
- )
+ ) : null
) : null}
{isTable && isIndexAdvisorAvailable && !isIndexAdvisorEnabled && (
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
index f56ec5c6820..70daf4bde1d 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
@@ -15,6 +15,7 @@ import type { ForeignKeyConstraint } from 'data/database/foreign-key-constraints
import { databaseKeys } from 'data/database/keys'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { entityTypeKeys } from 'data/entity-types/keys'
+import { lintKeys } from 'data/lint/keys'
import { privilegeKeys } from 'data/privileges/keys'
import { tableEditorKeys } from 'data/table-editor/keys'
import { isTableLike } from 'data/table-editor/table-editor-types'
@@ -530,6 +531,7 @@ export const SidePanelEditor = ({
queryClient.invalidateQueries({
queryKey: privilegeKeys.tablePrivilegesList(project?.ref),
}),
+ queryClient.invalidateQueries({ queryKey: lintKeys.lint(project?.ref) }),
])
// Show success toast after everything is complete
@@ -583,6 +585,7 @@ export const SidePanelEditor = ({
queryClient.invalidateQueries({
queryKey: privilegeKeys.tablePrivilegesList(project?.ref),
}),
+ queryClient.invalidateQueries({ queryKey: lintKeys.lint(project?.ref) }),
])
toast.success(
diff --git a/apps/studio/data/config/project-postgrest-config-update-mutation.ts b/apps/studio/data/config/project-postgrest-config-update-mutation.ts
index 238a7cc0a30..44aa1f70dfc 100644
--- a/apps/studio/data/config/project-postgrest-config-update-mutation.ts
+++ b/apps/studio/data/config/project-postgrest-config-update-mutation.ts
@@ -3,6 +3,7 @@ import { toast } from 'sonner'
import { components } from 'api-types'
import { handleError, patch } from 'data/fetchers'
+import { lintKeys } from 'data/lint/keys'
import type { ResponseError, UseCustomMutationOptions } from 'types'
import { configKeys } from './keys'
@@ -63,7 +64,10 @@ export const useProjectPostgrestConfigUpdateMutation = ({
mutationFn: (vars) => updateProjectPostgrestConfig(vars),
async onSuccess(data, variables, context) {
const { projectRef } = variables
- queryClient.invalidateQueries({ queryKey: configKeys.postgrest(projectRef) })
+ await Promise.all([
+ queryClient.invalidateQueries({ queryKey: configKeys.postgrest(projectRef) }),
+ queryClient.invalidateQueries({ queryKey: lintKeys.lint(projectRef) }),
+ ])
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
diff --git a/e2e/studio/features/table-editor.spec.ts b/e2e/studio/features/table-editor.spec.ts
index d4e3445ee92..ec66e4b8a8e 100644
--- a/e2e/studio/features/table-editor.spec.ts
+++ b/e2e/studio/features/table-editor.spec.ts
@@ -1,7 +1,7 @@
-import { expect, Locator, Page } from '@playwright/test'
+import { expect, Page } from '@playwright/test'
import fs from 'fs'
import path from 'path'
-import { isCLI } from '../utils/is-cli.js'
+import { env } from '../env.config.js'
import { releaseFileOnceCleanup, withFileOnceSetup } from '../utils/once-per-file.js'
import { resetLocalStorage } from '../utils/reset-local-storage.js'
import { test } from '../utils/test.js'
@@ -13,7 +13,6 @@ import {
waitForGridDataToLoad,
waitForTableToLoad,
} from '../utils/wait-for-response.js'
-import { env } from '../env.config.js'
const tableNamePrefix = 'pw_table'
const columnName = 'pw_column'
@@ -244,14 +243,20 @@ testRunner('table editor', () => {
await page.getByTestId('table-name-input').fill(tableNameRlsDisabled)
await page.getByLabel('Enable Row Level Security (').click()
await page.getByRole('button', { name: 'Confirm' }).click()
+
+ // Wait for table creation
const apiPromise = waitForApiResponse(
page,
'pg-meta',
ref,
'tables?include_columns=false&included_schemas=public'
- ) // wait for table creation
+ )
+ // Wait for lints refresh
+ const lintsPromise = waitForApiResponse(page, 'projects', ref, 'run-lints')
+
await page.getByRole('button', { name: 'Save' }).click()
await apiPromise
+ await lintsPromise
await page.getByRole('button', { name: `View ${tableNameRlsDisabled}` }).click()
await expect(page.getByRole('button', { name: 'RLS disabled' })).toBeVisible()
})