From 182713d02db5eb183a26db941b5134058618b7f5 Mon Sep 17 00:00:00 2001 From: Jessica Lawshe <5312836+lawshe@users.noreply.github.com> Date: Wed, 26 Feb 2025 09:18:43 -0600 Subject: [PATCH] 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 --- .../web/app/src/Features/User/UserGetter.js | 23 ++++++++-- .../web/test/unit/src/User/UserGetterTests.js | 44 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/services/web/app/src/Features/User/UserGetter.js b/services/web/app/src/Features/User/UserGetter.js index 4729fea3d3..34d758add6 100644 --- a/services/web/app/src/Features/User/UserGetter.js +++ b/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, diff --git a/services/web/test/unit/src/User/UserGetterTests.js b/services/web/test/unit/src/User/UserGetterTests.js index b7fbe1dc43..67fe233def 100644 --- a/services/web/test/unit/src/User/UserGetterTests.js +++ b/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')