Files
supabase/apps/studio/components/interfaces/Integrations/Wrappers/AddWrapperButton.tsx
T
fffb1e23ca feat: implement profile permissions v2 api (#50966)
## 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>
2026-10-21 06:54:16 -04:00

60 lines
1.8 KiB
TypeScript

import { useParams } from 'common'
import Link from 'next/link'
import { useMemo } from 'react'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { useDatabaseExtensionsQuery } from '@/data/database-extensions/database-extensions-query'
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
const WRAPPER_REQUIRED_EXTENSION_NAMES = ['wrappers', 'supabase_vault']
interface AddWrapperButtonProps {
variant?: 'default' | 'primary' | 'outline'
}
export const AddWrapperButton = ({ variant = 'default' }: AddWrapperButtonProps) => {
const { ref, id } = useParams()
const { can: canCreateWrapper } = useAsyncCheckPermissionsV2(
FGA_PERMISSIONS.PROJECT.DATABASE_WRITE
)
const { data: project } = useSelectedProjectQuery()
const { data: extensions } = useDatabaseExtensionsQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
const needsExtensions = useMemo(
() =>
WRAPPER_REQUIRED_EXTENSION_NAMES.some(
(name) => !extensions?.find((ext) => ext.name === name)?.installed_version
),
[extensions]
)
const label = needsExtensions ? 'Install wrapper' : 'Add new wrapper'
return (
<ButtonTooltip
asChild={canCreateWrapper}
variant={variant}
disabled={!canCreateWrapper}
tooltip={{
content: {
side: 'bottom',
text: !canCreateWrapper
? 'You need additional permissions to create a foreign data wrapper'
: undefined,
},
}}
>
{canCreateWrapper ? (
<Link href={`/project/${ref}/integrations/${id}/wrappers?new=true`}>{label}</Link>
) : (
label
)}
</ButtonTooltip>
)
}