Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SAML NewDot][CP Staging] Hide SAML changes behind beta #29798

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/libs/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -68,5 +72,6 @@ export default {
canUseCustomStatus,
canUseCategories,
canUseTags,
canUseSAML,
canUseLinkPreviews,
};
18 changes: 13 additions & 5 deletions src/pages/signin/SignInPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -70,13 +71,17 @@ 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 = {
account: {},
credentials: {},
isInModal: false,
activeClients: [],
betas: [],
};

/**
Expand All @@ -87,9 +92,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);
Expand All @@ -99,7 +105,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;
Expand All @@ -108,7 +114,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();
}

Expand All @@ -131,7 +137,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;
Expand Down Expand Up @@ -173,9 +179,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));
}
Expand Down Expand Up @@ -273,4 +280,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},
Copy link
Contributor

@francoisl francoisl Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use withBetas() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only see src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js using it that was atm

})(SignInPage);
Loading