From fc9bfa84cde86f3281481dfd2addbfc45cd1161c Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Mon, 23 May 2022 08:43:01 -0500 Subject: [PATCH] Merge pull request #7721 from overleaf/jel-td-notify-commons Only handle confirmed users via commons script GitOrigin-RevId: 0d00147943228bff6c435848ff88481c5c184a8a --- .../app/src/Features/Institutions/InstitutionsAPI.js | 12 ++++++++++++ .../src/Features/Institutions/InstitutionsManager.js | 6 ++++-- .../src/Institutions/InstitutionsManagerTests.js | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/services/web/app/src/Features/Institutions/InstitutionsAPI.js b/services/web/app/src/Features/Institutions/InstitutionsAPI.js index b0786b52af..ca8dd4450c 100644 --- a/services/web/app/src/Features/Institutions/InstitutionsAPI.js +++ b/services/web/app/src/Features/Institutions/InstitutionsAPI.js @@ -22,6 +22,17 @@ const InstitutionsAPI = { ) }, + getConfirmedInstitutionAffiliations(institutionId, callback) { + makeAffiliationRequest( + { + method: 'GET', + path: `/api/v2/institutions/${institutionId.toString()}/confirmed_affiliations`, + defaultErrorMessage: "Couldn't get institution affiliations", + }, + (error, body) => callback(error, body || []) + ) + }, + getInstitutionAffiliationsCounts(institutionId, callback) { makeAffiliationRequest( { @@ -267,6 +278,7 @@ function makeAffiliationRequest(options, callback) { } ;[ 'getInstitutionAffiliations', + 'getConfirmedInstitutionAffiliations', 'getUserAffiliations', 'addAffiliation', 'removeAffiliation', diff --git a/services/web/app/src/Features/Institutions/InstitutionsManager.js b/services/web/app/src/Features/Institutions/InstitutionsManager.js index 7b44f0790b..943fb7e296 100644 --- a/services/web/app/src/Features/Institutions/InstitutionsManager.js +++ b/services/web/app/src/Features/Institutions/InstitutionsManager.js @@ -4,6 +4,7 @@ const { ObjectId } = require('mongodb') const Settings = require('@overleaf/settings') const { getInstitutionAffiliations, + getConfirmedInstitutionAffiliations, promises: InstitutionsAPIPromises, } = require('./InstitutionsAPI') const FeaturesUpdater = require('../Subscription/FeaturesUpdater') @@ -261,8 +262,9 @@ const fetchInstitutionAndAffiliations = (institutionId, callback) => (institution, cb) => institution.fetchV1Data((err, institution) => cb(err, institution)), (institution, cb) => - getInstitutionAffiliations(institutionId, (err, affiliations) => - cb(err, institution, affiliations) + getConfirmedInstitutionAffiliations( + institutionId, + (err, affiliations) => cb(err, institution, affiliations) ), ], callback diff --git a/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js b/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js index 814352d3b5..d38242335a 100644 --- a/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js +++ b/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js @@ -13,6 +13,7 @@ describe('InstitutionsManager', function () { this.institutionId = 123 this.user = {} this.getInstitutionAffiliations = sinon.stub() + this.getConfirmedInstitutionAffiliations = sinon.stub() this.refreshFeatures = sinon.stub().yields() this.users = [ { _id: 'lapsed', features: {} }, @@ -95,11 +96,17 @@ describe('InstitutionsManager', function () { requires: { './InstitutionsAPI': { getInstitutionAffiliations: this.getInstitutionAffiliations, + getConfirmedInstitutionAffiliations: + this.getConfirmedInstitutionAffiliations, promises: { getInstitutionAffiliations: (this.getInstitutionAffiliationsPromise = sinon .stub() .resolves(this.affiliations)), + getConfirmedInstitutionAffiliations: + (this.getConfirmedInstitutionAffiliationsPromise = sinon + .stub() + .resolves(this.affiliations)), getInstitutionAffiliationsCounts: (this.getInstitutionAffiliationsCounts = sinon .stub() @@ -173,6 +180,7 @@ describe('InstitutionsManager', function () { this.refreshFeatures.withArgs(this.user1Id).yields(null, {}, true) this.getInstitutionAffiliations.yields(null, this.affiliations) + this.getConfirmedInstitutionAffiliations.yields(null, this.affiliations) }) it('refresh all users Features', function (done) {