From a7f816f49abe278fb510d1239720f4ac4b586a72 Mon Sep 17 00:00:00 2001 From: Attiya Ishaque Date: Mon, 20 Mar 2023 10:52:17 +0500 Subject: [PATCH] feat: hide signup page on the bases of flag (#779) --- src/common-components/EnterpriseSSO.jsx | 6 +- src/common-components/Logistration.jsx | 65 +++++++++++++------ src/common-components/messages.jsx | 5 ++ .../tests/Logistration.test.jsx | 36 ++++++++++ src/login/tests/LoginPage.test.jsx | 45 +++++++++++++ 5 files changed, 137 insertions(+), 20 deletions(-) diff --git a/src/common-components/EnterpriseSSO.jsx b/src/common-components/EnterpriseSSO.jsx index 72ae2d43..953edd8a 100644 --- a/src/common-components/EnterpriseSSO.jsx +++ b/src/common-components/EnterpriseSSO.jsx @@ -18,6 +18,7 @@ import messages from './messages'; const EnterpriseSSO = (props) => { const { intl } = props; const tpaProvider = props.provider; + const disablePublicAccountCreation = getConfig().ALLOW_PUBLIC_ACCOUNT_CREATION === false; const handleSubmit = (e, url) => { e.preventDefault(); @@ -64,12 +65,15 @@ const EnterpriseSSO = (props) => {
diff --git a/src/common-components/Logistration.jsx b/src/common-components/Logistration.jsx index 6032bd0b..aef2b8f4 100644 --- a/src/common-components/Logistration.jsx +++ b/src/common-components/Logistration.jsx @@ -33,6 +33,7 @@ const Logistration = (props) => { } = tpaProviders; const [institutionLogin, setInstitutionLogin] = useState(false); const [key, setKey] = useState(''); + const disablePublicAccountCreation = getConfig().ALLOW_PUBLIC_ACCOUNT_CREATION === false; useEffect(() => { const authService = getAuthService(); @@ -79,28 +80,54 @@ const Logistration = (props) => { return (
- {institutionLogin + {disablePublicAccountCreation ? ( - - - - ) - : (!isValidTpaHint() && ( <> - - - - + + {institutionLogin && ( + + + + )} +
+ {!institutionLogin && ( +

{intl.formatMessage(messages['logistration.sign.in'])}

+ )} + +
- ))} - { key && ( - - )} -
- {selectedPage === LOGIN_PAGE - ? - : } -
+ ) + : ( +
+ {institutionLogin + ? ( + + + + ) + : (!isValidTpaHint() && ( + <> + + + + + + ))} + { key && ( + + )} +
+ {selectedPage === LOGIN_PAGE + ? + : ( + + )} +
+
+ )}
); diff --git a/src/common-components/messages.jsx b/src/common-components/messages.jsx index a47166f3..5df3fa74 100644 --- a/src/common-components/messages.jsx +++ b/src/common-components/messages.jsx @@ -29,6 +29,11 @@ const messages = defineMessages({ defaultMessage: 'Show me other ways to sign in or register', description: 'Button text for login', }, + 'enterprisetpa.login.button.text.public.account.creation.disabled': { + id: 'enterprisetpa.login.button.text.public.account.creation.disabled', + defaultMessage: 'Show me other ways to sign in', + description: 'Button text for login when account creation is disabled', + }, // social auth providers 'sso.sign.in.with': { id: 'sso.sign.in.with', diff --git a/src/common-components/tests/Logistration.test.jsx b/src/common-components/tests/Logistration.test.jsx index fb2a6bff..b1eb34d9 100644 --- a/src/common-components/tests/Logistration.test.jsx +++ b/src/common-components/tests/Logistration.test.jsx @@ -52,6 +52,9 @@ describe('Logistration', () => { }); it('should render registration page', () => { + mergeConfig({ + ALLOW_PUBLIC_ACCOUNT_CREATION: true, + }); store = mockStore({ register: { registrationResult: { success: false, redirectUrl: '' }, @@ -88,9 +91,42 @@ describe('Logistration', () => { expect(logistration.find('#main-content').find('LoginPage').exists()).toBeTruthy(); }); + it('should render only login page when public account creation is disabled', () => { + mergeConfig({ + ALLOW_PUBLIC_ACCOUNT_CREATION: false, + DISABLE_ENTERPRISE_LOGIN: 'true', + }); + + store = mockStore({ + login: { + loginResult: { success: false, redirectUrl: '' }, + }, + commonComponents: { + thirdPartyAuthContext: { + currentProvider: null, + finishAuthUrl: null, + providers: [], + secondaryProviders: [secondaryProviders], + }, + thirdPartyAuthApiStatus: COMPLETE_STATE, + }, + }); + + const props = { selectedPage: LOGIN_PAGE }; + const logistration = mount(reduxWrapper()); + + // verifying sign in heading for institution login false + expect(logistration.find('#main-content').find('h3').text()).toEqual('Sign in'); + + // verifying tabs heading for institution login true + logistration.find(RenderInstitutionButton).simulate('click', { institutionLogin: true }); + expect(logistration.find('#controlled-tab').exists()).toBeTruthy(); + }); + it('should display institution login option when secondary providers are present', () => { mergeConfig({ DISABLE_ENTERPRISE_LOGIN: 'true', + ALLOW_PUBLIC_ACCOUNT_CREATION: 'true', }); store = mockStore({ diff --git a/src/login/tests/LoginPage.test.jsx b/src/login/tests/LoginPage.test.jsx index 4c984013..e2398662 100644 --- a/src/login/tests/LoginPage.test.jsx +++ b/src/login/tests/LoginPage.test.jsx @@ -611,6 +611,51 @@ describe('LoginPage', () => { }); }); + it('should render other ways to sign in button', () => { + store = mockStore({ + ...initialState, + commonComponents: { + ...initialState.commonComponents, + thirdPartyAuthContext: { + ...initialState.commonComponents.thirdPartyAuthContext, + providers: [ssoProvider], + }, + thirdPartyAuthApiStatus: COMPLETE_STATE, + }, + }); + + delete window.location; + window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?tpa_hint=${ssoProvider.id}` }; + ssoProvider.iconImage = null; + + const loginPage = mount(reduxWrapper()); + expect(loginPage.find('button#other-ways-to-sign-in').text()).toEqual('Show me other ways to sign in or register'); + }); + + it('should render other ways to sign in button when public account creation disabled', () => { + mergeConfig({ + ALLOW_PUBLIC_ACCOUNT_CREATION: false, + }); + store = mockStore({ + ...initialState, + commonComponents: { + ...initialState.commonComponents, + thirdPartyAuthContext: { + ...initialState.commonComponents.thirdPartyAuthContext, + providers: [ssoProvider], + }, + thirdPartyAuthApiStatus: COMPLETE_STATE, + }, + }); + + delete window.location; + window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?tpa_hint=${ssoProvider.id}` }; + ssoProvider.iconImage = null; + + const loginPage = mount(reduxWrapper()); + expect(loginPage.find('button#other-ways-to-sign-in').text()).toEqual('Show me other ways to sign in'); + }); + // ******** miscellaneous tests ******** it('should render cookie banner', () => {