mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 10:25:06 +03:00
* feat(studio): add mutation to update table access privileges Adds a mutation to update table grants for `anon` and `authenticated` roles. * feat(studio): add data api toggles Add toggles to the Table Editor, allowing fine-grained grants to the anon and authenticated roles. * fix(studio): don't show rls policies warning if table not exposed RLS policies warning was showing in Table Editor side panel even if table was not exposed due to no grants to anon/authenticated. * fixup! feat(studio): add data api toggles * fixup! feat(studio): add data api toggles * fix(studio): revalidate rls lints when table grants are toggled --------- Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
75 lines
1.7 KiB
TypeScript
75 lines
1.7 KiB
TypeScript
import { useMemo } from 'react'
|
|
|
|
import {
|
|
parseDbSchemaString,
|
|
useProjectPostgrestConfigQuery,
|
|
} from 'data/config/project-postgrest-config-query'
|
|
|
|
type UseIsSchemaExposedParams = {
|
|
projectRef?: string
|
|
schemaName?: string
|
|
}
|
|
|
|
type UseIsSchemaExposedOptions = {
|
|
enabled?: boolean
|
|
}
|
|
|
|
export type UseIsSchemaExposedReturn =
|
|
| {
|
|
status: 'pending'
|
|
data: undefined
|
|
isPending: true
|
|
isError: false
|
|
isSuccess: false
|
|
}
|
|
| {
|
|
status: 'error'
|
|
data: undefined
|
|
isPending: false
|
|
isError: true
|
|
isSuccess: false
|
|
}
|
|
| {
|
|
status: 'success'
|
|
data: boolean
|
|
isPending: false
|
|
isError: false
|
|
isSuccess: true
|
|
}
|
|
|
|
export const useIsSchemaExposed = (
|
|
{ projectRef, schemaName }: UseIsSchemaExposedParams,
|
|
{ enabled = true }: UseIsSchemaExposedOptions = {}
|
|
): UseIsSchemaExposedReturn => {
|
|
const shouldQueryConfig = enabled && !!projectRef && !!schemaName
|
|
const {
|
|
data: dbSchemaString,
|
|
isPending: isConfigPending,
|
|
isError: isConfigError,
|
|
} = useProjectPostgrestConfigQuery(
|
|
{ projectRef },
|
|
{ enabled: shouldQueryConfig, select: ({ db_schema }) => db_schema }
|
|
)
|
|
|
|
const exposedSchemas = useMemo(() => {
|
|
if (!dbSchemaString) return []
|
|
return parseDbSchemaString(dbSchemaString)
|
|
}, [dbSchemaString])
|
|
|
|
if (!shouldQueryConfig || isConfigPending) {
|
|
return { status: 'pending', data: undefined, isPending: true, isError: false, isSuccess: false }
|
|
}
|
|
|
|
if (isConfigError) {
|
|
return { status: 'error', data: undefined, isPending: false, isError: true, isSuccess: false }
|
|
}
|
|
|
|
return {
|
|
status: 'success',
|
|
data: exposedSchemas.includes(schemaName),
|
|
isPending: false,
|
|
isError: false,
|
|
isSuccess: true,
|
|
}
|
|
}
|