From 001f7f0cc2d2775ae4631db638e3d8b4b971b5ef Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 15 Mar 2021 16:10:55 +0100 Subject: [PATCH] Merge pull request #3773 from overleaf/revert-3718-jel-emailHasLicence Revert "Update emailHasLicence for reconfirmation and SAML" GitOrigin-RevId: 637b85d10fc0c79e8d55e51b43952e956d73baa6 --- .../Institutions/InstitutionsHelper.js | 4 -- .../Features/Subscription/FeaturesUpdater.js | 30 +++++++++++ .../test/acceptance/src/UserEmailsTests.js | 52 +++++++------------ .../test/acceptance/src/mocks/MockV1Api.js | 8 +-- 4 files changed, 50 insertions(+), 44 deletions(-) diff --git a/services/web/app/src/Features/Institutions/InstitutionsHelper.js b/services/web/app/src/Features/Institutions/InstitutionsHelper.js index a762386018..9b4a72028b 100644 --- a/services/web/app/src/Features/Institutions/InstitutionsHelper.js +++ b/services/web/app/src/Features/Institutions/InstitutionsHelper.js @@ -16,10 +16,6 @@ function emailHasLicence(emailData) { if (!affiliation.licence) { return false } - if (affiliation.pastReconfirmDate) { - return false - } - return affiliation.licence !== 'free' } diff --git a/services/web/app/src/Features/Subscription/FeaturesUpdater.js b/services/web/app/src/Features/Subscription/FeaturesUpdater.js index 4e02a111a7..1823d92404 100644 --- a/services/web/app/src/Features/Subscription/FeaturesUpdater.js +++ b/services/web/app/src/Features/Subscription/FeaturesUpdater.js @@ -63,6 +63,9 @@ const FeaturesUpdater = { bonusFeatures(cb) { ReferalFeatures.getBonusFeatures(userId, cb) }, + samlFeatures(cb) { + FeaturesUpdater._getSamlFeatures(userId, cb) + }, featuresOverrides(cb) { FeaturesUpdater._getFeaturesOverrides(userId, cb) } @@ -85,6 +88,7 @@ const FeaturesUpdater = { institutionFeatures, v1Features, bonusFeatures, + samlFeatures, featuresOverrides } = results logger.log( @@ -95,6 +99,7 @@ const FeaturesUpdater = { institutionFeatures, v1Features, bonusFeatures, + samlFeatures, featuresOverrides }, 'merging user features' @@ -104,6 +109,7 @@ const FeaturesUpdater = { institutionFeatures, v1Features, bonusFeatures, + samlFeatures, featuresOverrides ]) const features = _.reduce( @@ -127,6 +133,30 @@ const FeaturesUpdater = { ) }, + _getSamlFeatures(userId, callback) { + UserGetter.getUser(userId, (err, user) => { + if (err) { + return callback(err) + } + if ( + !user || + !Array.isArray(user.samlIdentifiers) || + !user.samlIdentifiers.length + ) { + return callback(null, {}) + } + for (const samlIdentifier of user.samlIdentifiers) { + if (samlIdentifier && samlIdentifier.hasEntitlement) { + return callback( + null, + FeaturesUpdater._planCodeToFeatures('professional') + ) + } + } + callback(null, {}) + }) + }, + _getFeaturesOverrides(userId, callback) { UserGetter.getUser(userId, { featuresOverrides: 1 }, (error, user) => { if (error) { diff --git a/services/web/test/acceptance/src/UserEmailsTests.js b/services/web/test/acceptance/src/UserEmailsTests.js index 493991d100..8fd041e141 100644 --- a/services/web/test/acceptance/src/UserEmailsTests.js +++ b/services/web/test/acceptance/src/UserEmailsTests.js @@ -1025,12 +1025,11 @@ describe('UserEmails', function() { password: userHelper.getDefaultPassword() }) const institutionId = MockV1Api.createInstitution({ - commonsAccount: true, ssoEnabled: false, maxConfirmationMonths }) const domain = 'example-affiliation.com' - MockV1Api.addInstitutionDomain(institutionId, domain, { confirmed: true }) + MockV1Api.addInstitutionDomain(institutionId, domain) email1 = `leonard@${domain}` email2 = `mccoy@${domain}` @@ -1054,37 +1053,24 @@ describe('UserEmails', function() { ) }) - describe('when all affiliations in notification period or past reconfirm date', function() { - it('should flag inReconfirmNotificationPeriod for all affiliations in period', async function() { - const response = await userHelper.request.get('/user/emails') - expect(response.statusCode).to.equal(200) - const fullEmails = JSON.parse(response.body) - expect(fullEmails.length).to.equal(4) - expect(fullEmails[0].affiliation).to.not.exist - expect( - fullEmails[1].affiliation.inReconfirmNotificationPeriod - ).to.equal(true) - expect( - fullEmails[2].affiliation.inReconfirmNotificationPeriod - ).to.equal(true) - expect( - fullEmails[3].affiliation.inReconfirmNotificationPeriod - ).to.equal(true) - }) - - it('should set pastReconfirmDate and emailHasInstitutionLicence:false for lapsed confirmations', async function() { - const response = await userHelper.request.get('/user/emails') - expect(response.statusCode).to.equal(200) - const fullEmails = JSON.parse(response.body) - expect(fullEmails.length).to.equal(4) - expect(fullEmails[0].affiliation).to.not.exist - expect(fullEmails[1].affiliation.pastReconfirmDate).to.equal(false) - expect(fullEmails[1].emailHasInstitutionLicence).to.equal(true) - expect(fullEmails[2].affiliation.pastReconfirmDate).to.equal(false) - expect(fullEmails[2].emailHasInstitutionLicence).to.equal(true) - expect(fullEmails[3].affiliation.pastReconfirmDate).to.equal(true) - expect(fullEmails[3].emailHasInstitutionLicence).to.equal(false) - }) + it('should flag inReconfirmNotificationPeriod for all affiliations in period', async function() { + const response = await userHelper.request.get('/user/emails') + expect(response.statusCode).to.equal(200) + const fullEmails = JSON.parse(response.body) + expect(fullEmails.length).to.equal(4) + expect(fullEmails[0].affiliation).to.not.exist + expect( + fullEmails[1].affiliation.inReconfirmNotificationPeriod + ).to.equal(true) + expect(fullEmails[1].affiliation.pastReconfirmDate).to.equal(false) + expect( + fullEmails[2].affiliation.inReconfirmNotificationPeriod + ).to.equal(true) + expect(fullEmails[2].affiliation.pastReconfirmDate).to.equal(false) + expect( + fullEmails[3].affiliation.inReconfirmNotificationPeriod + ).to.equal(true) + expect(fullEmails[3].affiliation.pastReconfirmDate).to.equal(true) }) describe('should flag emails before their confirmation expires, but within the notification period', function() { diff --git a/services/web/test/acceptance/src/mocks/MockV1Api.js b/services/web/test/acceptance/src/mocks/MockV1Api.js index 771f622309..4dc56e2295 100644 --- a/services/web/test/acceptance/src/mocks/MockV1Api.js +++ b/services/web/test/acceptance/src/mocks/MockV1Api.js @@ -212,13 +212,7 @@ class MockV1Api extends AbstractMockApi { affiliation.institution.confirmed = !!domainData.confirmed - affiliation.licence = 'free' - if ( - institutionData.commonsAccount && - (!institutionData.sso_enabled || - (institutionData.sso_enabled && - affiliation.cached_entitlement === true)) - ) { + if (institutionData.commonsAccount) { affiliation.licence = 'pro_plus' } return affiliation