Repository navigation
Shift old policies UI into storage since its only being used there - #47497
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughPolicy template factories were centralized into shared constants, Storage policy components and helpers were rehomed under local module paths and named exports, and table creation no longer passes or records generated-policy data. ChangesShared Policy Templates and Database Policies UI
Storage Policies module localization and utils
Remove generated-policy handling from table creation
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.utils.tsx (1)
542-546: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winUpdate the createTable test expectations with the new contract.
The provided downstream test context still expects
has_generated_policies: falseintable_createdand a{ failedPolicies: [], table }return, but Line 542 removes that telemetry field and Line 682 returns only{ table }. Update the test to match this PR’s intended API shape.Suggested test expectation update
expect(mockTrack).toHaveBeenCalledWith('table_created', { - has_generated_policies: false, method: 'table_editor', schema_name: 'public', table_name: 'test_table', }) expect(result).toStrictEqual({ - failedPolicies: [], table: mockTableResult, })Also applies to: 681-682
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.utils.tsx` around lines 542 - 546, The createTable contract changed in SidePanelEditor.utils, so downstream tests must stop expecting has_generated_policies on the table_created telemetry and the { failedPolicies: [], table } return shape. Update the test expectations to align with the current SidePanelEditor utilities behavior by asserting the table_created event only includes method, schema_name, and table_name, and that the createTable path returns just { table }.
🧹 Nitpick comments (5)
apps/studio/components/interfaces/Database/Policies/Policies.constants.ts (3)
325-341: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winQueue policy template has an empty
statement, so its SQL preview will be blank.
policy-queues-1setsstatement: ``.trim(), i.e. an empty string.TemplatePreviewrendersstatementdirectly into the read-only code editor as "Policy SQL template", so selecting this template shows no SQL at all, unlike every other template in this file. If that's intentional (user is meant to write their own SQL from scratch), it's worth a one-line comment explaining why; otherwise this looks like a gap that should show a representativecreate policy ...snippet like the other entries.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Database/Policies/Policies.constants.ts` around lines 325 - 341, The queue policy template `policy-queues-1` has an empty `statement`, so `TemplatePreview` will render a blank SQL preview. Update `getQueuePolicyTemplates` in `Policies.constants.ts` to provide a representative policy SQL snippet for `statement` like the other policy templates, or add an explicit comment if the blank preview is intentional. Make sure the fix is applied on the `Allow access to queue` template object so the preview shows useful SQL.
191-323: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider dropping the
as PolicyTemplate[]cast.The array literal is cast to
PolicyTemplate[]at line 321 instead of letting TypeScript infer/verify it against the interface directly (asgetGeneralPolicyTemplatesandgetQueuePolicyTemplatesdo). The cast suppresses structural checking, so a future missing/mistyped field here (e.g.command) would silently pass instead of producing a compile error.♻️ Proposed fix
-export const getRealtimePolicyTemplates = (): PolicyTemplate[] => { - const results = [ +export const getRealtimePolicyTemplates = (): PolicyTemplate[] => { + const results: PolicyTemplate[] = [ { id: 'policy-broadcast-1', ... - ] as PolicyTemplate[] + ] return results }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Database/Policies/Policies.constants.ts` around lines 191 - 323, The getRealtimePolicyTemplates array is being force-cast to PolicyTemplate[], which bypasses TypeScript’s structural checks. Remove the cast and let the array be validated directly like the other template helpers, so each object in getRealtimePolicyTemplates is checked against PolicyTemplate and any missing or mistyped fields are caught at compile time.
275-321: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueStray trailing semicolons produce double
;in generated SQL previews.For
policy-presences-2andpolicy-presences-4, the statement templates end with);\n ;.trim(), e.g.with check ( realtime.messages.extension = 'presence' );\n ;. Since.trim()only strips leading/trailing whitespace of the whole string (not the interior newline), the resulting statement text still contains a stray semicolon on its own line when rendered in the SQL preview (TemplatePreview`). Cosmetic, but worth cleaning up in this canonical module now that duplicates are gone.🧹 Proposed fix
statement: ` create policy "Allow broadcasting presences on all channels for authenticated users only" ON realtime.messages for insert TO authenticated -with check ( realtime.messages.extension = 'presence' ); - ;`.trim(), +with check ( realtime.messages.extension = 'presence' );`.trim(),Apply the analogous fix to
policy-presences-4.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Database/Policies/Policies.constants.ts` around lines 275 - 321, The SQL preview strings for the presence policies still include an extra standalone semicolon because the statement templates end with `);\n ;`. Update the `policy-presences-4` entry in `Policies.constants` so its `statement` text matches the cleaned pattern used elsewhere and does not render a double semicolon in `TemplatePreview`; keep the `statement`, `definition`, and `check` fields aligned with the corrected SQL shape.apps/studio/components/interfaces/Database/Policies/PolicyTableRow/index.tsx (1)
95-95: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove debug
console.log.Fires on every render of every policy table row; should not ship.
🧹 Proposed fix
- console.log({ status, exposedSchemas }) - return (🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Database/Policies/PolicyTableRow/index.tsx` at line 95, Remove the debug console output from the policy row render path: the `console.log({ status, exposedSchemas })` inside `PolicyTableRow` should be deleted so it doesn’t fire on every render of each row. Locate the log in `PolicyTableRow` and remove it without changing the component’s render logic or props handling.apps/studio/components/interfaces/Storage/StoragePolicies/StoragePolicies.utils.ts (1)
17-158: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd unit coverage for the extracted policy helpers.
This module now owns the create/update diffing, whitespace normalization, default-role handling, and SQL preview generation, but there is no companion test in this change set. A small table-driven
StoragePolicies.utils.test.tsaround whitespace-only edits, empty roles, and rename previews would make the refactor much safer. As per coding guidelines, pure.utils.tslogic should be unit tested with vitest.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Storage/StoragePolicies/StoragePolicies.utils.ts` around lines 17 - 158, Add a vitest unit test file for the policy helper functions in StoragePolicies.utils to cover the newly extracted create/update logic. Focus on createSQLPolicy, createSQLStatementForCreatePolicy, createSQLStatementForUpdatePolicy, createPayloadForCreatePolicy, and createPayloadForUpdatePolicy with table-driven cases for whitespace-only normalization, no-op diffs, empty roles defaulting to public, and rename/update SQL previews. Use the existing function names to locate the helpers and assert the returned statement/payload shapes for create and update paths.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@apps/studio/components/interfaces/Storage/StoragePolicies/StoragePolicies.utils.ts`:
- Around line 57-58: The update preview builder in StoragePolicies.utils.ts is
using the edited policy name for the ALTER POLICY target, which makes rename
previews self-referential and breaks rename-plus-edit cases. Update the logic in
createSQLStatementForUpdatePolicy (and the related preview path around
createUpdatePolicySQLStatement) to keep the original policy name for the ALTER
POLICY clause, while using the renamed value only in the RENAME TO portion.
Ensure the code that assembles the SQL distinguishes original vs edited name
before generating the final statement.
---
Outside diff comments:
In
`@apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.utils.tsx`:
- Around line 542-546: The createTable contract changed in
SidePanelEditor.utils, so downstream tests must stop expecting
has_generated_policies on the table_created telemetry and the { failedPolicies:
[], table } return shape. Update the test expectations to align with the current
SidePanelEditor utilities behavior by asserting the table_created event only
includes method, schema_name, and table_name, and that the createTable path
returns just { table }.
---
Nitpick comments:
In `@apps/studio/components/interfaces/Database/Policies/Policies.constants.ts`:
- Around line 325-341: The queue policy template `policy-queues-1` has an empty
`statement`, so `TemplatePreview` will render a blank SQL preview. Update
`getQueuePolicyTemplates` in `Policies.constants.ts` to provide a representative
policy SQL snippet for `statement` like the other policy templates, or add an
explicit comment if the blank preview is intentional. Make sure the fix is
applied on the `Allow access to queue` template object so the preview shows
useful SQL.
- Around line 191-323: The getRealtimePolicyTemplates array is being force-cast
to PolicyTemplate[], which bypasses TypeScript’s structural checks. Remove the
cast and let the array be validated directly like the other template helpers, so
each object in getRealtimePolicyTemplates is checked against PolicyTemplate and
any missing or mistyped fields are caught at compile time.
- Around line 275-321: The SQL preview strings for the presence policies still
include an extra standalone semicolon because the statement templates end with
`);\n ;`. Update the `policy-presences-4` entry in `Policies.constants` so its
`statement` text matches the cleaned pattern used elsewhere and does not render
a double semicolon in `TemplatePreview`; keep the `statement`, `definition`, and
`check` fields aligned with the corrected SQL shape.
In
`@apps/studio/components/interfaces/Database/Policies/PolicyTableRow/index.tsx`:
- Line 95: Remove the debug console output from the policy row render path: the
`console.log({ status, exposedSchemas })` inside `PolicyTableRow` should be
deleted so it doesn’t fire on every render of each row. Locate the log in
`PolicyTableRow` and remove it without changing the component’s render logic or
props handling.
In
`@apps/studio/components/interfaces/Storage/StoragePolicies/StoragePolicies.utils.ts`:
- Around line 17-158: Add a vitest unit test file for the policy helper
functions in StoragePolicies.utils to cover the newly extracted create/update
logic. Focus on createSQLPolicy, createSQLStatementForCreatePolicy,
createSQLStatementForUpdatePolicy, createPayloadForCreatePolicy, and
createPayloadForUpdatePolicy with table-driven cases for whitespace-only
normalization, no-op diffs, empty roles defaulting to public, and rename/update
SQL previews. Use the existing function names to locate the helpers and assert
the returned statement/payload shapes for create and update paths.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b6357177-dc22-4cd9-a9e8-af45eb7699c7
📒 Files selected for processing (34)
apps/studio/components/interfaces/Database/Policies/Policies.constants.tsapps/studio/components/interfaces/Database/Policies/Policies.utils.test.tsapps/studio/components/interfaces/Database/Policies/Policies.utils.tsapps/studio/components/interfaces/Database/Policies/PolicyEditorModal/PolicyEditorModal.constants.tsapps/studio/components/interfaces/Database/Policies/PolicyEditorPanel/PolicyTemplates.tsxapps/studio/components/interfaces/Database/Policies/PolicyTableRow/PolicyTableRowHeader.tsxapps/studio/components/interfaces/Database/Policies/PolicyTableRow/index.tsxapps/studio/components/interfaces/Database/Policies/PolicyTemplates/PolicyTemplates.constants.tsapps/studio/components/interfaces/Storage/Storage.types.tsapps/studio/components/interfaces/Storage/StoragePolicies/PolicyEditor/PolicyAllowedOperation.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyEditor/PolicyDefinition.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyEditor/PolicyEditorFooter.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyEditor/PolicyName.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyEditor/PolicyRoles.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyEditor/index.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyEditorModal/PolicyEditorModal.constants.tsapps/studio/components/interfaces/Storage/StoragePolicies/PolicyEditorModal/PolicyEditorModalTitle.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyEditorModal/index.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyReview.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicySelection.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyTemplates/TemplatePreview.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyTemplates/TemplatesList.tsxapps/studio/components/interfaces/Storage/StoragePolicies/PolicyTemplates/index.tsxapps/studio/components/interfaces/Storage/StoragePolicies/StoragePolicies.tsxapps/studio/components/interfaces/Storage/StoragePolicies/StoragePolicies.types.tsapps/studio/components/interfaces/Storage/StoragePolicies/StoragePolicies.utils.tsapps/studio/components/interfaces/Storage/StoragePolicies/StoragePoliciesEditPolicyModal.tsxapps/studio/components/interfaces/Storage/StoragePolicies/StoragePoliciesEditor.tsxapps/studio/components/interfaces/Storage/StoragePolicies/StoragePoliciesReview.tsxapps/studio/components/interfaces/Storage/StoragePolicies/StoragePolicyEditorModalTitle.tsxapps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsxapps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.utils.tsxapps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsxapps/studio/pages/project/[ref]/database/policies.tsx
💤 Files with no reviewable changes (5)
- apps/studio/components/interfaces/Database/Policies/PolicyTemplates/PolicyTemplates.constants.ts
- apps/studio/components/interfaces/Database/Policies/PolicyEditorModal/PolicyEditorModal.constants.ts
- apps/studio/components/interfaces/Database/Policies/Policies.utils.test.ts
- apps/studio/components/interfaces/Database/Policies/Policies.utils.ts
- apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
🎭 Playwright Test ResultsDetails
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
|
|
||
| const admonitionMessage = useMemo(() => getTableAdmonitionMessage(status), [status]) | ||
|
|
||
| console.log({ status, exposedSchemas }) |
Braintrust eval report
|
Context
This is one chonky boy of a PR, but it's just re-organizing files and folders to clean things up
Storage Policies have been using the old Database policy UI (the one with the Dialog), so it makes most sense to shift those files under the
Storagefolder instead of keeping them underDatabase, so it's clearer which files are being consumed by whom, and easier to clean things up as wellAs part of this clean up, also tore out all the RLS generation logic from the Table Editor which are no longer used as they were affected by the change in files.
Deprecated + deleted any unused code too
Summary by CodeRabbit