From c19285d1a851fa0b62759f336214a94954ce82cc Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Wed, 18 Oct 2023 00:11:48 +0700 Subject: [PATCH 1/2] hide saml changes behind beta --- src/libs/Permissions.ts | 5 +++++ src/pages/signin/SignInPage.js | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 13489c396c3c..139791721642 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -50,6 +50,10 @@ function canUseTags(betas: Beta[]): boolean { return betas?.includes(CONST.BETAS.NEW_DOT_TAGS) || canUseAllBetas(betas); } +function canUseSAML(betas: Beta[]): boolean { + return betas?.includes(CONST.BETAS.NEW_DOT_SAML) || canUseAllBetas(betas); +} + /** * Link previews are temporarily disabled. */ @@ -68,5 +72,6 @@ export default { canUseCustomStatus, canUseCategories, canUseTags, + canUseSAML, canUseLinkPreviews, }; diff --git a/src/pages/signin/SignInPage.js b/src/pages/signin/SignInPage.js index 8aae45c279c6..33566cf85f8d 100644 --- a/src/pages/signin/SignInPage.js +++ b/src/pages/signin/SignInPage.js @@ -26,6 +26,7 @@ import ROUTES from '../../ROUTES'; import ChooseSSOOrMagicCode from './ChooseSSOOrMagicCode'; import * as ActiveClientManager from '../../libs/ActiveClientManager'; import * as Session from '../../libs/actions/Session'; +import Permissions from '../../libs/Permissions'; const propTypes = { /** The details about the account that the user is signing in with */ @@ -87,9 +88,10 @@ const defaultProps = { * @param {Boolean} isUsingMagicCode * @param {Boolean} hasInitiatedSAMLLogin * @param {Boolean} hasEmailDeliveryFailure + * @param {Array} betas * @returns {Object} */ -function getRenderOptions({hasLogin, hasValidateCode, account, isPrimaryLogin, isUsingMagicCode, hasInitiatedSAMLLogin, isClientTheLeader}) { +function getRenderOptions({hasLogin, hasValidateCode, account, isPrimaryLogin, isUsingMagicCode, hasInitiatedSAMLLogin, isClientTheLeader, betas}) { const hasAccount = !_.isEmpty(account); const isSAMLEnabled = Boolean(account.isSAMLEnabled); const isSAMLRequired = Boolean(account.isSAMLRequired); @@ -99,7 +101,7 @@ function getRenderOptions({hasLogin, hasValidateCode, account, isPrimaryLogin, i let shouldShowChooseSSOOrMagicCode = false; let shouldInitiateSAMLLogin = false; const platform = getPlatform(); - if (platform === CONST.PLATFORM.WEB || platform === CONST.PLATFORM.DESKTOP) { + if (Permissions.canUseSAML(betas) && (platform === CONST.PLATFORM.WEB || platform === CONST.PLATFORM.DESKTOP)) { // True if the user has SAML required and we haven't already initiated SAML for their account shouldInitiateSAMLLogin = hasAccount && hasLogin && isSAMLRequired && !hasInitiatedSAMLLogin && account.isLoading; shouldShowChooseSSOOrMagicCode = hasAccount && hasLogin && isSAMLEnabled && !isSAMLRequired && !isUsingMagicCode; @@ -108,7 +110,7 @@ function getRenderOptions({hasLogin, hasValidateCode, account, isPrimaryLogin, i // SAML required users may reload the login page after having already entered their login details, in which // case we want to clear their sign in data so they don't end up in an infinite loop redirecting back to their // SSO provider's login page - if (hasLogin && isSAMLRequired && !shouldInitiateSAMLLogin && !hasInitiatedSAMLLogin && !account.isLoading) { + if (Permissions.canUseSAML(betas) && hasLogin && isSAMLRequired && !shouldInitiateSAMLLogin && !hasInitiatedSAMLLogin && !account.isLoading) { Session.clearSignInData(); } @@ -131,7 +133,7 @@ function getRenderOptions({hasLogin, hasValidateCode, account, isPrimaryLogin, i }; } -function SignInPage({credentials, account, isInModal, activeClients}) { +function SignInPage({credentials, account, isInModal, activeClients, betas}) { const {translate, formatPhoneNumber} = useLocalize(); const {isSmallScreenWidth} = useWindowDimensions(); const shouldShowSmallScreen = isSmallScreenWidth || isInModal; @@ -173,9 +175,10 @@ function SignInPage({credentials, account, isInModal, activeClients}) { isUsingMagicCode, hasInitiatedSAMLLogin, isClientTheLeader, + betas, }); - if (shouldInitiateSAMLLogin) { + if (Permissions.canUseSAML(betas) && shouldInitiateSAMLLogin) { setHasInitiatedSAMLLogin(true); Navigation.isNavigationReady().then(() => Navigation.navigate(ROUTES.SAML_SIGN_IN)); } @@ -273,4 +276,5 @@ export default withOnyx({ We use that function to prevent repeating code that checks which client is the leader. */ activeClients: {key: ONYXKEYS.ACTIVE_CLIENTS}, + betas: {key: ONYXKEYS.BETAS}, })(SignInPage); From a941463d60c24b3ea893c8c9bc915cf0ddc33557 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Wed, 18 Oct 2023 00:22:25 +0700 Subject: [PATCH 2/2] props validation --- src/pages/signin/SignInPage.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/signin/SignInPage.js b/src/pages/signin/SignInPage.js index 33566cf85f8d..96c6c65a67c9 100644 --- a/src/pages/signin/SignInPage.js +++ b/src/pages/signin/SignInPage.js @@ -71,6 +71,9 @@ const propTypes = { /** Whether or not the sign in page is being rendered in the RHP modal */ isInModal: PropTypes.bool, + + /** List of betas available to current user */ + betas: PropTypes.arrayOf(PropTypes.string), }; const defaultProps = { @@ -78,6 +81,7 @@ const defaultProps = { credentials: {}, isInModal: false, activeClients: [], + betas: [], }; /**