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 ? (Ran as
{!parseQueryResults.role ? (postgres
) : parseQueryResults.user ? (
{parseQueryResults.user.email}
) : parseQueryResults.role === 'anon' ? (an Anonymous user
) : null}Not logged in user
)} {!!parseQueryResults.user && (ID: {parseQueryResults.user.id}
)}
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.
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.
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 && ({results.length} row{results.length > 1 ? 's' : ''} {autoLimit && results.length >= limit && ` (Limited to only ${limit} rows)`}
)}