From 64dd54497ca1325eb69c20bb9e13bd35e2e773ea Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 29 Aug 2024 18:36:06 +0700 Subject: [PATCH 1/4] fix: normal user can access workspace upgrade page --- src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx index bb4bdff27097..51b9ada668c0 100644 --- a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx +++ b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx @@ -9,7 +9,7 @@ import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; -import {isControlPolicy} from '@libs/PolicyUtils'; +import * as PolicyUtils from '@libs/PolicyUtils'; import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; import CONST from '@src/CONST'; import * as Policy from '@src/libs/actions/Policy/Policy'; @@ -28,8 +28,9 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { const {translate} = useLocalize(); const [policy] = useOnyx(`policy_${policyID}`); const {isOffline} = useNetwork(); + const shouldShowNotFoundPage = !feature || !policy || !PolicyUtils.isPolicyAdmin(policy) - const isUpgraded = React.useMemo(() => isControlPolicy(policy), [policy]); + const isUpgraded = React.useMemo(() => PolicyUtils.isControlPolicy(policy), [policy]); const upgradeToCorporate = () => { if (!policy || !feature) { @@ -57,7 +58,7 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { useEffect(() => { const unsubscribeListener = navigation.addListener('blur', () => { - if (!isUpgraded) { + if (!isUpgraded || shouldShowNotFoundPage) { return; } confirmUpgrade(); @@ -66,7 +67,7 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { return unsubscribeListener; }, [isUpgraded, confirmUpgrade, navigation]); - if (!feature || !policy) { + if (!feature || !policy || shouldShowNotFoundPage) { return ; } From f1392ac4e8090471f1fcf4a0b85a58340cae4e34 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 30 Aug 2024 00:42:22 +0700 Subject: [PATCH 2/4] fix: lint --- src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx index 51b9ada668c0..0dd61c5d0ba4 100644 --- a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx +++ b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx @@ -28,7 +28,8 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { const {translate} = useLocalize(); const [policy] = useOnyx(`policy_${policyID}`); const {isOffline} = useNetwork(); - const shouldShowNotFoundPage = !feature || !policy || !PolicyUtils.isPolicyAdmin(policy) + // eslint-disable-next-line rulesdir/no-negated-variables + const shouldShowNotFoundPage = !feature || !policy || !PolicyUtils.isPolicyAdmin(policy); const isUpgraded = React.useMemo(() => PolicyUtils.isControlPolicy(policy), [policy]); @@ -65,7 +66,7 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { }); return unsubscribeListener; - }, [isUpgraded, confirmUpgrade, navigation]); + }, [isUpgraded, shouldShowNotFoundPage, confirmUpgrade, navigation]); if (!feature || !policy || shouldShowNotFoundPage) { return ; From 91105c0e0250dceca9d04c5b535704e9ed0d1bcf Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 30 Aug 2024 10:23:36 +0700 Subject: [PATCH 3/4] rename variables --- src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx index 0dd61c5d0ba4..958ab0d0f412 100644 --- a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx +++ b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx @@ -28,13 +28,12 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { const {translate} = useLocalize(); const [policy] = useOnyx(`policy_${policyID}`); const {isOffline} = useNetwork(); - // eslint-disable-next-line rulesdir/no-negated-variables - const shouldShowNotFoundPage = !feature || !policy || !PolicyUtils.isPolicyAdmin(policy); + const canPerformUpgrade = !!feature && !!policy && PolicyUtils.isPolicyAdmin(policy); const isUpgraded = React.useMemo(() => PolicyUtils.isControlPolicy(policy), [policy]); const upgradeToCorporate = () => { - if (!policy || !feature) { + if (!canPerformUpgrade) { return; } @@ -59,16 +58,16 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { useEffect(() => { const unsubscribeListener = navigation.addListener('blur', () => { - if (!isUpgraded || shouldShowNotFoundPage) { + if (!isUpgraded || !canPerformUpgrade) { return; } confirmUpgrade(); }); return unsubscribeListener; - }, [isUpgraded, shouldShowNotFoundPage, confirmUpgrade, navigation]); + }, [isUpgraded, canPerformUpgrade, confirmUpgrade, navigation]); - if (!feature || !policy || shouldShowNotFoundPage) { + if (!canPerformUpgrade) { return ; } From 47456fb3c879935b6708308cb2616a3af9819156 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 30 Aug 2024 17:09:12 +0700 Subject: [PATCH 4/4] prettify --- src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx index 958ab0d0f412..673b77d9c9a1 100644 --- a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx +++ b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx @@ -28,8 +28,8 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { const {translate} = useLocalize(); const [policy] = useOnyx(`policy_${policyID}`); const {isOffline} = useNetwork(); - const canPerformUpgrade = !!feature && !!policy && PolicyUtils.isPolicyAdmin(policy); + const canPerformUpgrade = !!feature && !!policy && PolicyUtils.isPolicyAdmin(policy); const isUpgraded = React.useMemo(() => PolicyUtils.isControlPolicy(policy), [policy]); const upgradeToCorporate = () => {