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

Fix UserGetter email retrieval with affiliations disabled (#2085)

GitOrigin-RevId: f868333f3c18f674b7ba9c387315c2d5ad1fd80b
Miguel Serrano 7 лет назад
Родитель
Сommit
9a8a182c1b

+ 5 - 0
services/web/app/src/Features/User/UserGetter.js

@@ -19,6 +19,7 @@ const { db } = mongojs
 const { ObjectId } = mongojs
 const { getUserAffiliations } = require('../Institutions/InstitutionsAPI')
 const Errors = require('../Errors/Errors')
+const Features = require('../../infrastructure/Features')
 
 module.exports = UserGetter = {
   getUser(query, projection, callback) {
@@ -66,6 +67,10 @@ module.exports = UserGetter = {
         return callback(new Error('User not Found'))
       }
 
+      if (!Features.hasFeature('affiliations')) {
+        return callback(null, decorateFullEmails(user.email, user.emails, []))
+      }
+
       return getUserAffiliations(userId, function(error, affiliationsData) {
         if (error != null) {
           return callback(error)

+ 3 - 0
services/web/test/unit/src/User/UserGetterTests.js

@@ -63,6 +63,9 @@ describe('UserGetter', function() {
         '../Institutions/InstitutionsAPI': {
           getUserAffiliations: this.getUserAffiliations
         },
+        '../../infrastructure/Features': {
+          hasFeature: sinon.stub().returns(true)
+        },
         '../Errors/Errors': Errors
       }
     }))