Files
supabase/apps/studio/components/interfaces/Auth/RLSTester/useTestQueryRLS.utils.ts
Joshen Lim 5d155df42b RLS Tester needs to consider policies for 'ALL' operation (#45623)
## Context

Missed another case here - RLS tester when retrieving policies
associated with query needs to consider policies with the `ALL`
operation

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Tests**
* Added comprehensive tests for Row-Level Security policy filtering,
covering schema/table matching, role handling (including
public/service-role cases), command/operation semantics, and combined
filter behavior.

* **Refactor**
* Centralized and clarified RLS policy filtering logic used by the
tester for improved maintainability and consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-08 15:18:51 +08:00

25 lines
669 B
TypeScript

import type { Policy } from '@/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils'
import type { ParseSQLQueryResponse } from '@/data/misc/parse-query-mutation'
export function filterTablePolicies({
policies,
schema,
table,
role,
operation,
}: {
policies: Policy[]
schema: string
table: string
role: string | undefined
operation: ParseSQLQueryResponse['operation']
}): Policy[] {
return policies.filter(
(x) =>
x.schema === schema &&
x.table === table &&
(x.roles.includes(role ?? '') || (x.roles.length === 1 && x.roles[0] === 'public')) &&
(x.command === 'ALL' || x.command === operation)
)
}