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

Merge pull request #7946 from overleaf/msm-settings-domain-blocklist

[Settings] domain blocklist for email autocompletion

GitOrigin-RevId: 62444f0f903ce3feae585c84c9f01164eac42a1f
Timothée Alby 4 лет назад
Родитель
Сommit
8c611a8f49

+ 4 - 0
services/web/frontend/js/features/settings/components/emails/add-email/input.tsx

@@ -8,6 +8,7 @@ import {
 } from 'react'
 import { getJSON } from '../../../../../infrastructure/fetch-json'
 import useAbortController from '../../../../../shared/hooks/use-abort-controller'
+import domainBlocklist from '../../../domain-blocklist'
 
 const LOCAL_AND_DOMAIN_REGEX = /([^@]+)@(.+)/
 
@@ -91,6 +92,9 @@ function Input({ onChange }: InputProps) {
           if (!(data && data[0])) {
             return
           }
+          if (domainBlocklist.has(data[0].hostname)) {
+            return
+          }
           const hostname = data[0]?.hostname
           if (hostname) {
             domainCache.set(match.domain, data[0])

+ 61 - 0
services/web/frontend/js/features/settings/domain-blocklist.ts

@@ -0,0 +1,61 @@
+const domainBlocklist = new Set(['overleaf.com'])
+const commonTLDs = [
+  'br',
+  'cn',
+  'co',
+  'co.jp',
+  'co.uk',
+  'com',
+  'com.au',
+  'de',
+  'fr',
+  'in',
+  'info',
+  'io',
+  'net',
+  'no',
+  'ru',
+  'se',
+  'us',
+  'com.tw',
+  'com.br',
+  'pl',
+  'it',
+  'co.in',
+  'com.mx',
+] as const
+const commonDomains = [
+  'gmail',
+  'googlemail',
+  'icloud',
+  'me',
+  'yahoo',
+  'ymail',
+  'yahoomail',
+  'hotmail',
+  'live',
+  'msn',
+  'outlook',
+  'gmx',
+  'mail',
+  'aol',
+  '163',
+  'mac',
+  'qq',
+  'o2',
+  'libero',
+  '126',
+  'protonmail',
+  'yandex',
+  'yeah',
+  'web',
+  'foxmail',
+] as const
+
+for (const domain of commonDomains) {
+  for (const tld of commonTLDs) {
+    domainBlocklist.add(`${domain}.${tld}`)
+  }
+}
+
+export default domainBlocklist

+ 17 - 0
services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx

@@ -189,6 +189,23 @@ describe('<AddEmailInput/>', function () {
       })
     })
 
+    describe('when there is a match for a blocklisted domain', function () {
+      beforeEach(function () {
+        const blockedInstitution = [
+          { university: { id: 1 }, hostname: 'overleaf.com' },
+        ]
+        fetchMock.get('express:/institutions/domains', blockedInstitution)
+        fireEvent.change(screen.getByRole('textbox'), {
+          target: { value: 'user@o' },
+        })
+      })
+
+      it('should not render the suggestion', async function () {
+        await fetchMock.flush(true)
+        expect(screen.queryByText('user@overleaf.com')).to.be.null
+      })
+    })
+
     describe('while waiting for a response', function () {
       beforeEach(async function () {
         // type an initial suggestion