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>
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { useEffect } from 'react'
|
|
import { Card, CardContent, CardFooter, Form } from 'ui'
|
|
|
|
import { AIOptInLevelSelector } from './AIOptInLevelSelector'
|
|
import { FormActions } from '@/components/ui/Forms/FormActions'
|
|
import { useAIOptInForm } from '@/hooks/forms/useAIOptInForm'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
|
|
export const DataPrivacyForm = () => {
|
|
const { form, onSubmit, isUpdating, currentOptInLevel } = useAIOptInForm()
|
|
const { can: canUpdateOrganization } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.ORGANIZATION.ADMIN_WRITE
|
|
)
|
|
|
|
const permissionsHelperText = !canUpdateOrganization
|
|
? "You need additional permissions to manage this organization's settings"
|
|
: undefined
|
|
|
|
useEffect(() => {
|
|
form.reset({ aiOptInLevel: currentOptInLevel })
|
|
}, [currentOptInLevel, form])
|
|
|
|
return (
|
|
<Form {...form}>
|
|
<form id="org-privacy-form" onSubmit={form.handleSubmit(onSubmit)}>
|
|
<Card>
|
|
<CardContent className="pt-6">
|
|
<AIOptInLevelSelector
|
|
control={form.control}
|
|
disabled={!canUpdateOrganization || isUpdating}
|
|
layout="flex-row-reverse"
|
|
label="Supabase Assistant Opt-in Level"
|
|
/>
|
|
</CardContent>
|
|
<CardFooter className="flex justify-end p-4 md:px-8">
|
|
<FormActions
|
|
form="org-privacy-form"
|
|
isSubmitting={isUpdating}
|
|
hasChanges={form.formState.isDirty}
|
|
handleReset={() => form.reset()}
|
|
helper={permissionsHelperText}
|
|
disabled={!canUpdateOrganization}
|
|
/>
|
|
</CardFooter>
|
|
</Card>
|
|
</form>
|
|
</Form>
|
|
)
|
|
}
|