mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Don't use deprecated Project.findPopulatedById in ReferencesManager
This commit is contained in:
parent
b64c8e3d78
commit
0882eb2a99
3 changed files with 31 additions and 24 deletions
|
@ -229,7 +229,6 @@ module.exports = ProjectController =
|
|||
title: project.name
|
||||
priority_title: true
|
||||
bodyClasses: ["editor"]
|
||||
project : project
|
||||
project_id : project._id
|
||||
user : {
|
||||
id : user.id
|
||||
|
|
|
@ -2,6 +2,7 @@ logger = require("logger-sharelatex")
|
|||
request = require("request")
|
||||
settings = require("settings-sharelatex")
|
||||
Project = require("../../models/Project").Project
|
||||
User = require("../../models/User").User
|
||||
DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
|
||||
U = require('underscore')
|
||||
Async = require('async')
|
||||
|
@ -31,11 +32,12 @@ module.exports = ReferencesHandler =
|
|||
return ids
|
||||
|
||||
_isFullIndex: (project, callback = (err, result) ->) ->
|
||||
owner = project.owner_ref
|
||||
callback(null, owner.features.references == true)
|
||||
User.find { _id: project.owner_ref }, { features: true }, (err, owner) ->
|
||||
return callback(err) if err?
|
||||
callback(null, owner?.features?.references == true)
|
||||
|
||||
indexAll: (projectId, callback=(err, data)->) ->
|
||||
Project.findPopulatedById projectId, (err, project) ->
|
||||
Project.find { _id: projectId }, (err, project) ->
|
||||
if err
|
||||
logger.err {err, projectId}, "error finding project"
|
||||
return callback(err)
|
||||
|
@ -44,7 +46,7 @@ module.exports = ReferencesHandler =
|
|||
ReferencesHandler._doIndexOperation(projectId, project, docIds, callback)
|
||||
|
||||
index: (projectId, docIds, callback=(err, data)->) ->
|
||||
Project.findPopulatedById projectId, (err, project) ->
|
||||
Project.find { _id: projectId }, (err, project) ->
|
||||
if err
|
||||
logger.err {err, projectId}, "error finding project"
|
||||
return callback(err)
|
||||
|
|
|
@ -41,9 +41,12 @@ describe 'ReferencesHandler', ->
|
|||
}
|
||||
'../../models/Project': {
|
||||
Project: @Project = {
|
||||
findPopulatedById: sinon.stub().callsArgWith(1, null, @fakeProject)
|
||||
find: sinon.stub().callsArgWith(1, null, @fakeProject)
|
||||
}
|
||||
}
|
||||
'../../models/User': {
|
||||
User: @User = {}
|
||||
}
|
||||
'../DocumentUpdater/DocumentUpdaterHandler': @DocumentUpdaterHandler = {
|
||||
flushDocToMongo: sinon.stub().callsArgWith(2, null)
|
||||
}
|
||||
|
@ -70,10 +73,10 @@ describe 'ReferencesHandler', ->
|
|||
@handler._findBibDocIds.callCount.should.equal 0
|
||||
done()
|
||||
|
||||
it 'should call Project.findPopulatedById', (done) ->
|
||||
it 'should call Project.find', (done) ->
|
||||
@call (err, data) =>
|
||||
@Project.findPopulatedById.callCount.should.equal 1
|
||||
@Project.findPopulatedById.calledWith(@projectId).should.equal true
|
||||
@Project.find.callCount.should.equal 1
|
||||
@Project.find.calledWith(_id: @projectId).should.equal true
|
||||
done()
|
||||
|
||||
it 'should not call _findBibDocIds', (done) ->
|
||||
|
@ -109,10 +112,10 @@ describe 'ReferencesHandler', ->
|
|||
expect(data).to.equal @fakeResponseData
|
||||
done()
|
||||
|
||||
describe 'when Project.findPopulatedById produces an error', ->
|
||||
describe 'when Project.find produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@Project.findPopulatedById.callsArgWith(1, new Error('woops'))
|
||||
@Project.find.callsArgWith(1, new Error('woops'))
|
||||
|
||||
it 'should produce an error', (done) ->
|
||||
@call (err, data) =>
|
||||
|
@ -129,7 +132,7 @@ describe 'ReferencesHandler', ->
|
|||
describe 'when _isFullIndex produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@Project.findPopulatedById.callsArgWith(1, null, @fakeProject)
|
||||
@Project.find.callsArgWith(1, null, @fakeProject)
|
||||
@handler._isFullIndex.callsArgWith(1, new Error('woops'))
|
||||
|
||||
it 'should produce an error', (done) ->
|
||||
|
@ -147,7 +150,7 @@ describe 'ReferencesHandler', ->
|
|||
describe 'when flushDocToMongo produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@Project.findPopulatedById.callsArgWith(1, null, @fakeProject)
|
||||
@Project.find.callsArgWith(1, null, @fakeProject)
|
||||
@handler._isFullIndex.callsArgWith(1, false)
|
||||
@DocumentUpdaterHandler.flushDocToMongo.callsArgWith(2, new Error('woops'))
|
||||
|
||||
|
@ -167,7 +170,7 @@ describe 'ReferencesHandler', ->
|
|||
describe 'when request produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@Project.findPopulatedById.callsArgWith(1, null, @fakeProject)
|
||||
@Project.find.callsArgWith(1, null, @fakeProject)
|
||||
@handler._isFullIndex.callsArgWith(1, null, false)
|
||||
@DocumentUpdaterHandler.flushDocToMongo.callsArgWith(2, null)
|
||||
@request.post.callsArgWith(1, new Error('woops'))
|
||||
|
@ -182,7 +185,7 @@ describe 'ReferencesHandler', ->
|
|||
describe 'when request responds with error status', ->
|
||||
|
||||
beforeEach ->
|
||||
@Project.findPopulatedById.callsArgWith(1, null, @fakeProject)
|
||||
@Project.find.callsArgWith(1, null, @fakeProject)
|
||||
@handler._isFullIndex.callsArgWith(1, null, false)
|
||||
@request.post.callsArgWith(1, null, {statusCode: 500}, null)
|
||||
|
||||
|
@ -234,10 +237,10 @@ describe 'ReferencesHandler', ->
|
|||
expect(data).to.equal @fakeResponseData
|
||||
done()
|
||||
|
||||
describe 'when Project.findPopulatedById produces an error', ->
|
||||
describe 'when Project.find produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@Project.findPopulatedById.callsArgWith(1, new Error('woops'))
|
||||
@Project.find.callsArgWith(1, new Error('woops'))
|
||||
|
||||
it 'should produce an error', (done) ->
|
||||
@call (err, data) =>
|
||||
|
@ -254,7 +257,7 @@ describe 'ReferencesHandler', ->
|
|||
describe 'when _isFullIndex produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@Project.findPopulatedById.callsArgWith(1, null, @fakeProject)
|
||||
@Project.find.callsArgWith(1, null, @fakeProject)
|
||||
@handler._isFullIndex.callsArgWith(1, new Error('woops'))
|
||||
|
||||
it 'should produce an error', (done) ->
|
||||
|
@ -272,7 +275,7 @@ describe 'ReferencesHandler', ->
|
|||
describe 'when flushDocToMongo produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@Project.findPopulatedById.callsArgWith(1, null, @fakeProject)
|
||||
@Project.find.callsArgWith(1, null, @fakeProject)
|
||||
@handler._isFullIndex.callsArgWith(1, false)
|
||||
@DocumentUpdaterHandler.flushDocToMongo.callsArgWith(2, new Error('woops'))
|
||||
|
||||
|
@ -312,16 +315,19 @@ describe 'ReferencesHandler', ->
|
|||
|
||||
beforeEach ->
|
||||
@fakeProject =
|
||||
owner_ref:
|
||||
owner_ref: @owner_ref = "owner-ref-123"
|
||||
@owner =
|
||||
features:
|
||||
references: false
|
||||
@User.find = sinon.stub()
|
||||
@User.find.withArgs({_id: @owner_ref}, {features: true}).yields(null, @owner)
|
||||
@call = (callback) =>
|
||||
@handler._isFullIndex @fakeProject, callback
|
||||
|
||||
describe 'with references feature on', ->
|
||||
|
||||
beforeEach ->
|
||||
@fakeProject.owner_ref.features.references = true
|
||||
@owner.features.references = true
|
||||
|
||||
it 'should return true', ->
|
||||
@call (err, isFullIndex) =>
|
||||
|
@ -331,7 +337,7 @@ describe 'ReferencesHandler', ->
|
|||
describe 'with references feature off', ->
|
||||
|
||||
beforeEach ->
|
||||
@fakeProject.owner_ref.features.references = false
|
||||
@owner.features.references = false
|
||||
|
||||
it 'should return false', ->
|
||||
@call (err, isFullIndex) =>
|
||||
|
|
Loading…
Reference in a new issue