From 9a8a182c1bda82baf7afd8cb0fe97cb49eaa0621 Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Mon, 19 Aug 2019 17:06:36 +0200 Subject: [PATCH] Fix UserGetter email retrieval with affiliations disabled (#2085) GitOrigin-RevId: f868333f3c18f674b7ba9c387315c2d5ad1fd80b --- services/web/app/src/Features/User/UserGetter.js | 5 +++++ services/web/test/unit/src/User/UserGetterTests.js | 3 +++ 2 files changed, 8 insertions(+) diff --git a/services/web/app/src/Features/User/UserGetter.js b/services/web/app/src/Features/User/UserGetter.js index ec571d3cb8..8e9a9793ae 100644 --- a/services/web/app/src/Features/User/UserGetter.js +++ b/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) diff --git a/services/web/test/unit/src/User/UserGetterTests.js b/services/web/test/unit/src/User/UserGetterTests.js index 5ce23911c9..d89c96f56d 100644 --- a/services/web/test/unit/src/User/UserGetterTests.js +++ b/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 } }))