mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Proxy version number to and from docstore
This commit is contained in:
parent
4b59fdd453
commit
eb648b9bc8
6 changed files with 33 additions and 25 deletions
|
@ -30,7 +30,7 @@ module.exports = DocstoreManager =
|
|||
logger.error err: error, project_id: project_id, "error getting all docs from docstore"
|
||||
callback(error)
|
||||
|
||||
getDoc: (project_id, doc_id, options = {}, callback = (error, lines, rev) ->) ->
|
||||
getDoc: (project_id, doc_id, options = {}, callback = (error, lines, rev, version) ->) ->
|
||||
if typeof(options) == "function"
|
||||
callback = options
|
||||
options = {}
|
||||
|
@ -45,19 +45,20 @@ module.exports = DocstoreManager =
|
|||
return callback(error) if error?
|
||||
if 200 <= res.statusCode < 300
|
||||
logger.log doc_id: doc_id, project_id: project_id, version: doc.version, rev: doc.rev, "got doc from docstore api"
|
||||
callback(null, doc.lines, doc.rev)
|
||||
callback(null, doc.lines, doc.rev, doc.version)
|
||||
else
|
||||
error = new Error("docstore api responded with non-success code: #{res.statusCode}")
|
||||
logger.error err: error, project_id: project_id, doc_id: doc_id, "error getting doc from docstore"
|
||||
callback(error)
|
||||
|
||||
updateDoc: (project_id, doc_id, lines, callback = (error, modified, rev) ->) ->
|
||||
updateDoc: (project_id, doc_id, lines, version, callback = (error, modified, rev) ->) ->
|
||||
logger.log project_id: project_id, doc_id: doc_id, "updating doc in docstore api"
|
||||
url = "#{settings.apis.docstore.url}/project/#{project_id}/doc/#{doc_id}"
|
||||
request.post {
|
||||
url: url
|
||||
json:
|
||||
lines: lines
|
||||
version: version
|
||||
}, (error, res, result) ->
|
||||
return callback(error) if error?
|
||||
if 200 <= res.statusCode < 300
|
||||
|
|
|
@ -7,7 +7,7 @@ module.exports =
|
|||
doc_id = req.params.doc_id
|
||||
plain = req?.query?.plain == 'true'
|
||||
logger.log doc_id:doc_id, project_id:project_id, "receiving get document request from api (docupdater)"
|
||||
ProjectEntityHandler.getDoc project_id, doc_id, (error, lines, rev) ->
|
||||
ProjectEntityHandler.getDoc project_id, doc_id, (error, lines, rev, version) ->
|
||||
if error?
|
||||
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
||||
return next(error)
|
||||
|
@ -18,14 +18,15 @@ module.exports =
|
|||
res.type "json"
|
||||
res.send JSON.stringify {
|
||||
lines: lines
|
||||
version: version
|
||||
}
|
||||
|
||||
setDocument: (req, res, next = (error) ->) ->
|
||||
project_id = req.params.Project_id
|
||||
doc_id = req.params.doc_id
|
||||
lines = req.body.lines
|
||||
{lines, version} = req.body
|
||||
logger.log doc_id:doc_id, project_id:project_id, "receiving set document request from api (docupdater)"
|
||||
ProjectEntityHandler.updateDocLines project_id, doc_id, lines, (error) ->
|
||||
ProjectEntityHandler.updateDocLines project_id, doc_id, lines, version, (error) ->
|
||||
if error?
|
||||
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
||||
return next(error)
|
||||
|
|
|
@ -126,7 +126,7 @@ module.exports = ProjectEntityHandler =
|
|||
doc = new Doc name: docName
|
||||
# Put doc in docstore first, so that if it errors, we don't have a doc_id in the project
|
||||
# which hasn't been created in docstore.
|
||||
DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, (err, modified, rev) ->
|
||||
DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, 0, (err, modified, rev) ->
|
||||
return callback(err) if err?
|
||||
|
||||
ProjectEntityHandler._putElement project, folder_id, doc, "doc", (err, result)=>
|
||||
|
@ -292,7 +292,7 @@ module.exports = ProjectEntityHandler =
|
|||
return callback(err)
|
||||
callback(err, folder, parentFolder_id)
|
||||
|
||||
updateDocLines : (project_id, doc_id, lines, callback = (error) ->)->
|
||||
updateDocLines : (project_id, doc_id, lines, version, callback = (error) ->)->
|
||||
ProjectGetter.getProjectWithoutDocLines project_id, (err, project)->
|
||||
return callback(err) if err?
|
||||
return callback(new Errors.NotFoundError("project not found")) if !project?
|
||||
|
@ -307,7 +307,7 @@ module.exports = ProjectEntityHandler =
|
|||
return callback(error)
|
||||
|
||||
logger.log project_id: project_id, doc_id: doc_id, "telling docstore manager to update doc"
|
||||
DocstoreManager.updateDoc project_id, doc_id, lines, (err, modified, rev) ->
|
||||
DocstoreManager.updateDoc project_id, doc_id, lines, version, (err, modified, rev) ->
|
||||
if err?
|
||||
logger.error err: err, doc_id: doc_id, project_id:project_id, lines: lines, "error sending doc to docstore"
|
||||
return callback(err)
|
||||
|
|
|
@ -56,12 +56,13 @@ describe "DocstoreManager", ->
|
|||
beforeEach ->
|
||||
@lines = ["mock", "doc", "lines"]
|
||||
@rev = 5
|
||||
@version = 42
|
||||
@modified = true
|
||||
|
||||
describe "with a successful response code", ->
|
||||
beforeEach ->
|
||||
@request.post = sinon.stub().callsArgWith(1, null, statusCode: 204, { modified: @modified, rev: @rev })
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @callback
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @version, @callback
|
||||
|
||||
it "should update the doc in the docstore api", ->
|
||||
@request.post
|
||||
|
@ -69,6 +70,7 @@ describe "DocstoreManager", ->
|
|||
url: "#{@settings.apis.docstore.url}/project/#{@project_id}/doc/#{@doc_id}"
|
||||
json:
|
||||
lines: @lines
|
||||
version: @version
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
|
@ -78,7 +80,7 @@ describe "DocstoreManager", ->
|
|||
describe "with a failed response code", ->
|
||||
beforeEach ->
|
||||
@request.post = sinon.stub().callsArgWith(1, null, statusCode: 500, "")
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @callback
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @version, @callback
|
||||
|
||||
it "should call the callback with an error", ->
|
||||
@callback.calledWith(new Error("docstore api responded with non-success code: 500")).should.equal true
|
||||
|
@ -97,6 +99,7 @@ describe "DocstoreManager", ->
|
|||
@doc =
|
||||
lines: @lines = ["mock", "doc", "lines"]
|
||||
rev: @rev = 5
|
||||
version: @version = 42
|
||||
|
||||
describe "with a successful response code", ->
|
||||
beforeEach ->
|
||||
|
@ -112,7 +115,7 @@ describe "DocstoreManager", ->
|
|||
.should.equal true
|
||||
|
||||
it "should call the callback with the lines, version and rev", ->
|
||||
@callback.calledWith(null, @lines, @rev).should.equal true
|
||||
@callback.calledWith(null, @lines, @rev, @version).should.equal true
|
||||
|
||||
describe "with a failed response code", ->
|
||||
beforeEach ->
|
||||
|
@ -145,7 +148,7 @@ describe "DocstoreManager", ->
|
|||
.should.equal true
|
||||
|
||||
it "should call the callback with the lines, version and rev", ->
|
||||
@callback.calledWith(null, @lines, @rev).should.equal true
|
||||
@callback.calledWith(null, @lines, @rev, @version).should.equal true
|
||||
|
||||
describe "getAllDocs", ->
|
||||
describe "with a successful response code", ->
|
||||
|
|
|
@ -33,7 +33,7 @@ describe "DocumentController", ->
|
|||
|
||||
describe "when the document exists", ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev)
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev, @version)
|
||||
@DocumentController.getDocument(@req, @res, @next)
|
||||
|
||||
it "should get the document from Mongo", ->
|
||||
|
@ -45,6 +45,7 @@ describe "DocumentController", ->
|
|||
@res.type.should.equal "json"
|
||||
@res.body.should.equal JSON.stringify
|
||||
lines: @doc_lines
|
||||
version: @version
|
||||
|
||||
describe "when the document doesn't exist", ->
|
||||
beforeEach ->
|
||||
|
@ -63,14 +64,15 @@ describe "DocumentController", ->
|
|||
|
||||
describe "when the document exists", ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.updateDocLines = sinon.stub().callsArg(3)
|
||||
@ProjectEntityHandler.updateDocLines = sinon.stub().yields()
|
||||
@req.body =
|
||||
lines: @doc_lines
|
||||
version: @version
|
||||
@DocumentController.setDocument(@req, @res, @next)
|
||||
|
||||
it "should update the document in Mongo", ->
|
||||
@ProjectEntityHandler.updateDocLines
|
||||
.calledWith(@project_id, @doc_id, @doc_lines)
|
||||
.calledWith(@project_id, @doc_id, @doc_lines, @version)
|
||||
.should.equal true
|
||||
|
||||
it "should return a successful response", ->
|
||||
|
@ -78,7 +80,7 @@ describe "DocumentController", ->
|
|||
|
||||
describe "when the document doesn't exist", ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.updateDocLines = sinon.stub().callsArgWith(3, new Errors.NotFoundError("document does not exist"))
|
||||
@ProjectEntityHandler.updateDocLines = sinon.stub().yields(new Errors.NotFoundError("document does not exist"))
|
||||
@req.body =
|
||||
lines: @doc_lines
|
||||
@DocumentController.setDocument(@req, @res, @next)
|
||||
|
|
|
@ -402,7 +402,7 @@ describe 'ProjectEntityHandler', ->
|
|||
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, {path:{fileSystem:@path}})
|
||||
@callback = sinon.stub()
|
||||
@tpdsUpdateSender.addDoc = sinon.stub().callsArg(1)
|
||||
@DocstoreManager.updateDoc = sinon.stub().callsArgWith(3, null, true, 0)
|
||||
@DocstoreManager.updateDoc = sinon.stub().yields(null, true, 0)
|
||||
|
||||
@ProjectEntityHandler.addDoc project_id, folder_id, @name, @lines, @callback
|
||||
|
||||
|
@ -589,6 +589,7 @@ describe 'ProjectEntityHandler', ->
|
|||
@doc = {
|
||||
_id: doc_id
|
||||
}
|
||||
@version = 42
|
||||
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().callsArgWith(1, null, @project)
|
||||
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, @doc, {fileSystem: @path})
|
||||
@tpdsUpdateSender.addDoc = sinon.stub().callsArg(1)
|
||||
|
@ -597,8 +598,8 @@ describe 'ProjectEntityHandler', ->
|
|||
|
||||
describe "when the doc has been modified", ->
|
||||
beforeEach ->
|
||||
@DocstoreManager.updateDoc = sinon.stub().callsArgWith(3, null, true, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @callback
|
||||
@DocstoreManager.updateDoc = sinon.stub().yields(null, true, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
|
||||
it "should get the project without doc lines", ->
|
||||
@ProjectGetter.getProjectWithoutDocLines
|
||||
|
@ -616,7 +617,7 @@ describe 'ProjectEntityHandler', ->
|
|||
|
||||
it "should update the doc in the docstore", ->
|
||||
@DocstoreManager.updateDoc
|
||||
.calledWith(project_id, doc_id, @lines)
|
||||
.calledWith(project_id, doc_id, @lines, @version)
|
||||
.should.equal true
|
||||
|
||||
it "should mark the project as updated", ->
|
||||
|
@ -640,8 +641,8 @@ describe 'ProjectEntityHandler', ->
|
|||
|
||||
describe "when the doc has not been modified", ->
|
||||
beforeEach ->
|
||||
@DocstoreManager.updateDoc = sinon.stub().callsArgWith(3, null, false, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @callback
|
||||
@DocstoreManager.updateDoc = sinon.stub().yields(null, false, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
|
||||
it "should not mark the project as updated", ->
|
||||
@projectUpdater.markAsUpdated.called.should.equal false
|
||||
|
@ -655,7 +656,7 @@ describe 'ProjectEntityHandler', ->
|
|||
describe "when the project is not found", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().callsArgWith(1, null, null)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @callback
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
|
||||
it "should return a not found error", ->
|
||||
@callback.calledWith(new Errors.NotFoundError()).should.equal true
|
||||
|
@ -663,7 +664,7 @@ describe 'ProjectEntityHandler', ->
|
|||
describe "when the doc is not found", ->
|
||||
beforeEach ->
|
||||
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, null, null)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @callback
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
|
||||
it "should log out the error", ->
|
||||
@logger.error
|
||||
|
|
Loading…
Reference in a new issue