mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge branch 'ja-delete-refactor' into ja-track-changes
Conflicts: test/acceptance/coffee/ArchiveDocsTests.coffee
This commit is contained in:
commit
a6ec672d84
9 changed files with 57 additions and 33 deletions
|
@ -11,7 +11,7 @@ thirtySeconds = 30 * 1000
|
||||||
module.exports = DocArchive =
|
module.exports = DocArchive =
|
||||||
|
|
||||||
archiveAllDocs: (project_id, callback = (err, docs) ->) ->
|
archiveAllDocs: (project_id, callback = (err, docs) ->) ->
|
||||||
MongoManager.getProjectsDocs project_id, (err, docs) ->
|
MongoManager.getProjectsDocs project_id, {include_deleted: true}, (err, docs) ->
|
||||||
if err?
|
if err?
|
||||||
return callback(err)
|
return callback(err)
|
||||||
else if !docs?
|
else if !docs?
|
||||||
|
|
|
@ -31,9 +31,9 @@ module.exports = DocManager =
|
||||||
else
|
else
|
||||||
callback err, doc
|
callback err, doc
|
||||||
|
|
||||||
getAllDocs: (project_id, callback = (error, docs) ->) ->
|
getAllNonDeletedDocs: (project_id, callback = (error, docs) ->) ->
|
||||||
DocArchive.unArchiveAllDocs project_id, (error) ->
|
DocArchive.unArchiveAllDocs project_id, (error) ->
|
||||||
MongoManager.getProjectsDocs project_id, (error, docs) ->
|
MongoManager.getProjectsDocs project_id, {include_deleted: false}, (error, docs) ->
|
||||||
if err?
|
if err?
|
||||||
return callback(error)
|
return callback(error)
|
||||||
else if !docs?
|
else if !docs?
|
||||||
|
|
|
@ -35,7 +35,7 @@ module.exports = HttpController =
|
||||||
getAllDocs: (req, res, next = (error) ->) ->
|
getAllDocs: (req, res, next = (error) ->) ->
|
||||||
project_id = req.params.project_id
|
project_id = req.params.project_id
|
||||||
logger.log project_id: project_id, "getting all docs"
|
logger.log project_id: project_id, "getting all docs"
|
||||||
DocManager.getAllDocs project_id, (error, docs = []) ->
|
DocManager.getAllNonDeletedDocs project_id, (error, docs = []) ->
|
||||||
return next(error) if error?
|
return next(error) if error?
|
||||||
docViews = []
|
docViews = []
|
||||||
for doc in docs
|
for doc in docs
|
||||||
|
|
|
@ -6,8 +6,11 @@ module.exports = MongoManager =
|
||||||
db.docs.find {_id: ObjectId(doc_id.toString()), project_id: ObjectId(project_id.toString())}, {}, (error, docs = []) ->
|
db.docs.find {_id: ObjectId(doc_id.toString()), project_id: ObjectId(project_id.toString())}, {}, (error, docs = []) ->
|
||||||
callback error, docs[0]
|
callback error, docs[0]
|
||||||
|
|
||||||
getProjectsDocs: (project_id, callback)->
|
getProjectsDocs: (project_id, options = {include_deleted: true}, callback)->
|
||||||
db.docs.find {project_id: ObjectId(project_id.toString()), deleted: { $ne: true }}, {}, callback
|
query = {project_id: ObjectId(project_id.toString())}
|
||||||
|
if !options.include_deleted
|
||||||
|
query.deleted = { $ne: true }
|
||||||
|
db.docs.find query, {}, callback
|
||||||
|
|
||||||
getArchivedProjectDocs: (project_id, callback)->
|
getArchivedProjectDocs: (project_id, callback)->
|
||||||
query =
|
query =
|
||||||
|
|
|
@ -33,6 +33,9 @@ describe "Archiving", ->
|
||||||
DocstoreClient.createDoc @project_id, doc._id, doc.lines, @version, @ranges, (err)=>
|
DocstoreClient.createDoc @project_id, doc._id, doc.lines, @version, @ranges, (err)=>
|
||||||
doc.lines[0] = doc.lines[0]+" added"
|
doc.lines[0] = doc.lines[0]+" added"
|
||||||
DocstoreClient.updateDoc @project_id, doc._id, doc.lines, @version, @ranges, callback
|
DocstoreClient.updateDoc @project_id, doc._id, doc.lines, @version, @ranges, callback
|
||||||
|
# Make sure archiving works on deleted docs too
|
||||||
|
jobs.push (cb) =>
|
||||||
|
DocstoreClient.deleteDoc @project_id, @docs[2]._id, cb
|
||||||
async.series jobs, done
|
async.series jobs, done
|
||||||
|
|
||||||
afterEach (done) ->
|
afterEach (done) ->
|
||||||
|
@ -139,10 +142,11 @@ describe "Archiving", ->
|
||||||
|
|
||||||
describe "Unarchiving", ->
|
describe "Unarchiving", ->
|
||||||
it "should unarchive all the docs", (done) ->
|
it "should unarchive all the docs", (done) ->
|
||||||
|
non_deleted_docs = @docs.slice(0,2)
|
||||||
DocstoreClient.archiveAllDoc @project_id, (error, res) =>
|
DocstoreClient.archiveAllDoc @project_id, (error, res) =>
|
||||||
DocstoreClient.getAllDocs @project_id, (error, res, docs) =>
|
DocstoreClient.getAllDocs @project_id, (error, res, docs) =>
|
||||||
throw error if error?
|
throw error if error?
|
||||||
docs.length.should.equal @docs.length
|
docs.length.should.equal non_deleted_docs.length
|
||||||
for doc, i in docs
|
for doc, i in non_deleted_docs
|
||||||
doc.lines.should.deep.equal @docs[i].lines
|
doc.lines.should.deep.equal @docs[i].lines
|
||||||
done()
|
done()
|
||||||
|
|
|
@ -64,7 +64,7 @@ describe "DocArchiveManager", ->
|
||||||
@MongoManager =
|
@MongoManager =
|
||||||
markDocAsArchived: sinon.stub().callsArgWith(2, null)
|
markDocAsArchived: sinon.stub().callsArgWith(2, null)
|
||||||
upsertIntoDocCollection: sinon.stub().callsArgWith(3, null)
|
upsertIntoDocCollection: sinon.stub().callsArgWith(3, null)
|
||||||
getProjectsDocs: sinon.stub().callsArgWith(1, null, @mongoDocs)
|
getProjectsDocs: sinon.stub().callsArgWith(2, null, @mongoDocs)
|
||||||
getArchivedProjectDocs: sinon.stub().callsArgWith(1, null, @mongoDocs)
|
getArchivedProjectDocs: sinon.stub().callsArgWith(1, null, @mongoDocs)
|
||||||
|
|
||||||
@requires =
|
@requires =
|
||||||
|
@ -127,7 +127,7 @@ describe "DocArchiveManager", ->
|
||||||
describe "archiveAllDocs", ->
|
describe "archiveAllDocs", ->
|
||||||
|
|
||||||
it "should archive all project docs which are not in s3", (done)->
|
it "should archive all project docs which are not in s3", (done)->
|
||||||
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(1, null, @mongoDocs)
|
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(2, null, @mongoDocs)
|
||||||
@DocArchiveManager.archiveDoc = sinon.stub().callsArgWith(2, null)
|
@DocArchiveManager.archiveDoc = sinon.stub().callsArgWith(2, null)
|
||||||
|
|
||||||
@DocArchiveManager.archiveAllDocs @project_id, (err)=>
|
@DocArchiveManager.archiveAllDocs @project_id, (err)=>
|
||||||
|
@ -142,14 +142,14 @@ describe "DocArchiveManager", ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should return error if have no docs", (done)->
|
it "should return error if have no docs", (done)->
|
||||||
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(1, null, null)
|
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(2, null, null)
|
||||||
|
|
||||||
@DocArchiveManager.archiveAllDocs @project_id, (err)=>
|
@DocArchiveManager.archiveAllDocs @project_id, (err)=>
|
||||||
should.exist err
|
should.exist err
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should return the error", (done)->
|
it "should return the error", (done)->
|
||||||
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(1, @error, null)
|
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(2, @error, null)
|
||||||
|
|
||||||
@DocArchiveManager.archiveAllDocs @project_id, (err)=>
|
@DocArchiveManager.archiveAllDocs @project_id, (err)=>
|
||||||
err.should.equal @error
|
err.should.equal @error
|
||||||
|
@ -163,7 +163,7 @@ describe "DocArchiveManager", ->
|
||||||
while --numberOfDocs != 0
|
while --numberOfDocs != 0
|
||||||
@mongoDocs.push({inS3:true, _id: ObjectId()})
|
@mongoDocs.push({inS3:true, _id: ObjectId()})
|
||||||
|
|
||||||
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(1, null, @mongoDocs)
|
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(2, null, @mongoDocs)
|
||||||
@DocArchiveManager.archiveDoc = sinon.stub().callsArgWith(2, null)
|
@DocArchiveManager.archiveDoc = sinon.stub().callsArgWith(2, null)
|
||||||
|
|
||||||
it "should not throw and error", (done)->
|
it "should not throw and error", (done)->
|
||||||
|
|
|
@ -100,17 +100,17 @@ describe "DocManager", ->
|
||||||
.calledWith(new Errors.NotFoundError("No such doc: #{@doc_id} in project #{@project_id}"))
|
.calledWith(new Errors.NotFoundError("No such doc: #{@doc_id} in project #{@project_id}"))
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "getAllDocs", ->
|
describe "getAllNonDeletedDocs", ->
|
||||||
describe "when the project exists", ->
|
describe "when the project exists", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@docs = [{ _id: @doc_id, project_id: @project_id, lines: ["mock-lines"] }]
|
@docs = [{ _id: @doc_id, project_id: @project_id, lines: ["mock-lines"] }]
|
||||||
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(1, null, @docs)
|
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(2, null, @docs)
|
||||||
@DocArchiveManager.unArchiveAllDocs = sinon.stub().callsArgWith(1, null, @docs)
|
@DocArchiveManager.unArchiveAllDocs = sinon.stub().callsArgWith(1, null, @docs)
|
||||||
@DocManager.getAllDocs @project_id, @callback
|
@DocManager.getAllNonDeletedDocs @project_id, @callback
|
||||||
|
|
||||||
it "should get the project from the database", ->
|
it "should get the project from the database", ->
|
||||||
@MongoManager.getProjectsDocs
|
@MongoManager.getProjectsDocs
|
||||||
.calledWith(@project_id)
|
.calledWith(@project_id, {include_deleted: false})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return the docs", ->
|
it "should return the docs", ->
|
||||||
|
@ -118,9 +118,9 @@ describe "DocManager", ->
|
||||||
|
|
||||||
describe "when there are no docs for the project", ->
|
describe "when there are no docs for the project", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(1, null, null)
|
@MongoManager.getProjectsDocs = sinon.stub().callsArgWith(2, null, null)
|
||||||
@DocArchiveManager.unArchiveAllDocs = sinon.stub().callsArgWith(1, null, null)
|
@DocArchiveManager.unArchiveAllDocs = sinon.stub().callsArgWith(1, null, null)
|
||||||
@DocManager.getAllDocs @project_id, @callback
|
@DocManager.getAllNonDeletedDocs @project_id, @callback
|
||||||
|
|
||||||
it "should return a NotFoundError", ->
|
it "should return a NotFoundError", ->
|
||||||
@callback
|
@callback
|
||||||
|
|
|
@ -120,11 +120,11 @@ describe "HttpController", ->
|
||||||
lines: ["mock", "lines", "two"]
|
lines: ["mock", "lines", "two"]
|
||||||
rev: 4
|
rev: 4
|
||||||
}]
|
}]
|
||||||
@DocManager.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
|
@DocManager.getAllNonDeletedDocs = sinon.stub().callsArgWith(1, null, @docs)
|
||||||
@HttpController.getAllDocs @req, @res, @next
|
@HttpController.getAllDocs @req, @res, @next
|
||||||
|
|
||||||
it "should get all the docs", ->
|
it "should get all the (non-deleted) docs", ->
|
||||||
@DocManager.getAllDocs
|
@DocManager.getAllNonDeletedDocs
|
||||||
.calledWith(@project_id)
|
.calledWith(@project_id)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ describe "HttpController", ->
|
||||||
lines: ["mock", "lines", "two"]
|
lines: ["mock", "lines", "two"]
|
||||||
rev: 4
|
rev: 4
|
||||||
}]
|
}]
|
||||||
@DocManager.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
|
@DocManager.getAllNonDeletedDocs = sinon.stub().callsArgWith(1, null, @docs)
|
||||||
@HttpController.getAllDocs @req, @res, @next
|
@HttpController.getAllDocs @req, @res, @next
|
||||||
|
|
||||||
it "should return the non null docs as JSON", ->
|
it "should return the non null docs as JSON", ->
|
||||||
|
|
|
@ -40,7 +40,10 @@ describe "MongoManager", ->
|
||||||
@doc3 = { name: "mock-doc3" }
|
@doc3 = { name: "mock-doc3" }
|
||||||
@doc4 = { name: "mock-doc4" }
|
@doc4 = { name: "mock-doc4" }
|
||||||
@db.docs.find = sinon.stub().callsArgWith(2, null, [@doc, @doc3, @doc4])
|
@db.docs.find = sinon.stub().callsArgWith(2, null, [@doc, @doc3, @doc4])
|
||||||
@MongoManager.getProjectsDocs @project_id, @callback
|
|
||||||
|
describe "with included_deleted = false", ->
|
||||||
|
beforeEach ->
|
||||||
|
@MongoManager.getProjectsDocs @project_id, include_deleted: false, @callback
|
||||||
|
|
||||||
it "should find the non-deleted docs via the project_id", ->
|
it "should find the non-deleted docs via the project_id", ->
|
||||||
@db.docs.find
|
@db.docs.find
|
||||||
|
@ -53,6 +56,20 @@ describe "MongoManager", ->
|
||||||
it "should call the callback with the docs", ->
|
it "should call the callback with the docs", ->
|
||||||
@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
|
@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
|
||||||
|
|
||||||
|
describe "with included_deleted = true", ->
|
||||||
|
beforeEach ->
|
||||||
|
@MongoManager.getProjectsDocs @project_id, include_deleted: true, @callback
|
||||||
|
|
||||||
|
it "should find all via the project_id", ->
|
||||||
|
@db.docs.find
|
||||||
|
.calledWith({
|
||||||
|
project_id: ObjectId(@project_id)
|
||||||
|
}, {})
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should call the callback with the docs", ->
|
||||||
|
@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
|
||||||
|
|
||||||
describe "upsertIntoDocCollection", ->
|
describe "upsertIntoDocCollection", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@db.docs.update = sinon.stub().callsArgWith(3, @stubbedErr)
|
@db.docs.update = sinon.stub().callsArgWith(3, @stubbedErr)
|
||||||
|
|
Loading…
Reference in a new issue