mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-09 01:32:39 +00:00
Don't proxy version number to/from docstore
This commit is contained in:
parent
bf8fae176f
commit
f6e85c4140
6 changed files with 29 additions and 41 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, callback = (error, lines, version, rev) ->) ->
|
||||
getDoc: (project_id, doc_id, callback = (error, lines, rev) ->) ->
|
||||
logger.log project_id: project_id, doc_id: doc_id, "getting doc in docstore api"
|
||||
url = "#{settings.apis.docstore.url}/project/#{project_id}/doc/#{doc_id}"
|
||||
request.get {
|
||||
|
@ -40,20 +40,19 @@ 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.version, doc.rev)
|
||||
callback(null, doc.lines, doc.rev)
|
||||
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, version, callback = (error, modified, rev) ->) ->
|
||||
logger.log project_id: project_id, doc_id: doc_id, version: version, "updating doc in docstore api"
|
||||
updateDoc: (project_id, doc_id, lines, 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,14 +7,13 @@ module.exports =
|
|||
project_id = req.params.Project_id
|
||||
doc_id = req.params.doc_id
|
||||
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, version, rev) ->
|
||||
ProjectEntityHandler.getDoc project_id, doc_id, (error, lines, rev) ->
|
||||
if error?
|
||||
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
||||
return next(error)
|
||||
res.type "json"
|
||||
res.send JSON.stringify {
|
||||
lines: lines
|
||||
version: version
|
||||
}
|
||||
req.session.destroy()
|
||||
|
||||
|
@ -22,9 +21,8 @@ module.exports =
|
|||
project_id = req.params.Project_id
|
||||
doc_id = req.params.doc_id
|
||||
lines = req.body.lines
|
||||
version = req.body.version
|
||||
logger.log doc_id:doc_id, project_id:project_id, "receiving set document request from api (docupdater)"
|
||||
ProjectEntityHandler.updateDocLines project_id, doc_id, lines, version, (error) ->
|
||||
ProjectEntityHandler.updateDocLines project_id, doc_id, lines, (error) ->
|
||||
if error?
|
||||
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
||||
return next(error)
|
||||
|
|
|
@ -111,7 +111,7 @@ module.exports = ProjectEntityHandler =
|
|||
logger.log sl_req_id: sl_req_id, project_id: project_id, "removing root doc"
|
||||
Project.update {_id:project_id}, {$unset: {rootDoc_id: true}}, {}, callback
|
||||
|
||||
getDoc: (project_id, doc_id, callback = (error, lines, version, rev) ->) ->
|
||||
getDoc: (project_id, doc_id, callback = (error, lines, rev) ->) ->
|
||||
DocstoreManager.getDoc project_id, doc_id, callback
|
||||
|
||||
addDoc: (project_or_id, folder_id, docName, docLines, sl_req_id, callback = (error, doc, folder_id) ->)=>
|
||||
|
@ -234,23 +234,23 @@ module.exports = ProjectEntityHandler =
|
|||
if callback?
|
||||
callback(err, folder, parentFolder_id)
|
||||
|
||||
updateDocLines : (project_id, doc_id, lines, version, callback = (error) ->)->
|
||||
updateDocLines : (project_id, doc_id, lines, callback = (error) ->)->
|
||||
ProjectGetter.getProjectWithoutDocLines project_id, (err, project)->
|
||||
return callback(err) if err?
|
||||
return callback(new Errors.NotFoundError("project not found")) if !project?
|
||||
logger.log project_id: project_id, doc_id: doc_id, version: version, "updating doc lines"
|
||||
logger.log project_id: project_id, doc_id: doc_id, "updating doc lines"
|
||||
projectLocator.findElement {project:project, element_id:doc_id, type:"docs"}, (err, doc, path)->
|
||||
if err?
|
||||
logger.error err: err, doc_id: doc_id, project_id: project_id, version: version, lines: lines, "error finding doc while updating doc lines"
|
||||
logger.error err: err, doc_id: doc_id, project_id: project_id, lines: lines, "error finding doc while updating doc lines"
|
||||
return callback err
|
||||
if !doc?
|
||||
error = new Errors.NotFoundError("doc not found")
|
||||
logger.error err: error, doc_id: doc_id, project_id: project_id, version: version, lines: lines, "doc not found while updating doc lines"
|
||||
logger.error err: error, doc_id: doc_id, project_id: project_id, lines: lines, "doc not found while updating doc lines"
|
||||
return callback(error)
|
||||
|
||||
DocstoreManager.updateDoc project_id, doc_id, lines, version, (err, modified, rev) ->
|
||||
DocstoreManager.updateDoc project_id, doc_id, lines, (err, modified, rev) ->
|
||||
if err?
|
||||
logger.error err: err, doc_id: doc_id, project_id:project_id, lines: lines, version: version, "error sending doc to docstore"
|
||||
logger.error err: err, doc_id: doc_id, project_id:project_id, lines: lines, "error sending doc to docstore"
|
||||
return callback(err)
|
||||
|
||||
if modified
|
||||
|
|
|
@ -55,14 +55,13 @@ describe "DocstoreManager", ->
|
|||
describe "updateDoc", ->
|
||||
beforeEach ->
|
||||
@lines = ["mock", "doc", "lines"]
|
||||
@version = 42
|
||||
@rev = 5
|
||||
@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, @version, @callback
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @callback
|
||||
|
||||
it "should update the doc in the docstore api", ->
|
||||
@request.post
|
||||
|
@ -70,7 +69,6 @@ describe "DocstoreManager", ->
|
|||
url: "#{@settings.apis.docstore.url}/project/#{@project_id}/doc/#{@doc_id}"
|
||||
json:
|
||||
lines: @lines
|
||||
version: @version
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
|
@ -80,7 +78,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, @version, @callback
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @callback
|
||||
|
||||
it "should call the callback with an error", ->
|
||||
@callback.calledWith(new Error("docstore api responded with non-success code: 500")).should.equal true
|
||||
|
@ -98,7 +96,6 @@ describe "DocstoreManager", ->
|
|||
beforeEach ->
|
||||
@doc =
|
||||
lines: @lines = ["mock", "doc", "lines"]
|
||||
version: @version = 42
|
||||
rev: @rev = 5
|
||||
|
||||
describe "with a successful response code", ->
|
||||
|
@ -115,7 +112,7 @@ describe "DocstoreManager", ->
|
|||
.should.equal true
|
||||
|
||||
it "should call the callback with the lines, version and rev", ->
|
||||
@callback.calledWith(null, @lines, @version, @rev).should.equal true
|
||||
@callback.calledWith(null, @lines, @rev).should.equal true
|
||||
|
||||
describe "with a failed response code", ->
|
||||
beforeEach ->
|
||||
|
|
|
@ -30,7 +30,7 @@ describe "DocumentController", ->
|
|||
|
||||
describe "when the document exists", ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @version, @rev)
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev)
|
||||
@DocumentController.getDocument(@req, @res, @next)
|
||||
|
||||
it "should get the document from Mongo", ->
|
||||
|
@ -42,7 +42,6 @@ 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 ->
|
||||
|
@ -61,15 +60,14 @@ describe "DocumentController", ->
|
|||
|
||||
describe "when the document exists", ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.updateDocLines = sinon.stub().callsArg(4)
|
||||
@ProjectEntityHandler.updateDocLines = sinon.stub().callsArg(3)
|
||||
@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, @version)
|
||||
.calledWith(@project_id, @doc_id, @doc_lines)
|
||||
.should.equal true
|
||||
|
||||
it "should return a successful response", ->
|
||||
|
@ -77,10 +75,9 @@ describe "DocumentController", ->
|
|||
|
||||
describe "when the document doesn't exist", ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.updateDocLines = sinon.stub().callsArgWith(4, new Errors.NotFoundError("document does not exist"))
|
||||
@ProjectEntityHandler.updateDocLines = sinon.stub().callsArgWith(3, new Errors.NotFoundError("document does not exist"))
|
||||
@req.body =
|
||||
lines: @doc_lines
|
||||
version: @version
|
||||
@DocumentController.setDocument(@req, @res, @next)
|
||||
|
||||
it "should call next with the NotFoundError", ->
|
||||
|
|
|
@ -284,9 +284,8 @@ describe 'ProjectEntityHandler', ->
|
|||
describe 'getDoc', ->
|
||||
beforeEach ->
|
||||
@lines = ["mock", "doc", "lines"]
|
||||
@version = 42
|
||||
@rev = 5
|
||||
@DocstoreManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @rev)
|
||||
@DocstoreManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @rev)
|
||||
@ProjectEntityHandler.getDoc project_id, doc_id, @callback
|
||||
|
||||
it "should call the docstore", ->
|
||||
|
@ -295,7 +294,7 @@ describe 'ProjectEntityHandler', ->
|
|||
.should.equal true
|
||||
|
||||
it "should call the callback with the lines, version and rev", ->
|
||||
@callback.calledWith(null, @lines, @version, @rev).should.equal true
|
||||
@callback.calledWith(null, @lines, @rev).should.equal true
|
||||
|
||||
describe 'addDoc', ->
|
||||
beforeEach ->
|
||||
|
@ -465,7 +464,6 @@ 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)
|
||||
|
@ -474,8 +472,8 @@ describe 'ProjectEntityHandler', ->
|
|||
|
||||
describe "when the doc has been modified", ->
|
||||
beforeEach ->
|
||||
@DocstoreManager.updateDoc = sinon.stub().callsArgWith(4, null, true, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
@DocstoreManager.updateDoc = sinon.stub().callsArgWith(3, null, true, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @callback
|
||||
|
||||
it "should get the project without doc lines", ->
|
||||
@ProjectGetter.getProjectWithoutDocLines
|
||||
|
@ -493,7 +491,7 @@ describe 'ProjectEntityHandler', ->
|
|||
|
||||
it "should update the doc in the docstore", ->
|
||||
@DocstoreManager.updateDoc
|
||||
.calledWith(project_id, doc_id, @lines, @version)
|
||||
.calledWith(project_id, doc_id, @lines)
|
||||
.should.equal true
|
||||
|
||||
it "should mark the project as updated", ->
|
||||
|
@ -517,8 +515,8 @@ describe 'ProjectEntityHandler', ->
|
|||
|
||||
describe "when the doc has not been modified", ->
|
||||
beforeEach ->
|
||||
@DocstoreManager.updateDoc = sinon.stub().callsArgWith(4, null, false, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
@DocstoreManager.updateDoc = sinon.stub().callsArgWith(3, null, false, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @callback
|
||||
|
||||
it "should not mark the project as updated", ->
|
||||
@projectUpdater.markAsUpdated.called.should.equal false
|
||||
|
@ -532,7 +530,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, @version, @callback
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @callback
|
||||
|
||||
it "should return a not found error", ->
|
||||
@callback.calledWith(new Errors.NotFoundError()).should.equal true
|
||||
|
@ -540,14 +538,13 @@ 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, @version, @callback
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @callback
|
||||
|
||||
it "should log out the error", ->
|
||||
@logger.error
|
||||
.calledWith(
|
||||
project_id: project_id
|
||||
doc_id: doc_id
|
||||
version: @version
|
||||
lines: @lines
|
||||
err: new Errors.NotFoundError("doc not found")
|
||||
"doc not found while updating doc lines"
|
||||
|
|
Loading…
Add table
Reference in a new issue