Просмотр исходного кода

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
Jessica Lawshe 5 месяцев назад
Родитель
Сommit
0f3ae5ac5b

+ 18 - 18
services/web/frontend/js/features/settings/components/emails/add-email.tsx

@@ -264,24 +264,7 @@ function AddEmailViaSSO({
   domainInfo: DomainInfo
   userInstitutions: string[]
 }) {
-  if (domainInfo.university.ssoEnabled) {
-    // Check if the user has already linked this institution
-    if (userInstitutions.includes(domainInfo.university.id.toString())) {
-      return (
-        <Notification
-          type="error"
-          ariaLive="polite"
-          content={
-            <>
-              This institution is already linked with your account via another
-              email address.
-            </>
-          }
-        />
-      )
-    }
-    return <SsoLinkingInfo email={email} domainInfo={domainInfo} />
-  } else if (
+  if (
     domainInfo.group?.domainCaptureEnabled &&
     domainInfo.group?.managedUsersEnabled
   ) {
@@ -298,6 +281,23 @@ function AddEmailViaSSO({
         }
       />
     )
+  } else if (domainInfo.university.ssoEnabled) {
+    // Check if the user has already linked this institution
+    if (userInstitutions.includes(domainInfo.university.id.toString())) {
+      return (
+        <Notification
+          type="error"
+          ariaLive="polite"
+          content={
+            <>
+              This institution is already linked with your account via another
+              email address.
+            </>
+          }
+        />
+      )
+    }
+    return <SsoLinkingInfo email={email} domainInfo={domainInfo} />
   } else if (
     domainInfo.group?.domainCaptureEnabled &&
     domainInfo.group?.ssoConfig?.enabled

+ 53 - 2
services/web/test/frontend/features/settings/components/emails/emails-section-add-new-email.test.tsx

@@ -830,8 +830,7 @@ describe('<EmailsSection />', 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('<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
+      })
+    })
   })
 })