diff --git a/services/web/app/src/Features/Institutions/InstitutionsController.js b/services/web/app/src/Features/Institutions/InstitutionsController.js index 6621e0af19..6e1b2dc479 100644 --- a/services/web/app/src/Features/Institutions/InstitutionsController.js +++ b/services/web/app/src/Features/Institutions/InstitutionsController.js @@ -85,7 +85,7 @@ var affiliateUserByReversedHostname = function( ) return innerCallback(error) } - return FeaturesUpdater.refreshFeatures(user._id, true, innerCallback) + return FeaturesUpdater.refreshFeatures(user._id, innerCallback) } ), callback diff --git a/services/web/app/src/Features/Institutions/InstitutionsManager.js b/services/web/app/src/Features/Institutions/InstitutionsManager.js index b2597cca5e..114292354b 100644 --- a/services/web/app/src/Features/Institutions/InstitutionsManager.js +++ b/services/web/app/src/Features/Institutions/InstitutionsManager.js @@ -114,7 +114,6 @@ var refreshFeatures = function(affiliation, callback) { cb => FeaturesUpdater.refreshFeatures( userId, - true, (err, features, featuresChanged) => cb(err, featuresChanged) ), (featuresChanged, cb) => diff --git a/services/web/app/src/Features/Subscription/FeaturesUpdater.js b/services/web/app/src/Features/Subscription/FeaturesUpdater.js index 00f1bfc0db..353670e293 100644 --- a/services/web/app/src/Features/Subscription/FeaturesUpdater.js +++ b/services/web/app/src/Features/Subscription/FeaturesUpdater.js @@ -27,28 +27,10 @@ const InstitutionsFeatures = require('../Institutions/InstitutionsFeatures') const oneMonthInSeconds = 60 * 60 * 24 * 30 module.exports = FeaturesUpdater = { - refreshFeatures(user_id, notifyV1, callback) { - if (notifyV1 == null) { - notifyV1 = true - } + refreshFeatures(user_id, callback) { if (callback == null) { callback = function(error, features, featuresChanged) {} } - if (typeof notifyV1 === 'function') { - callback = notifyV1 - notifyV1 = true - } - - if (notifyV1) { - V1SubscriptionManager.notifyV1OfFeaturesChange(user_id, function(error) { - if (error != null) { - return logger.err( - { err: error, user_id }, - 'error notifying v1 about updated features' - ) - } - }) - } const jobs = { individualFeatures(cb) { diff --git a/services/web/app/src/Features/Subscription/V1SubscriptionManager.js b/services/web/app/src/Features/Subscription/V1SubscriptionManager.js index 1b3025c490..3602e2c93b 100644 --- a/services/web/app/src/Features/Subscription/V1SubscriptionManager.js +++ b/services/web/app/src/Features/Subscription/V1SubscriptionManager.js @@ -58,22 +58,6 @@ module.exports = V1SubscriptionManager = { ) }, - notifyV1OfFeaturesChange(userId, callback) { - if (callback == null) { - callback = function(error) {} - } - return V1SubscriptionManager._v1Request( - userId, - { - method: 'POST', - url(v1Id) { - return `/api/v1/sharelatex/users/${v1Id}/sync` - } - }, - callback - ) - }, - getSubscriptionsFromV1(userId, callback) { if (callback == null) { callback = function(err, subscriptions, v1Id) {} diff --git a/services/web/app/src/Features/User/UserUpdater.js b/services/web/app/src/Features/User/UserUpdater.js index be89632d6b..50d2850889 100644 --- a/services/web/app/src/Features/User/UserUpdater.js +++ b/services/web/app/src/Features/User/UserUpdater.js @@ -303,7 +303,7 @@ module.exports = UserUpdater = { new Errors.NotFoundError('user id and email do no match') ) } - return FeaturesUpdater.refreshFeatures(userId, true, callback) + return FeaturesUpdater.refreshFeatures(userId, callback) }) }) }, diff --git a/services/web/scripts/sync_v1_subscriptions.js b/services/web/scripts/sync_v1_subscriptions.js deleted file mode 100644 index fa8c45366c..0000000000 --- a/services/web/scripts/sync_v1_subscriptions.js +++ /dev/null @@ -1,71 +0,0 @@ -const { db } = require('../app/js/infrastructure/mongojs') -const FeaturesUpdater = require('../app/js/Features/Subscription/FeaturesUpdater') -const V1SubscriptionManager = require('../app/js/Features/Subscription/V1SubscriptionManager') -const async = require('async') -const logger = require('logger-sharelatex') -logger.logger.level('error') - -const areFeaturesEqual = function(featuresA, featuresB) { - for (const feature in featuresA) { - if (featuresA[feature] !== featuresB[feature]) { - return false - } - } - return true -} - -var outOfSyncUserCount = 0 -var userCount = null - -db.users.find( - { - 'overleaf.id': { $exists: true } - }, - { - overleaf: 1, - features: 1 - }, - function(error, users) { - if (error) throw error - console.log('USER COUNT', (userCount = users.length)) - async.mapSeries( - users, - function(user, callback) { - console.log('REFRESHING IN v2', user._id) - FeaturesUpdater.refreshFeatures(user._id, false, function(error) { - if (error) console.error('ERROR', error) - console.log('REFRESHING IN v1', user._id) - V1SubscriptionManager.notifyV1OfFeaturesChange(user._id, function( - error - ) { - if (error) console.error('ERROR', error) - db.users.find( - { - _id: user._id - }, - { - features: 1 - }, - function(error, [updatedUser]) { - if (error) throw error - if (areFeaturesEqual(user.features, updatedUser.features)) { - console.log('UNCHANGED', user._id) - } else { - console.log('MODIFIED', user._id) - outOfSyncUserCount = outOfSyncUserCount + 1 - } - callback() - } - ) - }) - }) - }, - function(error) { - if (error) throw error - console.log('FINISHED!') - console.log('OUT OF SYNC USERS', outOfSyncUserCount, '/', userCount) - process.exit() - } - ) - } -) diff --git a/services/web/test/acceptance/src/FeatureUpdaterTests.js b/services/web/test/acceptance/src/FeatureUpdaterTests.js index 51684bb9c0..50c678da52 100644 --- a/services/web/test/acceptance/src/FeatureUpdaterTests.js +++ b/services/web/test/acceptance/src/FeatureUpdaterTests.js @@ -30,7 +30,7 @@ const syncUserAndGetFeatures = function(user, callback) { if (callback == null) { callback = function(error, features) {} } - return FeaturesUpdater.refreshFeatures(user._id, false, function(error) { + return FeaturesUpdater.refreshFeatures(user._id, function(error) { if (error != null) { return callback(error) } @@ -331,14 +331,5 @@ describe('FeatureUpdater.refreshFeatures', function() { } ) }) // returns a promise - - return it('should ping the v1 API end point to sync', function(done) { - return FeaturesUpdater.refreshFeatures(this.user._id, true, error => { - return setTimeout(() => { - expect(MockV1Api.syncUserFeatures.calledWith('42')).to.equal(true) - return done() - }, 500) - }) - }) }) }) diff --git a/services/web/test/unit/src/Institutions/InstitutionsControllerTests.js b/services/web/test/unit/src/Institutions/InstitutionsControllerTests.js index 6c2f691d3b..808b28167b 100644 --- a/services/web/test/unit/src/Institutions/InstitutionsControllerTests.js +++ b/services/web/test/unit/src/Institutions/InstitutionsControllerTests.js @@ -49,7 +49,7 @@ describe('InstitutionsController', function() { .stub() .callsArgWith(2, null, [this.stubbedUser1, this.stubbedUser2]) this.addAffiliation = sinon.stub().callsArgWith(3, null) - this.refreshFeatures = sinon.stub().callsArgWith(2, null) + this.refreshFeatures = sinon.stub().yields(null) this.InstitutionsController = SandboxedModule.require(modulePath, { requires: { 'logger-sharelatex': this.logger, @@ -90,10 +90,10 @@ describe('InstitutionsController', function() { .calledWith(this.stubbedUser2._id, this.stubbedUser2.emails[0].email) .should.equal(true) this.refreshFeatures - .calledWith(this.stubbedUser1._id, true) + .calledWith(this.stubbedUser1._id) .should.equal(true) this.refreshFeatures - .calledWith(this.stubbedUser2._id, true) + .calledWith(this.stubbedUser2._id) .should.equal(true) return done() } diff --git a/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js b/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js index 59f96712b4..43d4fd4986 100644 --- a/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js +++ b/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js @@ -102,9 +102,7 @@ describe('InstitutionsManager', function() { this.SubscriptionLocator.getUsersSubscription .withArgs(this.user2) .callsArgWith(1, null, this.subscription) - this.refreshFeatures - .withArgs(this.user1Id) - .callsArgWith(2, null, {}, true) + this.refreshFeatures.withArgs(this.user1Id).yields(null, {}, true) return this.getInstitutionAffiliations.yields(null, this.affiliations) }) diff --git a/services/web/test/unit/src/Subscription/FeaturesUpdaterTests.js b/services/web/test/unit/src/Subscription/FeaturesUpdaterTests.js index 6c4c878292..8593085eca 100644 --- a/services/web/test/unit/src/Subscription/FeaturesUpdaterTests.js +++ b/services/web/test/unit/src/Subscription/FeaturesUpdaterTests.js @@ -40,9 +40,6 @@ describe('FeaturesUpdater', function() { describe('refreshFeatures', function() { beforeEach(function() { - this.V1SubscriptionManager.notifyV1OfFeaturesChange = sinon - .stub() - .yields() this.UserFeaturesUpdater.updateFeatures = sinon.stub().yields() this.FeaturesUpdater._getIndividualFeatures = sinon .stub() @@ -144,28 +141,6 @@ describe('FeaturesUpdater', function() { .calledWith(this.user_id, { merged: 'features' }) .should.equal(true) }) - - return it('should notify v1', function() { - return this.V1SubscriptionManager.notifyV1OfFeaturesChange.called.should.equal( - true - ) - }) - }) - - return describe('with notifyV1 == false', function() { - beforeEach(function() { - return this.FeaturesUpdater.refreshFeatures( - this.user_id, - false, - this.callback - ) - }) - - return it('should not notify v1', function() { - return this.V1SubscriptionManager.notifyV1OfFeaturesChange.called.should.equal( - false - ) - }) }) }) diff --git a/services/web/test/unit/src/User/UserUpdaterTests.js b/services/web/test/unit/src/User/UserUpdaterTests.js index 501eb59ecc..e5ace19f11 100644 --- a/services/web/test/unit/src/User/UserUpdaterTests.js +++ b/services/web/test/unit/src/User/UserUpdaterTests.js @@ -497,11 +497,7 @@ describe('UserUpdater', function() { this.newEmail, err => { should.not.exist(err) - sinon.assert.calledWith( - this.refreshFeatures, - this.stubbedUser._id, - true - ) + sinon.assert.calledWith(this.refreshFeatures, this.stubbedUser._id) return done() } )