import { Badge, cn, Tabs_Shadcn_, TabsContent_Shadcn_, TabsList_Shadcn_, TabsTrigger_Shadcn_, } from 'ui' import { Admonition } from 'ui-patterns' import { Results } from '../../SQLEditor/UtilityPanel/Results' import { RLSTableCard } from './RLSTableCard' import { ParseQueryResults } from './RLSTester.types' import { deriveRLSTestState } from './RLSTesterResults.utils' import { useTestQueryRLS } from './useTestQueryRLS' import type { Policy } from '@/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils' interface RLSTesterResultsProps { results: Object[] autoLimit: boolean parseQueryResults: ParseQueryResults handleSelectEditPolicy: (policy: Policy) => void } export const RLSTesterResults = ({ results, autoLimit, parseQueryResults, handleSelectEditPolicy, }: RLSTesterResultsProps) => { const { limit } = useTestQueryRLS() const { isServiceRole, tableWithRLSEnabledButNoPolicies, tableWithRLSEnabledWithPolicyFalse, noAccessToData, } = deriveRLSTestState(parseQueryResults) return (

Summary

{noAccessToData ? ( No access ) : ( {results.length > 0 ? 'Can access' : 'Has access'} )}
Policies applied Data preview {!!parseQueryResults && (

Ran as

{!parseQueryResults.role ? ( postgres ) : parseQueryResults.user ? (

{parseQueryResults.user.email}

) : parseQueryResults.role === 'anon' ? (

an Anonymous user

) : null}
{parseQueryResults.role === 'anon' && (

Not logged in user

)} {!!parseQueryResults.user && ( ID: {parseQueryResults.user.id} )}
)} {!isServiceRole && (!!tableWithRLSEnabledButNoPolicies ? (

This user has no access to any rows from this query

The table{' '} {tableWithRLSEnabledButNoPolicies.schema}. {tableWithRLSEnabledButNoPolicies.table} {' '} has RLS enabled but no policies set up for the{' '} {parseQueryResults.role}{' '} role.

) : tableWithRLSEnabledWithPolicyFalse ? (

This user has no access to any rows from this query

The table{' '} {tableWithRLSEnabledWithPolicyFalse.schema}. {tableWithRLSEnabledWithPolicyFalse.table} {' '} has a policy that evaluates to false for the{' '} {parseQueryResults.role}{' '} role.

) : null)} {isServiceRole && (

The postgres role has access to all rows for this query

The postgres role has admin privileges and bypasses all RLS policies.

)}

Table access

{!isServiceRole && (
{parseQueryResults?.tables.map((x) => { const { schema, table, tablePolicies, isRLSEnabled } = x return ( ) })}
)}
{results.length > 0 && (

{results.length} row{results.length > 1 ? 's' : ''} {autoLimit && results.length >= limit && ` (Limited to only ${limit} rows)`}

)}
) }