mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem Migrating Studio's permission checks from the old RLS json logic to openfga backed permissions. ### New hooks and helpers - `usePermissionsQueryV2` fetches the new profile openfga permisisons - `useAsyncCheckPermissionsV2` the replacement for the old check hook; takes an FGA permission string (or a list) - `FGA_PERMISSIONS` permission constants derived from `@supabase/shared-types`. At the moment, the hook also accepts plain strings for permissions not yet published in the package - `useAsyncCheckUserContentPermissions` new hook for permission checks on user content (SQL snippets, reports, log snippets). This wraps ``useAsyncCheckPermissionsV2` and adds existing content level rules on top of the fga permission check ### Notes - ~~Need api to support new permissions: project_operations_write, billing_read/write, audit_logs_read~~ [DONE] - ~~Still need to support: organization_config_read/write, auth hooks and users permissions~~ [DONE] --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { useParams } from 'common'
|
|
import { PropsWithChildren } from 'react'
|
|
|
|
import { ProjectLayout } from '../ProjectLayout'
|
|
import { LogsSidebarMenuV2 } from './LogsSidebarMenuV2'
|
|
import { NoPermission } from '@/components/ui/NoPermission'
|
|
import { UnknownInterface } from '@/components/ui/UnknownInterface'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { withAuth } from '@/hooks/misc/withAuth'
|
|
|
|
interface LogsLayoutProps {
|
|
title: string
|
|
}
|
|
|
|
const LogsLayout = ({ title, children }: PropsWithChildren<LogsLayoutProps>) => {
|
|
const { ref } = useParams()
|
|
const logsEnabled = useIsFeatureEnabled('logs:all')
|
|
|
|
const { isLoading, can: canUseLogsExplorer } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.ANALYTICS_LOGS_READ
|
|
)
|
|
|
|
if (!logsEnabled) {
|
|
return (
|
|
<ProjectLayout product="Logs" browserTitle={{ section: title }}>
|
|
<UnknownInterface urlBack={`/project/${ref}`} />
|
|
</ProjectLayout>
|
|
)
|
|
}
|
|
|
|
if (!canUseLogsExplorer) {
|
|
if (isLoading) {
|
|
return <ProjectLayout isLoading product="Logs" browserTitle={{ section: title }} />
|
|
}
|
|
|
|
if (!isLoading && !canUseLogsExplorer) {
|
|
return (
|
|
<ProjectLayout product="Logs" browserTitle={{ section: title }}>
|
|
<NoPermission isFullPage resourceText="access your project's logs" />
|
|
</ProjectLayout>
|
|
)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<ProjectLayout
|
|
product="Logs"
|
|
browserTitle={{ section: title }}
|
|
productMenu={<LogsSidebarMenuV2 />}
|
|
>
|
|
{children}
|
|
</ProjectLayout>
|
|
)
|
|
}
|
|
|
|
export default withAuth(LogsLayout)
|