mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +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>
75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import type { PropsWithChildren } from 'react'
|
|
import { createContext, useContext, useMemo } from 'react'
|
|
|
|
import type { OrganizationRolesResponse } from '@/data/organization-members/organization-roles-query'
|
|
import type { OrganizationMember } from '@/data/organizations/organization-members-query'
|
|
import type { OrganizationBase } from '@/data/organizations/organizations-query'
|
|
import { PermissionsV2Data } from '@/data/permissions/permissions-query-v2'
|
|
import type { Permission } from '@/types'
|
|
|
|
type TeamSettingsDataContextValue = {
|
|
members: OrganizationMember[]
|
|
roles: OrganizationRolesResponse | undefined
|
|
isLoadingRoles: boolean
|
|
permissions: Permission[] | undefined
|
|
permissionsV2: PermissionsV2Data | undefined
|
|
totalNumOrgProjects: number
|
|
selectedOrganization: OrganizationBase | undefined
|
|
organizationMembersDeletionEnabled: boolean
|
|
onManageAccess: (member: OrganizationMember) => void
|
|
}
|
|
|
|
const TeamSettingsDataContext = createContext<TeamSettingsDataContextValue | null>(null)
|
|
|
|
export const useTeamSettingsData = () => {
|
|
const context = useContext(TeamSettingsDataContext)
|
|
if (!context) {
|
|
throw new Error('useTeamSettingsData must be used within TeamSettingsDataProvider')
|
|
}
|
|
return context
|
|
}
|
|
|
|
export const TeamSettingsDataProvider = ({
|
|
children,
|
|
members,
|
|
roles,
|
|
isLoadingRoles,
|
|
permissions,
|
|
permissionsV2,
|
|
totalNumOrgProjects,
|
|
selectedOrganization,
|
|
organizationMembersDeletionEnabled,
|
|
onManageAccess,
|
|
}: PropsWithChildren<TeamSettingsDataContextValue>) => {
|
|
const contextValue = useMemo(
|
|
() => ({
|
|
members,
|
|
roles,
|
|
isLoadingRoles,
|
|
permissions,
|
|
permissionsV2,
|
|
totalNumOrgProjects,
|
|
selectedOrganization,
|
|
organizationMembersDeletionEnabled,
|
|
onManageAccess,
|
|
}),
|
|
[
|
|
members,
|
|
roles,
|
|
isLoadingRoles,
|
|
permissions,
|
|
permissionsV2,
|
|
totalNumOrgProjects,
|
|
selectedOrganization,
|
|
organizationMembersDeletionEnabled,
|
|
onManageAccess,
|
|
]
|
|
)
|
|
|
|
return (
|
|
<TeamSettingsDataContext.Provider value={contextValue}>
|
|
{children}
|
|
</TeamSettingsDataContext.Provider>
|
|
)
|
|
}
|