From ada017a50c65594ed9e83f8c7898631efb068bdc Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Tue, 2 Feb 2021 08:24:42 -0600 Subject: [PATCH] Merge pull request #3580 from overleaf/jel-dash-pending-license Get all institutions with inReconfirmNotificationPeriod for dash GitOrigin-RevId: 904454e5c14f647cc6adc6f7c7b740e64607abc5 --- .../src/Features/Project/ProjectController.js | 41 ++++++++++++++++++- .../test/acceptance/src/helpers/UserHelper.js | 21 +++------- .../src/Project/ProjectControllerTests.js | 17 +++++++- 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/services/web/app/src/Features/Project/ProjectController.js b/services/web/app/src/Features/Project/ProjectController.js index 2571318b16..29e13c98b6 100644 --- a/services/web/app/src/Features/Project/ProjectController.js +++ b/services/web/app/src/Features/Project/ProjectController.js @@ -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, diff --git a/services/web/test/acceptance/src/helpers/UserHelper.js b/services/web/test/acceptance/src/helpers/UserHelper.js index d48aed649d..9c464bc097 100644 --- a/services/web/test/acceptance/src/helpers/UserHelper.js +++ b/services/web/test/acceptance/src/helpers/UserHelper.js @@ -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) { diff --git a/services/web/test/unit/src/Project/ProjectControllerTests.js b/services/web/test/unit/src/Project/ProjectControllerTests.js index 417a627302..aff2fb7609 100644 --- a/services/web/test/unit/src/Project/ProjectControllerTests.js +++ b/services/web/test/unit/src/Project/ProjectControllerTests.js @@ -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) {