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

Merge pull request #23890 from overleaf/jel-reconfirm-date

[web] If v1 date doesn't show as reconfirmed, ensure v2 does not as well

GitOrigin-RevId: dc2850221a2d9176023380b38508311ea98abe43
Jessica Lawshe 1 год назад
Родитель
Сommit
182713d02d

+ 20 - 3
services/web/app/src/Features/User/UserGetter.js

@@ -40,7 +40,10 @@ function _pastReconfirmDate(lastDayToReconfirm) {
   return moment(lastDayToReconfirm).isBefore()
 }
 
-function _emailInReconfirmNotificationPeriod(cachedLastDayToReconfirm) {
+function _emailInReconfirmNotificationPeriod(
+  cachedLastDayToReconfirm,
+  lastDayToReconfirm
+) {
   const globalReconfirmPeriod = settings.reconfirmNotificationDays
 
   if (!globalReconfirmPeriod || !cachedLastDayToReconfirm) return false
@@ -50,7 +53,20 @@ function _emailInReconfirmNotificationPeriod(cachedLastDayToReconfirm) {
     'days'
   )
 
-  return moment().isAfter(notificationStarts)
+  let isInNotificationPeriod = moment().isAfter(notificationStarts)
+
+  if (!isInNotificationPeriod) {
+    // for possible issues in v1/v2 date mismatch, ensure v2 date doesn't show as needing to reconfirm
+
+    const notificationStartsV2 = moment(lastDayToReconfirm).subtract(
+      globalReconfirmPeriod,
+      'days'
+    )
+
+    isInNotificationPeriod = moment().isAfter(notificationStartsV2)
+  }
+
+  return isInNotificationPeriod
 }
 
 async function getUserFullEmails(userId) {
@@ -279,7 +295,8 @@ const decorateFullEmails = (
       }
       const pastReconfirmDate = _pastReconfirmDate(lastDayToReconfirm)
       const inReconfirmNotificationPeriod = _emailInReconfirmNotificationPeriod(
-        cachedLastDayToReconfirm
+        cachedLastDayToReconfirm,
+        lastDayToReconfirm
       )
       emailData.affiliation = {
         institution,

+ 44 - 0
services/web/test/unit/src/User/UserGetterTests.js

@@ -946,6 +946,50 @@ describe('UserGetter', function () {
         )
       })
 
+      it('should flag to show notification if v2 shows as reconfirmation upcoming but v1 does not', function (done) {
+        const email = 'abc123@test.com'
+        const { maxConfirmationMonths } = institutionNonSSO
+
+        const datePastReconfirmation = moment()
+          .subtract(maxConfirmationMonths, 'months')
+          .add(3, 'day')
+          .toDate()
+
+        const dateNotPastReconfirmation = moment().add(1, 'month').toDate()
+
+        const affiliationsData = [
+          {
+            email,
+            licence: 'free',
+            institution: institutionNonSSO,
+            last_day_to_reconfirm: dateNotPastReconfirmation,
+          },
+        ]
+        const user = {
+          _id: '12390i',
+          email,
+          emails: [
+            {
+              email,
+              confirmedAt: datePastReconfirmation,
+              default: true,
+            },
+          ],
+        }
+        this.getUserAffiliations.resolves(affiliationsData)
+        this.UserGetter.promises.getUser = sinon.stub().resolves(user)
+        this.UserGetter.getUserFullEmails(
+          this.fakeUser._id,
+          (error, fullEmails) => {
+            expect(error).to.not.exist
+            expect(
+              fullEmails[0].affiliation.inReconfirmNotificationPeriod
+            ).to.equal(true)
+            done()
+          }
+        )
+      })
+
       describe('cachedLastDayToReconfirm', function () {
         const email = 'abc123@test.com'
         const confirmedAt = new Date('2019-07-11T18:25:01.639Z')