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>
104 lines
3.6 KiB
TypeScript
104 lines
3.6 KiB
TypeScript
import { useParams } from 'common'
|
|
import dayjs from 'dayjs'
|
|
import { AlertCircleIcon } from 'lucide-react'
|
|
|
|
import { TimezoneSelection } from './TimezoneSelection'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { FormPanel } from '@/components/ui/Forms/FormPanel'
|
|
import { useBackupsQuery } from '@/data/database/backups-query'
|
|
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import type { Timezone } from '@/lib/constants/timezones'
|
|
|
|
interface PITRStatusProps {
|
|
selectedTimezone: Timezone
|
|
onUpdateTimezone: (timezone: Timezone) => void
|
|
onSetConfiguration: () => void
|
|
}
|
|
|
|
const PITRStatus = ({
|
|
selectedTimezone,
|
|
onUpdateTimezone,
|
|
onSetConfiguration,
|
|
}: PITRStatusProps) => {
|
|
const { ref } = useParams()
|
|
const { data: backups } = useBackupsQuery({ projectRef: ref })
|
|
const { data: databases } = useReadReplicasQuery({ projectRef: ref })
|
|
|
|
const hasReadReplicas = (databases ?? []).length > 1
|
|
|
|
const { earliestPhysicalBackupDateUnix, latestPhysicalBackupDateUnix } =
|
|
backups?.physicalBackupData ?? {}
|
|
|
|
const earliestAvailableBackup = dayjs
|
|
.unix(earliestPhysicalBackupDateUnix ?? 0)
|
|
.tz(selectedTimezone?.utc[0])
|
|
.format('DD MMM YYYY, HH:mm:ss')
|
|
|
|
const latestAvailableBackup = dayjs
|
|
.unix(latestPhysicalBackupDateUnix ?? 0)
|
|
.tz(selectedTimezone?.utc[0])
|
|
.format('DD MMM YYYY, HH:mm:ss')
|
|
|
|
const { can: canTriggerPhysicalBackup } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.BACKUPS_WRITE
|
|
)
|
|
|
|
return (
|
|
<>
|
|
<FormPanel
|
|
disabled={true}
|
|
footer={
|
|
<div className="flex items-center justify-between p-6">
|
|
<div className="flex items-center space-x-4">
|
|
<AlertCircleIcon className="text-foreground-light" size={18} strokeWidth={1.5} />
|
|
<span className="text-foreground-light text-sm">
|
|
You'll be able to pick the right date and time when you begin
|
|
</span>
|
|
</div>
|
|
<ButtonTooltip
|
|
variant="primary"
|
|
disabled={hasReadReplicas || !canTriggerPhysicalBackup}
|
|
onClick={() => onSetConfiguration()}
|
|
tooltip={{
|
|
content: {
|
|
side: 'left',
|
|
text: hasReadReplicas
|
|
? 'You will need to remove all read replicas first to trigger a PITR recovery'
|
|
: !canTriggerPhysicalBackup
|
|
? 'You need additional permissions to trigger a PITR recovery'
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
Start a restore
|
|
</ButtonTooltip>
|
|
</div>
|
|
}
|
|
>
|
|
<div className="p-6 space-y-6">
|
|
<div className="w-[350px]">
|
|
<TimezoneSelection
|
|
selectedTimezone={selectedTimezone}
|
|
date={dayjs.unix(latestPhysicalBackupDateUnix ?? 0)}
|
|
onSelectTimezone={onUpdateTimezone}
|
|
/>
|
|
</div>
|
|
<div className="flex items-center space-x-20">
|
|
<div className="space-y-2">
|
|
<p className="text-sm text-foreground-light">Database restore available from</p>
|
|
<p className="text-2xl">{earliestAvailableBackup}</p>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<p className="text-sm text-foreground-light">Latest restore available at</p>
|
|
<p className="text-2xl">{latestAvailableBackup}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</FormPanel>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default PITRStatus
|