From 6006c8ca79927743e492d9c995504b670ef0842e Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Mon, 12 Aug 2019 13:27:55 +0200 Subject: [PATCH] Fixed incompatibilities between overleaf.com and community (#2028) GitOrigin-RevId: fc1e4e3e179cab75144043d83197f09e4f6c7642 --- .../src/Features/Project/ProjectController.js | 9 +++++++- .../Features/References/ReferencesHandler.js | 5 ++-- .../web/app/src/infrastructure/Features.js | 4 ++++ services/web/config/settings.defaults.coffee | 2 +- .../src/Project/ProjectControllerTests.js | 4 ++++ .../src/References/ReferencesHandlerTests.js | 23 +++++++++++++++++++ 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/services/web/app/src/Features/Project/ProjectController.js b/services/web/app/src/Features/Project/ProjectController.js index ddd51769b6..ed0bebdef3 100644 --- a/services/web/app/src/Features/Project/ProjectController.js +++ b/services/web/app/src/Features/Project/ProjectController.js @@ -347,6 +347,10 @@ module.exports = ProjectController = { ) }, v1Projects(cb) { + if (!Features.hasFeature('overleaf-integration')) { + return cb(null, null) + } + return Modules.hooks.fire('findAllV1Projects', user_id, function( error, projects @@ -379,6 +383,9 @@ module.exports = ProjectController = { ) }, userAffiliations(cb) { + if (!Features.hasFeature('affiliations')) { + return cb(null, null) + } return getUserAffiliations(user_id, cb) } }, @@ -905,7 +912,7 @@ module.exports = ProjectController = { v1ProjectData = {} } const warnings = [] - if (v1ProjectData.noConnection) { + if (v1ProjectData.noConnection && Settings.overleaf) { warnings.push('No V1 Connection') } if (v1ProjectData.hasHiddenV1Projects) { diff --git a/services/web/app/src/Features/References/ReferencesHandler.js b/services/web/app/src/Features/References/ReferencesHandler.js index 974a15be1e..0d25dd0033 100644 --- a/services/web/app/src/Features/References/ReferencesHandler.js +++ b/services/web/app/src/Features/References/ReferencesHandler.js @@ -16,6 +16,7 @@ let ReferencesHandler const logger = require('logger-sharelatex') const request = require('request') const settings = require('settings-sharelatex') +const Features = require('../../infrastructure/Features') const ProjectGetter = require('../Project/ProjectGetter') const UserGetter = require('../User/UserGetter') const DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler') @@ -25,7 +26,7 @@ const Async = require('async') const oneMinInMs = 60 * 1000 const fiveMinsInMs = oneMinInMs * 5 -if (!settings.apis.references.url) { +if (!Features.hasFeature('references')) { logger.log('references search not enabled') } @@ -144,7 +145,7 @@ module.exports = ReferencesHandler = { }, _doIndexOperation(projectId, project, docIds, fileIds, callback) { - if (!settings.apis.references.url) { + if (!Features.hasFeature('references')) { return callback() } return ReferencesHandler._isFullIndex(project, function(err, isFullIndex) { diff --git a/services/web/app/src/infrastructure/Features.js b/services/web/app/src/infrastructure/Features.js index d0bbd9d29f..0b2a831b4d 100644 --- a/services/web/app/src/infrastructure/Features.js +++ b/services/web/app/src/infrastructure/Features.js @@ -46,6 +46,10 @@ module.exports = Features = { return !!Settings.apis.v1.url case 'redirect-sl': return Settings.redirectToV2 != null + case 'overleaf-integration': + return Settings.overleaf != null + case 'references': + return Settings.apis.references.url != null default: throw new Error(`unknown feature: ${feature}`) } diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index 9b16cf09e7..166768fd95 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -148,7 +148,7 @@ module.exports = settings = sixpack: url: "" references: - url: "http://#{process.env['REFERENCES_HOST'] or 'localhost'}:3040" + url: if process.env['REFERENCES_HOST']? then "http://#{process.env['REFERENCES_HOST']}:3040" else undefined notifications: url: "http://#{process.env['NOTIFICATIONS_HOST'] or 'localhost'}:3042" analytics: diff --git a/services/web/test/unit/src/Project/ProjectControllerTests.js b/services/web/test/unit/src/Project/ProjectControllerTests.js index 5d467444ec..e26fc67531 100644 --- a/services/web/test/unit/src/Project/ProjectControllerTests.js +++ b/services/web/test/unit/src/Project/ProjectControllerTests.js @@ -553,6 +553,10 @@ describe('ProjectController', function() { describe('with overleaf-integration-web-module hook', function() { beforeEach(function() { + this.Features.hasFeature = sinon + .stub() + .withArgs('overleaf-integration') + .returns(true) this.V1Response = { projects: [ { diff --git a/services/web/test/unit/src/References/ReferencesHandlerTests.js b/services/web/test/unit/src/References/ReferencesHandlerTests.js index b10482a969..78c534c6dc 100644 --- a/services/web/test/unit/src/References/ReferencesHandlerTests.js +++ b/services/web/test/unit/src/References/ReferencesHandlerTests.js @@ -76,6 +76,9 @@ describe('ReferencesHandler', function() { }), '../DocumentUpdater/DocumentUpdaterHandler': (this.DocumentUpdaterHandler = { flushDocToMongo: sinon.stub().callsArgWith(2, null) + }), + '../../infrastructure/Features': (this.Features = { + hasFeature: sinon.stub().returns(true) }) } }) @@ -101,6 +104,26 @@ describe('ReferencesHandler', function() { }) }) + describe('when references feature is disabled', function() { + beforeEach(function() { + this.Features.hasFeature.withArgs('references').returns(false) + }) + + it('should not try to retrieve any user information', function(done) { + this.call(() => { + this.UserGetter.getUser.callCount.should.equal(0) + done() + }) + }) + + it('should not produce an error', function(done) { + return this.call(err => { + expect(err).to.equal(undefined) + return done() + }) + }) + }) + describe('with docIds as an array', function() { beforeEach(function() { return (this.docIds = ['aaa', 'ccc'])