From c04e7f58c016ca630005e38545e3e0a284ba0aca Mon Sep 17 00:00:00 2001 From: Moncef Abboud Date: Mon, 2 Oct 2023 11:54:44 +0200 Subject: [PATCH] feat: implement SHOW_REGISTRATION_LINKS setting --- src/common-components/EnterpriseSSO.jsx | 5 +++-- src/logistration/Logistration.jsx | 8 +++++++- src/logistration/Logistration.test.jsx | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/common-components/EnterpriseSSO.jsx b/src/common-components/EnterpriseSSO.jsx index 4bfc5ae33b..f6b206bbe9 100644 --- a/src/common-components/EnterpriseSSO.jsx +++ b/src/common-components/EnterpriseSSO.jsx @@ -19,7 +19,8 @@ import { LOGIN_PAGE, SUPPORTED_ICON_CLASSES } from '../data/constants'; const EnterpriseSSO = (props) => { const { formatMessage } = useIntl(); const tpaProvider = props.provider; - const disablePublicAccountCreation = getConfig().ALLOW_PUBLIC_ACCOUNT_CREATION === false; + const hideRegistrationLink = getConfig().ALLOW_PUBLIC_ACCOUNT_CREATION === false + || getConfig().SHOW_REGISTRATION_LINKS === false; const handleSubmit = (e, url) => { e.preventDefault(); @@ -74,7 +75,7 @@ const EnterpriseSSO = (props) => { className="w-100" onClick={(e) => handleClick(e)} > - {disablePublicAccountCreation + {hideRegistrationLink ? formatMessage(messages['enterprisetpa.login.button.text.public.account.creation.disabled']) : formatMessage(messages['enterprisetpa.login.button.text'])} diff --git a/src/logistration/Logistration.jsx b/src/logistration/Logistration.jsx index 7c6d77ff0b..5091531855 100644 --- a/src/logistration/Logistration.jsx +++ b/src/logistration/Logistration.jsx @@ -39,6 +39,7 @@ const Logistration = (props) => { const [key, setKey] = useState(''); const navigate = useNavigate(); const disablePublicAccountCreation = getConfig().ALLOW_PUBLIC_ACCOUNT_CREATION === false; + const hideRegistrationLink = getConfig().SHOW_REGISTRATION_LINKS === false; useEffect(() => { const authService = getAuthService(); @@ -116,7 +117,7 @@ const Logistration = (props) => { ) - : (!isValidTpaHint() && ( + : (!isValidTpaHint() && !hideRegistrationLink && ( @@ -126,6 +127,11 @@ const Logistration = (props) => { )}
+ {!institutionLogin && !isValidTpaHint() && hideRegistrationLink && ( +

+ {formatMessage(messages[selectedPage === LOGIN_PAGE ? 'logistration.sign.in' : 'logistration.register'])} +

+ )} {selectedPage === LOGIN_PAGE ? : ( diff --git a/src/logistration/Logistration.test.jsx b/src/logistration/Logistration.test.jsx index 886ca53313..b63735f64c 100644 --- a/src/logistration/Logistration.test.jsx +++ b/src/logistration/Logistration.test.jsx @@ -12,7 +12,7 @@ import Logistration from './Logistration'; import { clearThirdPartyAuthContextErrorMessage } from '../common-components/data/actions'; import { RenderInstitutionButton } from '../common-components/InstitutionLogistration'; import { - COMPLETE_STATE, LOGIN_PAGE, + COMPLETE_STATE, LOGIN_PAGE, REGISTER_PAGE, } from '../data/constants'; import { backupRegistrationForm } from '../register/data/actions'; @@ -111,10 +111,31 @@ describe('Logistration', () => { expect(logistration.find('#main-content').find('LoginPage').exists()).toBeTruthy(); }); + it('should render login/register headings when show registration links is disabled', () => { + mergeConfig({ + SHOW_REGISTRATION_LINKS: false, + }); + + let props = { selectedPage: LOGIN_PAGE }; + let logistration = mount(reduxWrapper()); + + // verifying sign in heading + expect(logistration.find('#main-content').find('h3').text()).toEqual('Sign in'); + + // register page is still accessible when SHOW_REGISTRATION_LINKS is false + // but it needs to be accessed directly + props = { selectedPage: REGISTER_PAGE }; + logistration = mount(reduxWrapper()); + + // verifying register heading + expect(logistration.find('#main-content').find('h3').text()).toEqual('Register'); + }); + it('should render only login page when public account creation is disabled', () => { mergeConfig({ ALLOW_PUBLIC_ACCOUNT_CREATION: false, DISABLE_ENTERPRISE_LOGIN: 'true', + SHOW_REGISTRATION_LINKS: 'true', }); store = mockStore({