mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-15 21:23:14 +00:00
Merge pull request #5802 from overleaf/jel-reconfirm-notification
[web] Extend reconfirmation notification check GitOrigin-RevId: da3785a25b4fa1152a862214af3c17a67f57f10b
This commit is contained in:
parent
cdaf55c7da
commit
8060b5e781
2 changed files with 55 additions and 3 deletions
|
@ -42,7 +42,10 @@ function _pastReconfirmDate(lastDayToReconfirm) {
|
|||
return moment(lastDayToReconfirm).isBefore()
|
||||
}
|
||||
|
||||
function _emailInReconfirmNotificationPeriod(lastDayToReconfirm) {
|
||||
function _emailInReconfirmNotificationPeriod(
|
||||
lastDayToReconfirm,
|
||||
cachedPastReconfirmDate
|
||||
) {
|
||||
const globalReconfirmPeriod = settings.reconfirmNotificationDays
|
||||
|
||||
if (!globalReconfirmPeriod || !lastDayToReconfirm) return false
|
||||
|
@ -52,7 +55,15 @@ function _emailInReconfirmNotificationPeriod(lastDayToReconfirm) {
|
|||
'days'
|
||||
)
|
||||
|
||||
return moment().isAfter(notificationStarts)
|
||||
let inNotificationPeriod = moment().isAfter(notificationStarts)
|
||||
|
||||
if (!inNotificationPeriod && cachedPastReconfirmDate) {
|
||||
// show notification if cached date is past,
|
||||
// even if non-cached date is not past
|
||||
inNotificationPeriod = true
|
||||
}
|
||||
|
||||
return inNotificationPeriod
|
||||
}
|
||||
|
||||
async function getUserFullEmails(userId) {
|
||||
|
@ -224,18 +235,21 @@ const decorateFullEmails = (
|
|||
role,
|
||||
department,
|
||||
licence,
|
||||
past_reconfirm_date: cachedPastReconfirmDate,
|
||||
portal,
|
||||
} = affiliation
|
||||
const lastDayToReconfirm = _lastDayToReconfirm(emailData, institution)
|
||||
const pastReconfirmDate = _pastReconfirmDate(lastDayToReconfirm)
|
||||
const inReconfirmNotificationPeriod = _emailInReconfirmNotificationPeriod(
|
||||
lastDayToReconfirm
|
||||
lastDayToReconfirm,
|
||||
cachedPastReconfirmDate
|
||||
)
|
||||
emailData.affiliation = {
|
||||
institution,
|
||||
inferred,
|
||||
inReconfirmNotificationPeriod,
|
||||
lastDayToReconfirm,
|
||||
cachedPastReconfirmDate,
|
||||
pastReconfirmDate,
|
||||
role,
|
||||
department,
|
||||
|
|
|
@ -181,6 +181,7 @@ describe('UserGetter', function () {
|
|||
isUniversity: true,
|
||||
confirmed: true,
|
||||
},
|
||||
past_reconfirm_date: false,
|
||||
portal: undefined,
|
||||
},
|
||||
]
|
||||
|
@ -204,6 +205,7 @@ describe('UserGetter', function () {
|
|||
lastDayToReconfirm: undefined,
|
||||
licence: affiliationsData[0].licence,
|
||||
inReconfirmNotificationPeriod: false,
|
||||
cachedPastReconfirmDate: false,
|
||||
pastReconfirmDate: false,
|
||||
portal: undefined,
|
||||
},
|
||||
|
@ -796,6 +798,42 @@ describe('UserGetter', function () {
|
|||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('should flag to show notification if v1 shows as past reconfirmation but v2 does not', function (done) {
|
||||
const email = 'abc123@test.com'
|
||||
const confirmedAt = new Date()
|
||||
const affiliationsData = [
|
||||
{
|
||||
email,
|
||||
licence: 'free',
|
||||
institution: institutionNonSSO,
|
||||
past_reconfirm_date: true,
|
||||
},
|
||||
]
|
||||
const user = {
|
||||
_id: '12390i',
|
||||
email,
|
||||
emails: [
|
||||
{
|
||||
email,
|
||||
confirmedAt,
|
||||
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()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue