mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +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>
197 lines
7.0 KiB
TypeScript
197 lines
7.0 KiB
TypeScript
import {
|
|
BookOpenIcon,
|
|
CheckIcon,
|
|
EditIcon,
|
|
MoreVerticalIcon,
|
|
TrashIcon,
|
|
WebhookIcon,
|
|
} from 'lucide-react'
|
|
import {
|
|
Badge,
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from 'ui'
|
|
import { Input } from 'ui-patterns/DataInputs/Input'
|
|
|
|
import { Hook } from './hooks.constants'
|
|
import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { DOCS_URL } from '@/lib/constants'
|
|
|
|
interface HookCardProps {
|
|
hook: Hook
|
|
onSelectEdit: () => void
|
|
onSelectDelete: () => void
|
|
}
|
|
|
|
export const HookCard = ({ hook, onSelectEdit, onSelectDelete }: HookCardProps) => {
|
|
const { can: canUpdateAuthHook } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.AUTH_HOOKS_WRITE
|
|
)
|
|
|
|
return (
|
|
<div className="bg-surface-100 border-default overflow-hidden border shadow-sm px-5 py-4 flex flex-row first:rounded-t-md last:rounded-b-md space-x-4">
|
|
<div>
|
|
<WebhookIcon size={21} strokeWidth="1" />
|
|
</div>
|
|
<div className="flex flex-col grow overflow-y-auto w-full">
|
|
<span className="text-sm text-foreground">{hook.title}</span>
|
|
<span className="text-sm text-foreground-lighter">{hook.subtitle}</span>
|
|
<div className="text-sm flex flex-row space-x-5 py-4">
|
|
{hook.method.type === 'postgres' ? (
|
|
<div className="flex flex-col w-full space-y-2 max-w-xl">
|
|
<div className="flex flex-row items-center">
|
|
<span className="text-foreground-light w-20">Type</span>
|
|
<span className="text-foreground">Postgres function</span>
|
|
</div>
|
|
<div className="flex flex-row items-center">
|
|
<label htmlFor="schema" className="text-foreground-light w-20">
|
|
Schema
|
|
</label>
|
|
<Input
|
|
id="schema"
|
|
title={hook.method.schema}
|
|
copy
|
|
readOnly
|
|
disabled
|
|
containerClassName="flex-1"
|
|
className="font-mono text-xs md:text-xs disabled:text-foreground-light opacity-100"
|
|
value={hook.method.schema}
|
|
/>
|
|
</div>
|
|
<div className="flex flex-row items-center">
|
|
<label htmlFor="functionName" className="text-foreground-light w-20">
|
|
Function
|
|
</label>
|
|
<Input
|
|
id="functionName"
|
|
title={hook.method.functionName}
|
|
copy
|
|
readOnly
|
|
disabled
|
|
containerClassName="flex-1"
|
|
className="font-mono text-xs md:text-xs disabled:text-foreground-light opacity-100"
|
|
value={hook.method.functionName}
|
|
/>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="flex flex-col w-full space-y-2 max-w-xl">
|
|
<div className="flex flex-row items-center">
|
|
<span className="text-foreground-light w-20">Type</span>
|
|
<span className="text-foreground">HTTPS endpoint</span>
|
|
</div>
|
|
<div className="flex flex-row items-center">
|
|
<label htmlFor="url" className="text-foreground-light w-20">
|
|
Endpoint
|
|
</label>
|
|
<Input
|
|
id="url"
|
|
title={hook.method.url}
|
|
copy
|
|
readOnly
|
|
disabled
|
|
containerClassName="flex-1"
|
|
className="font-mono text-xs md:text-xs disabled:text-foreground-light opacity-100"
|
|
value={hook.method.url}
|
|
/>
|
|
</div>
|
|
<div className="flex flex-row items-center">
|
|
<label htmlFor="secret" className="text-foreground-light w-20">
|
|
Secret
|
|
</label>
|
|
<Input
|
|
id="secret"
|
|
copy
|
|
title={hook.method.secret}
|
|
reveal={true}
|
|
readOnly
|
|
disabled
|
|
containerClassName="flex-1"
|
|
className="font-mono text-xs md:text-xs disabled:text-foreground-light opacity-100"
|
|
value={hook.method.secret}
|
|
/>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<div className="flex items-center gap-x-2">
|
|
{hook.enabled ? (
|
|
<Badge className="space-x-1" variant="success">
|
|
<div className="h-3.5 w-3.5 bg-brand-default rounded-full flex justify-center items-center">
|
|
<CheckIcon className="h-2 w-2 text-background-overlay " strokeWidth={6} />
|
|
</div>
|
|
<span>Enabled</span>
|
|
</Badge>
|
|
) : (
|
|
<Badge variant="warning">
|
|
<span>Disabled</span>
|
|
</Badge>
|
|
)}
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
className="px-1"
|
|
icon={<MoreVerticalIcon />}
|
|
aria-label={`Open actions for ${hook.title}`}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-40">
|
|
<DropdownMenuItemTooltip
|
|
className="gap-x-2"
|
|
disabled={!canUpdateAuthHook}
|
|
onClick={onSelectEdit}
|
|
tooltip={{
|
|
content: {
|
|
text: !canUpdateAuthHook
|
|
? 'You need additional permissions to configure auth hooks'
|
|
: undefined,
|
|
side: 'left',
|
|
},
|
|
}}
|
|
>
|
|
<EditIcon size={12} />
|
|
<span>Edit hook</span>
|
|
</DropdownMenuItemTooltip>
|
|
<DropdownMenuItem asChild className="gap-x-2">
|
|
<a
|
|
target="_blank"
|
|
rel="noreferrer noopener"
|
|
href={`${DOCS_URL}/guides/auth/auth-hooks/${hook.docSlug}`}
|
|
>
|
|
<BookOpenIcon size={12} />
|
|
<span>Documentation</span>
|
|
</a>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItemTooltip
|
|
className="gap-x-2"
|
|
disabled={!canUpdateAuthHook}
|
|
onClick={onSelectDelete}
|
|
tooltip={{
|
|
content: {
|
|
text: !canUpdateAuthHook
|
|
? 'You need additional permissions to delete auth hooks'
|
|
: undefined,
|
|
side: 'left',
|
|
},
|
|
}}
|
|
>
|
|
<TrashIcon size={12} />
|
|
<span>Delete hook</span>
|
|
</DropdownMenuItemTooltip>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|