R2NP: add 403 permissions or physical backups disabled handler (#31197)

* add 403 err handler

* validate error

* rm retry logic in fvor of enabling the query only if pitr or pb are enabled

* disable queries instead of checking error code
This commit is contained in:
Jordi Enric authored and GitHub committed 2024-12-19 13:35:21 +01:00
1 parent 02ad2661f7
commit bbf806de30
1 file changed
+18 -17
@@ -82,7 +82,7 @@ const RestoreToNewProject = () => {
PermissionAction.INFRA_EXECUTE,
'queue_job.restore.prepare'
)
const hasPITREnabled = cloneBackups?.pitr_enabled
const PITR_ENABLED = cloneBackups?.pitr_enabled
const dbVersion = getDatabaseMajorVersion(project?.dbVersion ?? '')
const IS_PG15_OR_ABOVE = dbVersion >= 15
@@ -100,9 +100,10 @@ const RestoreToNewProject = () => {
refetchInterval,
refetchOnWindowFocus: false,
onSuccess: (data) => {
const hasTransientState = data.clones.some((c) => c.status === 'IN_PROGRESS')
const hasTransientState = data?.clones.some((c) => c.status === 'IN_PROGRESS')
if (!hasTransientState) setRefetchInterval(false)
},
enabled: PHYSICAL_BACKUPS_ENABLED || PITR_ENABLED,
}
)
const IS_CLONED_PROJECT = (cloneStatus?.cloned_from?.source_project as any)?.ref ? true : false
@@ -179,6 +180,16 @@ const RestoreToNewProject = () => {
}
}
if (isFreePlan) {
return (
<UpgradeToPro
buttonText="Upgrade"
primaryText="Restore to a new project requires a pro plan or above."
secondaryText="To restore to a new project, you need to upgrade to a Pro plan and have physical backups enabled."
/>
)
}
if (isOrioleDb) {
return (
<Admonition
@@ -191,10 +202,6 @@ const RestoreToNewProject = () => {
)
}
if (isLoading) {
return <GenericSkeletonLoader />
}
if (!canReadPhysicalBackups) {
return <NoPermission resourceText="view backups" />
}
@@ -243,14 +250,8 @@ const RestoreToNewProject = () => {
)
}
if (plan === 'free') {
return (
<UpgradeToPro
buttonText="Upgrade"
primaryText="Restore to a new project requires a pro plan or above."
secondaryText="To restore to a new project, you need to upgrade to a Pro plan and have physical backups enabled."
/>
)
if (isLoading) {
return <GenericSkeletonLoader />
}
if (IS_CLONED_PROJECT) {
@@ -286,7 +287,7 @@ const RestoreToNewProject = () => {
if (
!isLoading &&
hasPITREnabled &&
PITR_ENABLED &&
!cloneBackups?.physicalBackupData.earliestPhysicalBackupDateUnix
) {
return (
@@ -298,7 +299,7 @@ const RestoreToNewProject = () => {
)
}
if (!isLoading && !hasPITREnabled && cloneBackups?.backups.length === 0) {
if (!isLoading && !PITR_ENABLED && cloneBackups?.backups.length === 0) {
return (
<>
<Admonition
@@ -354,7 +355,7 @@ const RestoreToNewProject = () => {
</Panel>
</div>
) : null}
{hasPITREnabled ? (
{PITR_ENABLED ? (
<>
<PITRForm
disabled={isRestoring}