Просмотр исходного кода

Merge pull request #3718 from overleaf/jel-emailHasLicence

Update emailHasLicence for reconfirmation and SAML

GitOrigin-RevId: 58daf538d9f0a7db46bb3c1e21f8ca04df095446
Thomas 5 лет назад
Родитель
Сommit
1c54a15e42

+ 4 - 0
services/web/app/src/Features/Institutions/InstitutionsHelper.js

@@ -16,6 +16,10 @@ function emailHasLicence(emailData) {
   if (!affiliation.licence) {
   if (!affiliation.licence) {
     return false
     return false
   }
   }
+  if (affiliation.pastReconfirmDate) {
+    return false
+  }
+
   return affiliation.licence !== 'free'
   return affiliation.licence !== 'free'
 }
 }
 
 

+ 0 - 30
services/web/app/src/Features/Subscription/FeaturesUpdater.js

@@ -63,9 +63,6 @@ const FeaturesUpdater = {
       bonusFeatures(cb) {
       bonusFeatures(cb) {
         ReferalFeatures.getBonusFeatures(userId, cb)
         ReferalFeatures.getBonusFeatures(userId, cb)
       },
       },
-      samlFeatures(cb) {
-        FeaturesUpdater._getSamlFeatures(userId, cb)
-      },
       featuresOverrides(cb) {
       featuresOverrides(cb) {
         FeaturesUpdater._getFeaturesOverrides(userId, cb)
         FeaturesUpdater._getFeaturesOverrides(userId, cb)
       }
       }
@@ -88,7 +85,6 @@ const FeaturesUpdater = {
         institutionFeatures,
         institutionFeatures,
         v1Features,
         v1Features,
         bonusFeatures,
         bonusFeatures,
-        samlFeatures,
         featuresOverrides
         featuresOverrides
       } = results
       } = results
       logger.log(
       logger.log(
@@ -99,7 +95,6 @@ const FeaturesUpdater = {
           institutionFeatures,
           institutionFeatures,
           v1Features,
           v1Features,
           bonusFeatures,
           bonusFeatures,
-          samlFeatures,
           featuresOverrides
           featuresOverrides
         },
         },
         'merging user features'
         'merging user features'
@@ -109,7 +104,6 @@ const FeaturesUpdater = {
         institutionFeatures,
         institutionFeatures,
         v1Features,
         v1Features,
         bonusFeatures,
         bonusFeatures,
-        samlFeatures,
         featuresOverrides
         featuresOverrides
       ])
       ])
       const features = _.reduce(
       const features = _.reduce(
@@ -133,30 +127,6 @@ 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) {
   _getFeaturesOverrides(userId, callback) {
     UserGetter.getUser(userId, { featuresOverrides: 1 }, (error, user) => {
     UserGetter.getUser(userId, { featuresOverrides: 1 }, (error, user) => {
       if (error) {
       if (error) {

+ 33 - 19
services/web/test/acceptance/src/UserEmailsTests.js

@@ -1025,11 +1025,12 @@ describe('UserEmails', function() {
         password: userHelper.getDefaultPassword()
         password: userHelper.getDefaultPassword()
       })
       })
       const institutionId = MockV1Api.createInstitution({
       const institutionId = MockV1Api.createInstitution({
+        commonsAccount: true,
         ssoEnabled: false,
         ssoEnabled: false,
         maxConfirmationMonths
         maxConfirmationMonths
       })
       })
       const domain = 'example-affiliation.com'
       const domain = 'example-affiliation.com'
-      MockV1Api.addInstitutionDomain(institutionId, domain)
+      MockV1Api.addInstitutionDomain(institutionId, domain, { confirmed: true })
 
 
       email1 = `leonard@${domain}`
       email1 = `leonard@${domain}`
       email2 = `mccoy@${domain}`
       email2 = `mccoy@${domain}`
@@ -1053,24 +1054,37 @@ describe('UserEmails', 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[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('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)
+        })
       })
       })
 
 
       describe('should flag emails before their confirmation expires, but within the notification period', function() {
       describe('should flag emails before their confirmation expires, but within the notification period', function() {

+ 7 - 1
services/web/test/acceptance/src/mocks/MockV1Api.js

@@ -212,7 +212,13 @@ class MockV1Api extends AbstractMockApi {
 
 
           affiliation.institution.confirmed = !!domainData.confirmed
           affiliation.institution.confirmed = !!domainData.confirmed
 
 
-          if (institutionData.commonsAccount) {
+          affiliation.licence = 'free'
+          if (
+            institutionData.commonsAccount &&
+            (!institutionData.sso_enabled ||
+              (institutionData.sso_enabled &&
+                affiliation.cached_entitlement === true))
+          ) {
             affiliation.licence = 'pro_plus'
             affiliation.licence = 'pro_plus'
           }
           }
           return affiliation
           return affiliation