useTestQueryRLS.utils.ts 669 B

123456789101112131415161718192021222324
  1. import type { Policy } from '@/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils'
  2. import type { ParseSQLQueryResponse } from '@/data/misc/parse-query-mutation'
  3. export function filterTablePolicies({
  4. policies,
  5. schema,
  6. table,
  7. role,
  8. operation,
  9. }: {
  10. policies: Policy[]
  11. schema: string
  12. table: string
  13. role: string | undefined
  14. operation: ParseSQLQueryResponse['operation']
  15. }): Policy[] {
  16. return policies.filter(
  17. (x) =>
  18. x.schema === schema &&
  19. x.table === table &&
  20. (x.roles.includes(role ?? '') || (x.roles.length === 1 && x.roles[0] === 'public')) &&
  21. (x.command === 'ALL' || x.command === operation)
  22. )
  23. }