Fixed incompatibilities between overleaf.com and community (#2028)

GitOrigin-RevId: fc1e4e3e179cab75144043d83197f09e4f6c7642
This commit is contained in:
Miguel Serrano 2019-08-12 13:27:55 +02:00 committed by sharelatex
parent 7d1bab4e88
commit 6006c8ca79
6 changed files with 43 additions and 4 deletions

View file

@ -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) {

View file

@ -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) {

View file

@ -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}`)
}

View file

@ -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:

View file

@ -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: [
{

View file

@ -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'])