Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Prevent disabling PITR when hipaa is enabled (#34513)

Joshen Lim47fe4738d3e1
diff --git a/apps/studio/components/interfaces/Settings/Addons/PITRSidePanel.tsx b/apps/studio/components/interfaces/Settings/Addons/PITRSidePanel.tsx
index c14c6e1ae7a..9e9e04dd071 100644
--- a/apps/studio/components/interfaces/Settings/Addons/PITRSidePanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Addons/PITRSidePanel.tsx
@@ -7,6 +7,7 @@ import { toast } from 'sonner'
import { useParams } from 'common'
import { subscriptionHasHipaaAddon } from 'components/interfaces/Billing/Subscription/Subscription.utils'
+import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useProjectAddonRemoveMutation } from 'data/subscriptions/project-addon-remove-mutation'
@@ -57,6 +58,7 @@ const PITRSidePanel = () => {
const { resolvedTheme } = useTheme()
const project = useSelectedProject()
const organization = useSelectedOrganization()
+ const { data: projectSettings } = useProjectSettingsV2Query({ projectRef })
const [selectedCategory, setSelectedCategory] = useState<'on' | 'off'>('off')
const [selectedOption, setSelectedOption] = useState<string>('pitr_0')
@@ -65,13 +67,13 @@ const PITRSidePanel = () => {
const isBranchingEnabled =
project?.is_branch_enabled === true || project?.parent_project_ref !== undefined
- const { panel, setPanel, closePanel } = useAddonsPagePanel()
+ const { panel, closePanel } = useAddonsPagePanel()
const visible = panel === 'pitr'
const { data: databases } = useReadReplicasQuery({ projectRef })
const { data: addons, isLoading } = useProjectAddonsQuery({ projectRef })
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug })
- const hasHipaaAddon = subscriptionHasHipaaAddon(subscription)
+ const hasHipaaAddon = subscriptionHasHipaaAddon(subscription) && projectSettings?.is_sensitive
const { mutate: updateAddon, isLoading: isUpdating } = useProjectAddonUpdateMutation({
onSuccess: () => {
@@ -102,10 +104,17 @@ const PITRSidePanel = () => {
const hasReadReplicas = (databases ?? []).length > 1
const hasChanges = selectedOption !== (subscriptionPitr?.variant.identifier ?? 'pitr_0')
- const selectedPitr = availableOptions.find((option) => option.identifier === selectedOption)
const isFreePlan = subscription?.plan?.id === 'free'
+ const selectedPitr = availableOptions.find((option) => option.identifier === selectedOption)
+
+ // These are illegal states. If they are true, we should block the user from saving them.
const blockDowngradeDueToReadReplicas =
hasChanges && hasReadReplicas && selectedCategory === 'off' && selectedOption === 'pitr_0'
+ const blockDowngradeDueToHipaa =
+ hasHipaaAddon &&
+ (selectedCategory !== 'on' ||
+ // If the project is HIPAA, we don't allow the user to downgrade below 28 days
+ selectedPitr?.identifier !== 'pitr_28')
useEffect(() => {
if (visible) {
@@ -142,17 +151,19 @@ const PITRSidePanel = () => {
!hasChanges ||
isSubmitting ||
!canUpdatePitr ||
- hasHipaaAddon ||
+ blockDowngradeDueToHipaa ||
blockDowngradeDueToReadReplicas
}
tooltip={
- hasHipaaAddon
- ? 'Unable to change PITR with HIPAA add-on'
- : isFreePlan
- ? 'Unable to enable point in time recovery on a Free Plan'
- : !canUpdatePitr
- ? 'You do not have permission to update PITR'
- : undefined
+ blockDowngradeDueToHipaa
+ ? 'Unable to disable PITR with HIPAA add-on'
+ : blockDowngradeDueToReadReplicas
+ ? 'Remove all read replicas before disabling PITR'
+ : isFreePlan
+ ? 'Unable to enable point in time recovery on a Free Plan'
+ : !canUpdatePitr
+ ? 'You do not have permission to update PITR'
+ : undefined
}
header={
<div className="flex items-center justify-between">
@@ -170,20 +181,6 @@ const PITRSidePanel = () => {
}
>
<SidePanel.Content>
- {hasHipaaAddon && (
- <Alert_Shadcn_>
- <AlertTitle_Shadcn_>PITR cannot be changed with HIPAA</AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>
- All projects should have PITR enabled by default and cannot be changed with HIPAA
- enabled. Contact support for further assistance.
- </AlertDescription_Shadcn_>
- <div className="mt-4">
- <Button type="default" asChild>
- <Link href="/support/new">Contact support</Link>
- </Button>
- </div>
- </Alert_Shadcn_>
- )}
<div className="py-6 space-y-4">
<p className="text-sm">
Point-in-Time Recovery (PITR) allows a project to be backed up at much shorter
@@ -206,7 +203,11 @@ const PITRSidePanel = () => {
} else if (subscriptionPitr?.variant.identifier !== undefined) {
setSelectedOption(subscriptionPitr.variant.identifier)
} else {
- setSelectedOption('pitr_7')
+ if (hasHipaaAddon) {
+ setSelectedOption('pitr_28')
+ } else {
+ setSelectedOption('pitr_7')
+ }
}
}}
>
@@ -250,10 +251,25 @@ const PITRSidePanel = () => {
</Alert_Shadcn_>
)}
- {blockDowngradeDueToReadReplicas && (
+ {blockDowngradeDueToHipaa ? (
+ <Alert_Shadcn_>
+ <AlertTitle_Shadcn_>PITR cannot be disabled on HIPAA projects</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ PITR is enabled by default for all HIPAA projects and cannot be turned off. Contact
+ support for further assistance.
+ </AlertDescription_Shadcn_>
+ <div className="mt-4">
+ <Button type="default" asChild>
+ <Link href="/support/new">Contact support</Link>
+ </Button>
+ </div>
+ </Alert_Shadcn_>
+ ) : blockDowngradeDueToReadReplicas ? (
<Alert_Shadcn_>
<WarningIcon />
- <AlertTitle_Shadcn_>Remove all read replicas before downgrading</AlertTitle_Shadcn_>
+ <AlertTitle_Shadcn_>
+ Remove all read replicas before disabling PITR
+ </AlertTitle_Shadcn_>
<AlertDescription_Shadcn_>
You currently have active read replicas. The minimum compute size for using read
replicas is the Small Compute. You need to remove all read replicas before
@@ -267,7 +283,7 @@ const PITRSidePanel = () => {
</Button>
</AlertDescription_Shadcn_>
</Alert_Shadcn_>
- )}
+ ) : null}
{selectedCategory === 'on' && (
<div className="!mt-8 pb-4">