mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-05 06:09:20 +00:00
Return deleted docs
This commit is contained in:
parent
828aefe2c8
commit
7870b4fb55
6 changed files with 67 additions and 7 deletions
|
@ -10,8 +10,14 @@ module.exports = DocManager =
|
|||
return callback new Errors.NotFoundError("No such project: #{project_id}") if !project?
|
||||
DocManager.findDocInProject project, doc_id, (error, doc, mongoPath) ->
|
||||
return callback(error) if error?
|
||||
return callback new Errors.NotFoundError("No such doc: #{project_id}") if !doc?
|
||||
return callback null, doc, mongoPath
|
||||
if doc?
|
||||
return callback null, doc, mongoPath
|
||||
else
|
||||
# Perhaps it's a deleted doc
|
||||
MongoManager.findDoc doc_id, (error, doc) ->
|
||||
return callback(error) if error?
|
||||
return callback new Errors.NotFoundError("No such doc: #{project_id}") if !doc?
|
||||
return callback null, doc
|
||||
|
||||
getAllDocs: (project_id, callback = (error, docs) ->) ->
|
||||
MongoManager.findProject project_id, (error, project) ->
|
||||
|
@ -24,7 +30,7 @@ module.exports = DocManager =
|
|||
updateDoc: (project_id, doc_id, lines, callback = (error, modified, rev) ->) ->
|
||||
DocManager.getDoc project_id, doc_id, (error, doc, mongoPath) ->
|
||||
return callback(error) if error?
|
||||
return callback new Errors.NotFoundError("No such project/doc: #{project_id}/#{doc_id}") if !doc?
|
||||
return callback new Errors.NotFoundError("No such project/doc: #{project_id}/#{doc_id}") if !doc? or !mongoPath?
|
||||
|
||||
if _.isEqual(doc.lines, lines)
|
||||
logger.log {
|
||||
|
|
|
@ -8,6 +8,7 @@ module.exports = HttpController =
|
|||
logger.log project_id: project_id, doc_id: doc_id, "getting doc"
|
||||
DocManager.getDoc project_id, doc_id, (error, doc) ->
|
||||
return next(error) if error?
|
||||
logger.log doc: doc, "got doc"
|
||||
if !doc?
|
||||
res.send 404
|
||||
else
|
||||
|
@ -69,6 +70,7 @@ module.exports = HttpController =
|
|||
_id: doc._id?.toString()
|
||||
lines: doc.lines
|
||||
rev: doc.rev
|
||||
deleted: !!doc.deleted
|
||||
}
|
||||
|
||||
_buildRawDocView: (doc)->
|
||||
|
|
|
@ -5,6 +5,10 @@ module.exports = MongoManager =
|
|||
db.projects.find _id: ObjectId(project_id.toString()), {}, (error, projects = []) ->
|
||||
callback error, projects[0]
|
||||
|
||||
findDoc: (doc_id, callback = (error, doc) ->) ->
|
||||
db.docs.find _id: ObjectId(doc_id.toString()), {}, (error, docs = []) ->
|
||||
callback error, docs[0]
|
||||
|
||||
updateDoc: (project_id, docPath, lines, callback = (error) ->) ->
|
||||
update =
|
||||
$set: {}
|
||||
|
|
|
@ -53,11 +53,11 @@ describe "DocManager", ->
|
|||
.calledWith(new Errors.NotFoundError("No such project: #{@project_id}"))
|
||||
.should.equal true
|
||||
|
||||
describe "when the doc does not exist", ->
|
||||
describe "when the doc does not exist in the project tree", ->
|
||||
beforeEach ->
|
||||
@project = { name: "mock-project" }
|
||||
@MongoManager.findProject = sinon.stub().callsArgWith(1, null, @project)
|
||||
@DocManager.findDocInProject = sinon.stub().callsArgWith(2, null, null, null)
|
||||
@MongoManager.findDoc = sinon.stub().callsArgWith(1, null, @doc)
|
||||
@DocManager.getDoc @project_id, @doc_id, @callback
|
||||
|
||||
it "should try to find the doc in the project", ->
|
||||
|
@ -65,6 +65,33 @@ describe "DocManager", ->
|
|||
.calledWith(@project, @doc_id)
|
||||
.should.equal true
|
||||
|
||||
it "should try to find the doc in the docs collection", ->
|
||||
@MongoManager.findDoc
|
||||
.calledWith(@doc_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return the doc", ->
|
||||
@callback
|
||||
.calledWith(null, @doc)
|
||||
.should.equal true
|
||||
|
||||
describe "when the doc does not exist anywhere", ->
|
||||
beforeEach ->
|
||||
@MongoManager.findProject = sinon.stub().callsArgWith(1, null, @project)
|
||||
@DocManager.findDocInProject = sinon.stub().callsArgWith(2, null, null, null)
|
||||
@MongoManager.findDoc = sinon.stub().callsArgWith(1, null, null)
|
||||
@DocManager.getDoc @project_id, @doc_id, @callback
|
||||
|
||||
it "should try to find the doc in the project", ->
|
||||
@DocManager.findDocInProject
|
||||
.calledWith(@project, @doc_id)
|
||||
.should.equal true
|
||||
|
||||
it "should try to find the doc in the docs collection", ->
|
||||
@MongoManager.findDoc
|
||||
.calledWith(@doc_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return a NotFoundError", ->
|
||||
@callback
|
||||
.calledWith(new Errors.NotFoundError("No such doc: #{@doc_id}"))
|
||||
|
|
|
@ -43,6 +43,7 @@ describe "HttpController", ->
|
|||
_id: @doc_id
|
||||
lines: @doc.lines
|
||||
rev: @doc.rev
|
||||
deleted: false
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
|
@ -93,10 +94,12 @@ describe "HttpController", ->
|
|||
_id: @docs[0]._id.toString()
|
||||
lines: @docs[0].lines
|
||||
rev: @docs[0].rev
|
||||
deleted: false
|
||||
}, {
|
||||
_id: @docs[1]._id.toString()
|
||||
lines: @docs[1].lines
|
||||
rev: @docs[1].rev
|
||||
deleted: false
|
||||
}])
|
||||
.should.equal true
|
||||
|
||||
|
@ -124,10 +127,12 @@ describe "HttpController", ->
|
|||
_id: @docs[0]._id.toString()
|
||||
lines: @docs[0].lines
|
||||
rev: @docs[0].rev
|
||||
deleted: false
|
||||
}, {
|
||||
_id: @docs[2]._id.toString()
|
||||
lines: @docs[2].lines
|
||||
rev: @docs[2].rev
|
||||
deleted: false
|
||||
}])
|
||||
.should.equal true
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ describe "MongoManager", ->
|
|||
db: @db = { projects: {}, docs: {} }
|
||||
ObjectId: ObjectId
|
||||
@project_id = ObjectId().toString()
|
||||
@doc_id = ObjectId().toString()
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "findProject", ->
|
||||
|
@ -19,7 +20,7 @@ describe "MongoManager", ->
|
|||
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
||||
@MongoManager.findProject @project_id, @callback
|
||||
|
||||
it "should find the project without the doc lines", ->
|
||||
it "should find the project", ->
|
||||
@db.projects.find
|
||||
.calledWith({
|
||||
_id: ObjectId(@project_id)
|
||||
|
@ -29,6 +30,22 @@ describe "MongoManager", ->
|
|||
it "should call the callback with the project", ->
|
||||
@callback.calledWith(null, @project).should.equal true
|
||||
|
||||
describe "findDoc", ->
|
||||
beforeEach ->
|
||||
@doc = { name: "mock-doc" }
|
||||
@db.docs.find = sinon.stub().callsArgWith(2, null, [@doc])
|
||||
@MongoManager.findDoc @doc_id, @callback
|
||||
|
||||
it "should find the doc", ->
|
||||
@db.docs.find
|
||||
.calledWith({
|
||||
_id: ObjectId(@doc_id)
|
||||
}, {})
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with the doc", ->
|
||||
@callback.calledWith(null, @doc).should.equal true
|
||||
|
||||
describe "updateDoc", ->
|
||||
beforeEach ->
|
||||
@lines = ["mock-lines"]
|
||||
|
@ -53,7 +70,6 @@ describe "MongoManager", ->
|
|||
|
||||
describe "insertDoc", ->
|
||||
beforeEach ->
|
||||
@doc_id = ObjectId().toString()
|
||||
@lines = ["mock-lines"]
|
||||
@db.docs.insert = sinon.stub().callsArg(1)
|
||||
@MongoManager.insertDoc @project_id, @doc_id, lines: @lines, @callback
|
||||
|
|
Loading…
Reference in a new issue