Merge pull request #3580 from overleaf/jel-dash-pending-license

Get all institutions with inReconfirmNotificationPeriod for dash

GitOrigin-RevId: 904454e5c14f647cc6adc6f7c7b740e64607abc5
This commit is contained in:
Jessica Lawshe 2021-02-02 08:24:42 -06:00 committed by Copybot
parent a31e8a7525
commit ada017a50c
3 changed files with 62 additions and 17 deletions

View file

@ -36,6 +36,7 @@ const BrandVariationsHandler = require('../BrandVariations/BrandVariationsHandle
const { getUserAffiliations } = require('../Institutions/InstitutionsAPI')
const UserController = require('../User/UserController')
const AnalyticsManager = require('../Analytics/AnalyticsManager')
const Modules = require('../../infrastructure/Modules')
const _ssoAvailable = (affiliation, session, linkedInstitutionIds) => {
if (!affiliation.institution) return false
@ -426,6 +427,35 @@ const ProjectController = {
}
cb(error, affiliations)
})
},
userEmailsData(cb) {
const result = { list: [], allInReconfirmNotificationPeriods: [] }
UserGetter.getUserFullEmails(userId, (error, fullEmails) => {
if (error && error instanceof V1ConnectionError) {
noV1Connection = true
return cb(null, result)
}
if (!Features.hasFeature('affiliations')) {
result.list = fullEmails
return cb(null, result)
}
Modules.hooks.fire(
'allInReconfirmNotificationPeriodsForUser',
fullEmails,
(error, results) => {
// Module.hooks.fire accepts multiple methods
// and does async.series
const allInReconfirmNotificationPeriods =
(results && results[0]) || []
return cb(null, {
list: fullEmails,
allInReconfirmNotificationPeriods
})
}
)
})
}
},
(err, results) => {
@ -433,7 +463,15 @@ const ProjectController = {
OError.tag(err, 'error getting data for project list page')
return next(err)
}
const { notifications, user, userAffiliations } = results
const {
notifications,
user,
userAffiliations,
userEmailsData
} = results
const { allInReconfirmNotificationPeriods } = userEmailsData
// Handle case of deleted user
if (user == null) {
UserController.logout(req, res, next)
@ -558,6 +596,7 @@ const ProjectController = {
tags,
notifications: notifications || [],
notificationsInstitution,
allInReconfirmNotificationPeriods,
portalTemplates,
user,
userAffiliations,

View file

@ -292,7 +292,7 @@ class UserHelper {
return userHelper
}
async addEmailAndConfirm(userId, email) {
async addEmail(email) {
let response = await this.request.post({
form: {
email
@ -301,20 +301,11 @@ class UserHelper {
uri: '/user/emails'
})
expect(response.statusCode).to.equal(204)
const token = (
await db.tokens.findOne({
'data.user_id': userId.toString(),
'data.email': email
})
).token
response = await this.request.post({
form: {
token
},
simple: false,
uri: '/user/emails/confirm'
})
expect(response.statusCode).to.equal(200)
}
async addEmailAndConfirm(userId, email) {
await this.addEmail(email)
await this.confirmEmail(userId, email)
}
async backdateConfirmation(userId, email, days) {

View file

@ -98,6 +98,7 @@ describe('ProjectController', function() {
ipMatcherAffiliation: sinon.stub().returns({ create: sinon.stub() })
}
this.UserGetter = {
getUserFullEmails: sinon.stub().yields(null, []),
getUser: sinon
.stub()
.callsArgWith(2, null, { lastLoginIp: '192.170.18.2' })
@ -177,7 +178,10 @@ describe('ProjectController', function() {
},
'../ThirdPartyDataStore/TpdsProjectFlusher': this.TpdsProjectFlusher,
'../../models/Project': {},
'../Analytics/AnalyticsManager': { recordEvent: () => {} }
'../Analytics/AnalyticsManager': { recordEvent: () => {} },
'../../infrastructure/Modules': {
hooks: { fire: sinon.stub().yields(null, []) }
}
}
})
@ -530,6 +534,17 @@ describe('ProjectController', function() {
}
this.ProjectController.projectListPage(this.req, this.res)
})
it('should show a warning when there is an error getting full emails due to v1', function(done) {
this.UserGetter.getUserFullEmails.yields(
new Errors.V1ConnectionError('error')
)
this.res.render = (pageName, opts) => {
expect(opts.warnings).to.contain(this.connectionWarning)
done()
}
this.ProjectController.projectListPage(this.req, this.res)
})
})
describe('front widget', function(done) {