From c92ab2ef56ad8e714cdc0f67b73e1cb09829197d Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 11 Oct 2023 09:01:05 +0700 Subject: [PATCH 01/13] fix anonymous user can edit profile --- src/libs/Navigation/NavigationRoot.js | 6 ++++++ src/libs/actions/Session/index.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/libs/Navigation/NavigationRoot.js b/src/libs/Navigation/NavigationRoot.js index 34a52adfeca9..d8f083b9c59b 100644 --- a/src/libs/Navigation/NavigationRoot.js +++ b/src/libs/Navigation/NavigationRoot.js @@ -12,6 +12,7 @@ import StatusBar from '../StatusBar'; import useCurrentReportID from '../../hooks/useCurrentReportID'; import useWindowDimensions from '../../hooks/useWindowDimensions'; import {SidebarNavigationContext} from '../../pages/home/sidebar/SidebarNavigationContext'; +import * as Session from '../actions/Session'; // https://reactnavigation.org/docs/themes const navigationTheme = { @@ -133,6 +134,11 @@ function NavigationRoot(props) { // Update the global navigation to show the correct selected menu items. globalNavigation.updateFromNavigationState(state); + + const route = Navigation.getActiveRoute(); + if (Session.isAnonymousUser() && !Session.canAccessRouteByAnonymousUser(route)) { + Session.signOutAndRedirectToSignIn(); + } }; return ( diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 117a092c3875..30c5f3320e08 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -787,6 +787,20 @@ function waitForUserSignIn() { }); } +/** + * check if the route can be accessed by anonymous user + * + * @param {string} route + */ + +const canAccessRouteByAnonymousUser = (route) => { + const reportID = ReportUtils.getReportIDFromLink(route); + if (reportID) { + return true; + } + return false; +}; + export { beginSignIn, beginAppleSignIn, @@ -815,4 +829,5 @@ export { toggleTwoFactorAuth, validateTwoFactorAuth, waitForUserSignIn, + canAccessRouteByAnonymousUser, }; From fa0fc433829dc7e5749a7047ede3851cc3315ab9 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 11 Oct 2023 13:25:01 +0700 Subject: [PATCH 02/13] fix update util function --- src/libs/ReportUtils.js | 1 + src/libs/actions/Session/index.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index b5fc0bff6ec7..ffb34355845f 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3959,4 +3959,5 @@ export { getIOUReportActionDisplayMessage, isWaitingForTaskCompleteFromAssignee, isReportDraft, + parseReportRouteParams }; diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 30c5f3320e08..b52f172f2efa 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -798,6 +798,19 @@ const canAccessRouteByAnonymousUser = (route) => { if (reportID) { return true; } + const parsedReportRouteParams = ReportUtils.parseReportRouteParams(route); + let routeRemovedReportId = route; + if (parsedReportRouteParams.reportID) { + routeRemovedReportId = route.replace(lodashGet(parsedReportRouteParams, 'reportID', ''), ':reportID'); + } + if (route.startsWith('/')) { + routeRemovedReportId = routeRemovedReportId.slice(1); + } + const routesCanAccessByAnonymousUser = [ROUTES.SIGN_IN_MODAL, ROUTES.REPORT_WITH_ID_DETAILS.route, ROUTES.REPORT_WITH_ID_DETAILS_SHARE_CODE.route]; + + if (_.contains(routesCanAccessByAnonymousUser, routeRemovedReportId)) { + return true; + } return false; }; From 78ba2a46d5bfb9f2fce3a22f2c786d9810cd3565 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 11 Oct 2023 14:26:11 +0700 Subject: [PATCH 03/13] fix lint issue --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index ffb34355845f..50df076ba043 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3959,5 +3959,5 @@ export { getIOUReportActionDisplayMessage, isWaitingForTaskCompleteFromAssignee, isReportDraft, - parseReportRouteParams + parseReportRouteParams, }; From 709d48fbab1fce7dfc3936ad3b3a81c8b5a0e1d6 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 13 Oct 2023 13:42:14 +0700 Subject: [PATCH 04/13] fix dissmiss modal login when clicking on back button --- src/pages/signin/SignInModal.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/signin/SignInModal.js b/src/pages/signin/SignInModal.js index f1ce09def084..0ca8fa6838b2 100644 --- a/src/pages/signin/SignInModal.js +++ b/src/pages/signin/SignInModal.js @@ -24,7 +24,11 @@ function SignInModal() { shouldEnableMaxHeight testID={SignInModal.displayName} > - + { + Navigation.dismissModal(); + }} + /> ); From 0d08b325058d0a96f2bb543150d268f786f1a9e4 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 13 Oct 2023 13:45:17 +0700 Subject: [PATCH 05/13] fix refactor code --- src/pages/signin/SignInModal.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/signin/SignInModal.js b/src/pages/signin/SignInModal.js index 0ca8fa6838b2..98bd0692298c 100644 --- a/src/pages/signin/SignInModal.js +++ b/src/pages/signin/SignInModal.js @@ -24,11 +24,7 @@ function SignInModal() { shouldEnableMaxHeight testID={SignInModal.displayName} > - { - Navigation.dismissModal(); - }} - /> + ); From 03af64861ae3e64fc41cfc4c19274b13f51f68af Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 19 Oct 2023 00:56:31 +0700 Subject: [PATCH 06/13] fix sign in modal appear for a second --- src/libs/Navigation/NavigationRoot.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/NavigationRoot.js b/src/libs/Navigation/NavigationRoot.js index a920bfeeca9e..b39e5bbb0d5f 100644 --- a/src/libs/Navigation/NavigationRoot.js +++ b/src/libs/Navigation/NavigationRoot.js @@ -13,6 +13,8 @@ import useCurrentReportID from '../../hooks/useCurrentReportID'; import useWindowDimensions from '../../hooks/useWindowDimensions'; import {SidebarNavigationContext} from '../../pages/home/sidebar/SidebarNavigationContext'; import * as Session from '../actions/Session'; +import getCurrentUrl from './currentUrl'; +import ROUTES from '../../ROUTES'; // https://reactnavigation.org/docs/themes const navigationTheme = { @@ -102,7 +104,7 @@ function NavigationRoot(props) { const animateStatusBarBackgroundColor = () => { const currentRoute = navigationRef.getCurrentRoute(); - const currentScreenBackgroundColor = (currentRoute.params && currentRoute.params.backgroundColor) || themeColors.PAGE_BACKGROUND_COLORS[currentRoute.name] || themeColors.appBG; + const currentScreenBackgroundColor = themeColors.PAGE_BACKGROUND_COLORS[currentRoute.name] || themeColors.appBG; prevStatusBarBackgroundColor.current = statusBarBackgroundColor.current; statusBarBackgroundColor.current = currentScreenBackgroundColor; @@ -136,7 +138,7 @@ function NavigationRoot(props) { globalNavigation.updateFromNavigationState(state); const route = Navigation.getActiveRoute(); - if (Session.isAnonymousUser() && !Session.canAccessRouteByAnonymousUser(route)) { + if (Session.isAnonymousUser() && !Session.canAccessRouteByAnonymousUser(route) && !getCurrentUrl().includes(ROUTES.SIGN_IN_MODAL)) { Session.signOutAndRedirectToSignIn(); } }; From 0ac3e98f814025b0df91c793c1352e94a218f190 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 19 Oct 2023 01:02:12 +0700 Subject: [PATCH 07/13] fix revert unrelated change --- src/libs/Navigation/NavigationRoot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/NavigationRoot.js b/src/libs/Navigation/NavigationRoot.js index b39e5bbb0d5f..a22b6714a306 100644 --- a/src/libs/Navigation/NavigationRoot.js +++ b/src/libs/Navigation/NavigationRoot.js @@ -104,7 +104,7 @@ function NavigationRoot(props) { const animateStatusBarBackgroundColor = () => { const currentRoute = navigationRef.getCurrentRoute(); - const currentScreenBackgroundColor = themeColors.PAGE_BACKGROUND_COLORS[currentRoute.name] || themeColors.appBG; + const currentScreenBackgroundColor = (currentRoute.params && currentRoute.params.backgroundColor) || themeColors.PAGE_BACKGROUND_COLORS[currentRoute.name] || themeColors.appBG; prevStatusBarBackgroundColor.current = statusBarBackgroundColor.current; statusBarBackgroundColor.current = currentScreenBackgroundColor; From ce653159b75e12465402d199712bd2e02e9f4a37 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 20 Oct 2023 14:30:33 +0700 Subject: [PATCH 08/13] fix error when open sign in modal --- .../HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js | 5 +++++ src/libs/Navigation/NavigationRoot.js | 8 -------- src/libs/actions/Report.js | 8 +++++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js b/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js index 92a313cf1e0a..5b15d7014d1f 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js +++ b/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js @@ -15,6 +15,7 @@ import * as Url from '../../../libs/Url'; import ROUTES from '../../../ROUTES'; import tryResolveUrlFromApiRoot from '../../../libs/tryResolveUrlFromApiRoot'; import useEnvironment from '../../../hooks/useEnvironment'; +import * as Session from '../../../libs/actions/Session'; function AnchorRenderer(props) { const htmlAttribs = props.tnode.attributes; @@ -52,6 +53,10 @@ function AnchorRenderer(props) { // If we are handling a New Expensify link then we will assume this should be opened by the app internally. This ensures that the links are opened internally via react-navigation // instead of in a new tab or with a page refresh (which is the default behavior of an anchor tag) if (internalNewExpensifyPath && hasSameOrigin) { + if (Session.isAnonymousUser() && !Session.canAccessRouteByAnonymousUser(internalNewExpensifyPath)) { + Session.signOutAndRedirectToSignIn(); + return; + } Navigation.navigate(internalNewExpensifyPath); return; } diff --git a/src/libs/Navigation/NavigationRoot.js b/src/libs/Navigation/NavigationRoot.js index a22b6714a306..c7a3b14e4fb0 100644 --- a/src/libs/Navigation/NavigationRoot.js +++ b/src/libs/Navigation/NavigationRoot.js @@ -12,9 +12,6 @@ import StatusBar from '../StatusBar'; import useCurrentReportID from '../../hooks/useCurrentReportID'; import useWindowDimensions from '../../hooks/useWindowDimensions'; import {SidebarNavigationContext} from '../../pages/home/sidebar/SidebarNavigationContext'; -import * as Session from '../actions/Session'; -import getCurrentUrl from './currentUrl'; -import ROUTES from '../../ROUTES'; // https://reactnavigation.org/docs/themes const navigationTheme = { @@ -136,11 +133,6 @@ function NavigationRoot(props) { // Update the global navigation to show the correct selected menu items. globalNavigation.updateFromNavigationState(state); - - const route = Navigation.getActiveRoute(); - if (Session.isAnonymousUser() && !Session.canAccessRouteByAnonymousUser(route) && !getCurrentUrl().includes(ROUTES.SIGN_IN_MODAL)) { - Session.signOutAndRedirectToSignIn(); - } }; return ( diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index af1b4a0ac1dd..d3e2f9c749d2 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1909,7 +1909,13 @@ function openReportFromDeepLink(url, isAuthenticated) { InteractionManager.runAfterInteractions(() => { Session.waitForUserSignIn().then(() => { if (route === ROUTES.CONCIERGE) { - navigateToConciergeChat(true); + navigateToConciergeChat(); + return; + } + if (Session.isAnonymousUser() && !Session.canAccessRouteByAnonymousUser(route)) { + Navigation.isNavigationReady().then(() => { + Session.signOutAndRedirectToSignIn(); + }); return; } Navigation.navigate(route, CONST.NAVIGATION.TYPE.PUSH); From ced932a1d2c8af33881b72772bec64293b6a014a Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 20 Oct 2023 14:36:09 +0700 Subject: [PATCH 09/13] fix revert not related changes --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index d3e2f9c749d2..51dcdc49847d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1909,7 +1909,7 @@ function openReportFromDeepLink(url, isAuthenticated) { InteractionManager.runAfterInteractions(() => { Session.waitForUserSignIn().then(() => { if (route === ROUTES.CONCIERGE) { - navigateToConciergeChat(); + navigateToConciergeChat(true); return; } if (Session.isAnonymousUser() && !Session.canAccessRouteByAnonymousUser(route)) { From dfddd3300c375d738e491fe71db1f2cb4d6afadb Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 20 Oct 2023 14:40:30 +0700 Subject: [PATCH 10/13] fix remove not related change --- src/libs/ReportUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 88261a0061ea..011907c2c88b 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4065,6 +4065,5 @@ export { getIOUReportActionDisplayMessage, isWaitingForTaskCompleteFromAssignee, isReportDraft, - parseReportRouteParams, shouldUseFullTitleToDisplay, }; From 70e068d97ded273f504ef06a7e4434242bfc8318 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 25 Oct 2023 19:17:42 +0700 Subject: [PATCH 11/13] fix type error --- src/libs/actions/Session/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 8e4e48480d29..affc75bfcb4b 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -874,22 +874,22 @@ function waitForUserSignIn(): Promise { * @param {string} route */ -const canAccessRouteByAnonymousUser = (route) => { +const canAccessRouteByAnonymousUser = (route: string) => { const reportID = ReportUtils.getReportIDFromLink(route); if (reportID) { return true; } const parsedReportRouteParams = ReportUtils.parseReportRouteParams(route); let routeRemovedReportId = route; - if (parsedReportRouteParams.reportID) { - routeRemovedReportId = route.replace(lodashGet(parsedReportRouteParams, 'reportID', ''), ':reportID'); + if ((parsedReportRouteParams as {reportID: string})?.reportID) { + routeRemovedReportId = route.replace((parsedReportRouteParams as {reportID: string})?.reportID, ':reportID'); } if (route.startsWith('/')) { routeRemovedReportId = routeRemovedReportId.slice(1); } const routesCanAccessByAnonymousUser = [ROUTES.SIGN_IN_MODAL, ROUTES.REPORT_WITH_ID_DETAILS.route, ROUTES.REPORT_WITH_ID_DETAILS_SHARE_CODE.route]; - if (_.contains(routesCanAccessByAnonymousUser, routeRemovedReportId)) { + if ((routesCanAccessByAnonymousUser as string[]).includes(routeRemovedReportId)) { return true; } return false; From 1cb4cc1659e544c6e9eca02a58bd95b306ec820c Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 30 Oct 2023 10:58:57 +0700 Subject: [PATCH 12/13] fix: lint --- .../HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js b/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js index a80be2d00fbf..df9bfac6c821 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js +++ b/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js @@ -14,8 +14,8 @@ import * as Link from '@userActions/Link'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; +import * as Session from '@userActions/Session'; import htmlRendererPropTypes from './htmlRendererPropTypes'; -import * as Session from '../../../libs/actions/Session'; function AnchorRenderer(props) { const htmlAttribs = props.tnode.attributes; From 3ff94514031961ea4c07cc188744b024aeb5c66a Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 30 Oct 2023 11:03:51 +0700 Subject: [PATCH 13/13] fix lint prettier --- .../HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js b/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js index df9bfac6c821..9079a7f3c091 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js +++ b/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js @@ -11,10 +11,10 @@ import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; import * as Url from '@libs/Url'; import styles from '@styles/styles'; import * as Link from '@userActions/Link'; +import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; -import * as Session from '@userActions/Session'; import htmlRendererPropTypes from './htmlRendererPropTypes'; function AnchorRenderer(props) {