Merge pull request #33335 from overleaf/jel-add-email-captured-by-group

[web] Group with domain capture takes priority over Commons when adding new email

GitOrigin-RevId: 40eb561018f4be0badf9f3885d24553c5f8bbde7
This commit is contained in:
Jessica Lawshe
2026-05-11 10:04:49 -05:00
committed by Copybot
parent ba13ccdb11
commit 0f3ae5ac5b
2 changed files with 71 additions and 20 deletions

View File

@@ -264,7 +264,24 @@ function AddEmailViaSSO({
domainInfo: DomainInfo domainInfo: DomainInfo
userInstitutions: string[] userInstitutions: string[]
}) { }) {
if (domainInfo.university.ssoEnabled) { if (
domainInfo.group?.domainCaptureEnabled &&
domainInfo.group?.managedUsersEnabled
) {
return (
<Notification
type="error"
ariaLive="polite"
content={
<>
Your company email address has been registered under a verified
domain, and cannot be added as a secondary email. Please create a
new <strong>Overleaf</strong> account linked to this email address.
</>
}
/>
)
} else if (domainInfo.university.ssoEnabled) {
// Check if the user has already linked this institution // Check if the user has already linked this institution
if (userInstitutions.includes(domainInfo.university.id.toString())) { if (userInstitutions.includes(domainInfo.university.id.toString())) {
return ( return (
@@ -281,23 +298,6 @@ function AddEmailViaSSO({
) )
} }
return <SsoLinkingInfo email={email} domainInfo={domainInfo} /> return <SsoLinkingInfo email={email} domainInfo={domainInfo} />
} else if (
domainInfo.group?.domainCaptureEnabled &&
domainInfo.group?.managedUsersEnabled
) {
return (
<Notification
type="error"
ariaLive="polite"
content={
<>
Your company email address has been registered under a verified
domain, and cannot be added as a secondary email. Please create a
new <strong>Overleaf</strong> account linked to this email address.
</>
}
/>
)
} else if ( } else if (
domainInfo.group?.domainCaptureEnabled && domainInfo.group?.domainCaptureEnabled &&
domainInfo.group?.ssoConfig?.enabled domainInfo.group?.ssoConfig?.enabled

View File

@@ -830,8 +830,7 @@ describe('<EmailsSection />', function () {
}) })
}) })
describe('if Commons SSO then enabled, that takes priority over group UI', function () { describe('if Commons SSO is enabled and managed users is not enabled, Commons 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
beforeEach(async function () { beforeEach(async function () {
await fetchMock.callHistory.flush(true) await fetchMock.callHistory.flush(true)
fetchMock.removeRoutes().clearHistory() fetchMock.removeRoutes().clearHistory()
@@ -874,5 +873,57 @@ describe('<EmailsSection />', 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(<EmailsSection />)
const button = await screen.findByRole<HTMLButtonElement>('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
})
})
}) })
}) })