diff --git a/services/web/frontend/js/features/settings/components/emails/add-email.tsx b/services/web/frontend/js/features/settings/components/emails/add-email.tsx index a530c610c7..f976ecb83e 100644 --- a/services/web/frontend/js/features/settings/components/emails/add-email.tsx +++ b/services/web/frontend/js/features/settings/components/emails/add-email.tsx @@ -264,7 +264,24 @@ function AddEmailViaSSO({ domainInfo: DomainInfo userInstitutions: string[] }) { - if (domainInfo.university.ssoEnabled) { + if ( + domainInfo.group?.domainCaptureEnabled && + domainInfo.group?.managedUsersEnabled + ) { + return ( + + Your company email address has been registered under a verified + domain, and cannot be added as a secondary email. Please create a + new Overleaf account linked to this email address. + + } + /> + ) + } else if (domainInfo.university.ssoEnabled) { // Check if the user has already linked this institution if (userInstitutions.includes(domainInfo.university.id.toString())) { return ( @@ -281,23 +298,6 @@ function AddEmailViaSSO({ ) } return - } else if ( - domainInfo.group?.domainCaptureEnabled && - domainInfo.group?.managedUsersEnabled - ) { - return ( - - Your company email address has been registered under a verified - domain, and cannot be added as a secondary email. Please create a - new Overleaf account linked to this email address. - - } - /> - ) } else if ( domainInfo.group?.domainCaptureEnabled && domainInfo.group?.ssoConfig?.enabled diff --git a/services/web/test/frontend/features/settings/components/emails/emails-section-add-new-email.test.tsx b/services/web/test/frontend/features/settings/components/emails/emails-section-add-new-email.test.tsx index c8093d1834..e98fd26965 100644 --- a/services/web/test/frontend/features/settings/components/emails/emails-section-add-new-email.test.tsx +++ b/services/web/test/frontend/features/settings/components/emails/emails-section-add-new-email.test.tsx @@ -830,8 +830,7 @@ describe('', function () { }) }) - describe('if Commons SSO then enabled, that takes priority over group UI', function () { - // we shouldn't have SSO config in v1 and in v2 but adding test to ensure Commons takes priority + describe('if Commons SSO is enabled and managed users is not enabled, Commons takes priority over group UI', function () { beforeEach(async function () { await fetchMock.callHistory.flush(true) fetchMock.removeRoutes().clearHistory() @@ -874,5 +873,57 @@ describe('', function () { }) }) }) + + describe('if Commons SSO is enabled and managed users is enabled, group domain capture takes priority', function () { + beforeEach(async function () { + await fetchMock.callHistory.flush(true) + fetchMock.removeRoutes().clearHistory() + const institution = { + university: { + id: 1234, + ssoEnabled: true, + name: 'Auto Complete University', + }, + hostname: 'autocomplete.edu', + confirmed: true, + group: { + domainCaptureEnabled: true, + managedUsersEnabled: true, + ssoConfig: { + enabled: true, + }, + }, + } + + fetchMock.get('express:/institutions/domains', [institution]) + }) + + it('renders group domain-capture error instead of Commons UI', async function () { + fetchMock.get('/user/emails?ensureAffiliation=true', []) + render() + + const button = await screen.findByRole('button', { + name: 'Add another email', + }) + + await userEvent.click(button) + + const input = screen.getByRole('textbox', { name: 'Email' }) + fireEvent.change(input, { + target: { value: 'user@autocomplete.edu' }, + }) + + const notification = await screen.findByRole('alert') + within(notification).getByText( + 'Your company email address has been registered under a verified domain, and cannot be added as a secondary email.', + { exact: false } + ) + expect( + screen.queryByRole('button', { + name: 'Link accounts and add email', + }) + ).to.be.null + }) + }) }) })