mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
return pathname from DocumentController.getDoc
This commit is contained in:
parent
13628f82ec
commit
bf1c24f6f9
4 changed files with 88 additions and 56 deletions
|
@ -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, version, ranges) ->
|
||||
ProjectEntityHandler.getDoc project_id, doc_id, {pathname: true}, (error, lines, rev, version, ranges, pathname) ->
|
||||
if error?
|
||||
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
||||
return next(error)
|
||||
|
@ -20,6 +20,7 @@ module.exports =
|
|||
lines: lines
|
||||
version: version
|
||||
ranges: ranges
|
||||
pathname: pathname
|
||||
}
|
||||
|
||||
setDocument: (req, res, next = (error) ->) ->
|
||||
|
@ -33,6 +34,3 @@ module.exports =
|
|||
return next(error)
|
||||
logger.log doc_id:doc_id, project_id:project_id, "finished receiving set document request from api (docupdater)"
|
||||
res.sendStatus 200
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -140,8 +140,15 @@ module.exports = ProjectEntityHandler =
|
|||
if typeof(options) == "function"
|
||||
callback = options
|
||||
options = {}
|
||||
DocstoreManager.getDoc project_id, doc_id, options, callback
|
||||
|
||||
if options["pathname"]
|
||||
delete options["pathname"]
|
||||
projectLocator.findElement {project_id: project_id, element_id: doc_id, type: 'doc'}, (error, doc, path) =>
|
||||
return callback(error) if error?
|
||||
DocstoreManager.getDoc project_id, doc_id, options, (error, lines, rev, version, ranges) =>
|
||||
callback(error, lines, rev, version, ranges, path.fileSystem)
|
||||
else
|
||||
DocstoreManager.getDoc project_id, doc_id, options, callback
|
||||
|
||||
addDoc: (project_id, folder_id, docName, docLines, callback = (error, doc, folder_id) ->)=>
|
||||
ProjectGetter.getProjectWithOnlyFolders project_id, (err, project) ->
|
||||
|
|
|
@ -24,6 +24,7 @@ describe "DocumentController", ->
|
|||
@doc_lines = ["one", "two", "three"]
|
||||
@version = 42
|
||||
@ranges = {"mock": "ranges"}
|
||||
@pathname = '/a/b/c/file.tex'
|
||||
@rev = 5
|
||||
|
||||
describe "getDocument", ->
|
||||
|
@ -34,12 +35,12 @@ describe "DocumentController", ->
|
|||
|
||||
describe "when the document exists", ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev, @version, @ranges)
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(3, null, @doc_lines, @rev, @version, @ranges, @pathname)
|
||||
@DocumentController.getDocument(@req, @res, @next)
|
||||
|
||||
it "should get the document from Mongo", ->
|
||||
@ProjectEntityHandler.getDoc
|
||||
.calledWith(@project_id, @doc_id)
|
||||
.calledWith(@project_id, @doc_id, pathname: true)
|
||||
.should.equal true
|
||||
|
||||
it "should return the document data to the client as JSON", ->
|
||||
|
@ -48,10 +49,11 @@ describe "DocumentController", ->
|
|||
lines: @doc_lines
|
||||
version: @version
|
||||
ranges: @ranges
|
||||
pathname: @pathname
|
||||
|
||||
describe "when the document doesn't exist", ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, new Errors.NotFoundError("not found"), null)
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(3, new Errors.NotFoundError("not found"), null)
|
||||
@DocumentController.getDocument(@req, @res, @next)
|
||||
|
||||
it "should call next with the NotFoundError", ->
|
||||
|
|
|
@ -385,7 +385,11 @@ describe 'ProjectEntityHandler', ->
|
|||
@rev = 5
|
||||
@version = 42
|
||||
@ranges = {"mock": "ranges"}
|
||||
|
||||
@DocstoreManager.getDoc = sinon.stub().callsArgWith(3, null, @lines, @rev, @version, @ranges)
|
||||
|
||||
describe 'without pathname option', ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.getDoc project_id, doc_id, @callback
|
||||
|
||||
it "should call the docstore", ->
|
||||
|
@ -396,6 +400,27 @@ describe 'ProjectEntityHandler', ->
|
|||
it "should call the callback with the lines, version and rev", ->
|
||||
@callback.calledWith(null, @lines, @rev, @version, @ranges).should.equal true
|
||||
|
||||
describe 'with pathname option', ->
|
||||
beforeEach ->
|
||||
@project = 'a project'
|
||||
@path = mongo: "mongo.path", fileSystem: "/file/system/path"
|
||||
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, {}, @path)
|
||||
@ProjectEntityHandler.getDoc project_id, doc_id, {pathname: true}, @callback
|
||||
|
||||
it "should call the project locator", ->
|
||||
@projectLocator.findElement
|
||||
.calledWith({project_id: project_id, element_id: doc_id, type: 'doc'})
|
||||
.should.equal true
|
||||
|
||||
it "should call the docstore", ->
|
||||
@DocstoreManager.getDoc
|
||||
.calledWith(project_id, doc_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return the pathname if option given", ->
|
||||
@callback.calledWith(null, @lines, @rev, @version, @ranges, @path.fileSystem).should.equal true
|
||||
|
||||
|
||||
describe 'addDoc', ->
|
||||
beforeEach ->
|
||||
@name = "some new doc"
|
||||
|
|
Loading…
Reference in a new issue