mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
version entity deletions in ProjectEntityHandler
This commit is contained in:
parent
81c061c6a7
commit
475e84b039
2 changed files with 58 additions and 32 deletions
|
@ -423,7 +423,7 @@ module.exports = ProjectEntityHandler =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
projectLocator.findElement {project: project, element_id: entity_id, type: entityType}, (error, entity, path)=>
|
projectLocator.findElement {project: project, element_id: entity_id, type: entityType}, (error, entity, path)=>
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
ProjectEntityHandler._cleanUpEntity project, entity, entityType, (error) ->
|
ProjectEntityHandler._cleanUpEntity project, entity, entityType, path.fileSystem, (error) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
tpdsUpdateSender.deleteEntity project_id:project_id, path:path.fileSystem, project_name:project.name, (error) ->
|
tpdsUpdateSender.deleteEntity project_id:project_id, path:path.fileSystem, project_name:project.name, (error) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
|
@ -456,17 +456,17 @@ module.exports = ProjectEntityHandler =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
DocumentUpdaterHandler.updateProjectStructure project_id, userId, {oldDocs, newDocs, oldFiles, newFiles}, callback
|
DocumentUpdaterHandler.updateProjectStructure project_id, userId, {oldDocs, newDocs, oldFiles, newFiles}, callback
|
||||||
|
|
||||||
_cleanUpEntity: (project, entity, entityType, callback = (error) ->) ->
|
_cleanUpEntity: (project, entity, entityType, path, callback = (error) ->) ->
|
||||||
if(entityType.indexOf("file") != -1)
|
if(entityType.indexOf("file") != -1)
|
||||||
ProjectEntityHandler._cleanUpFile project, entity, callback
|
ProjectEntityHandler._cleanUpFile project, entity, path, callback
|
||||||
else if (entityType.indexOf("doc") != -1)
|
else if (entityType.indexOf("doc") != -1)
|
||||||
ProjectEntityHandler._cleanUpDoc project, entity, callback
|
ProjectEntityHandler._cleanUpDoc project, entity, path, callback
|
||||||
else if (entityType.indexOf("folder") != -1)
|
else if (entityType.indexOf("folder") != -1)
|
||||||
ProjectEntityHandler._cleanUpFolder project, entity, callback
|
ProjectEntityHandler._cleanUpFolder project, entity, path, callback
|
||||||
else
|
else
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
_cleanUpDoc: (project, doc, callback = (error) ->) ->
|
_cleanUpDoc: (project, doc, path, callback = (error) ->) ->
|
||||||
project_id = project._id.toString()
|
project_id = project._id.toString()
|
||||||
doc_id = doc._id.toString()
|
doc_id = doc._id.toString()
|
||||||
unsetRootDocIfRequired = (callback) =>
|
unsetRootDocIfRequired = (callback) =>
|
||||||
|
@ -483,26 +483,33 @@ module.exports = ProjectEntityHandler =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
DocstoreManager.deleteDoc project_id, doc_id, (error) ->
|
DocstoreManager.deleteDoc project_id, doc_id, (error) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
callback()
|
changes = oldDocs: [ {doc, path} ]
|
||||||
|
DocumentUpdaterHandler.updateProjectStructure project_id, null, changes, callback
|
||||||
|
|
||||||
_cleanUpFile: (project, file, callback = (error) ->) ->
|
_cleanUpFile: (project, file, path, callback = (error) ->) ->
|
||||||
project_id = project._id.toString()
|
project_id = project._id.toString()
|
||||||
file_id = file._id.toString()
|
file_id = file._id.toString()
|
||||||
FileStoreHandler.deleteFile project_id, file_id, callback
|
FileStoreHandler.deleteFile project_id, file_id, (error) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
changes = oldFiles: [ {file, path} ]
|
||||||
|
DocumentUpdaterHandler.updateProjectStructure project_id, null, changes, callback
|
||||||
|
|
||||||
_cleanUpFolder: (project, folder, callback = (error) ->) ->
|
_cleanUpFolder: (project, folder, folderPath, callback = (error) ->) ->
|
||||||
jobs = []
|
jobs = []
|
||||||
for doc in folder.docs
|
for doc in folder.docs
|
||||||
do (doc) ->
|
do (doc) ->
|
||||||
jobs.push (callback) -> ProjectEntityHandler._cleanUpDoc project, doc, callback
|
docPath = path.join(folderPath, doc.name)
|
||||||
|
jobs.push (callback) -> ProjectEntityHandler._cleanUpDoc project, doc, docPath, callback
|
||||||
|
|
||||||
for file in folder.fileRefs
|
for file in folder.fileRefs
|
||||||
do (file) ->
|
do (file) ->
|
||||||
jobs.push (callback) -> ProjectEntityHandler._cleanUpFile project, file, callback
|
filePath = path.join(folderPath, file.name)
|
||||||
|
jobs.push (callback) -> ProjectEntityHandler._cleanUpFile project, file, filePath, callback
|
||||||
|
|
||||||
for childFolder in folder.folders
|
for childFolder in folder.folders
|
||||||
do (childFolder) ->
|
do (childFolder) ->
|
||||||
jobs.push (callback) -> ProjectEntityHandler._cleanUpFolder project, childFolder, callback
|
folderPath = path.join(folderPath, childFolder.name)
|
||||||
|
jobs.push (callback) -> ProjectEntityHandler._cleanUpFolder project, childFolder, folderPath, callback
|
||||||
|
|
||||||
async.series jobs, callback
|
async.series jobs, callback
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
@ProjectGetter.getProject.callsArgWith(2, null, @project)
|
@ProjectGetter.getProject.callsArgWith(2, null, @project)
|
||||||
@tpdsUpdateSender.deleteEntity = sinon.stub().callsArg(1)
|
@tpdsUpdateSender.deleteEntity = sinon.stub().callsArg(1)
|
||||||
@ProjectEntityHandler._removeElementFromMongoArray = sinon.stub().callsArg(3)
|
@ProjectEntityHandler._removeElementFromMongoArray = sinon.stub().callsArg(3)
|
||||||
@ProjectEntityHandler._cleanUpEntity = sinon.stub().callsArg(3)
|
@ProjectEntityHandler._cleanUpEntity = sinon.stub().callsArg(4)
|
||||||
@path = mongo: "mongo.path", fileSystem: "/file/system/path"
|
@path = mongo: "mongo.path", fileSystem: "/file/system/path"
|
||||||
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, @entity = { _id: entity_id }, @path)
|
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, @entity = { _id: entity_id }, @path)
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
|
|
||||||
it "should clean up the entity from the rest of the system", ->
|
it "should clean up the entity from the rest of the system", ->
|
||||||
@ProjectEntityHandler._cleanUpEntity
|
@ProjectEntityHandler._cleanUpEntity
|
||||||
.calledWith(@project, @entity, @type)
|
.calledWith(@project, @entity, @type, @path.fileSystem)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "_cleanUpEntity", ->
|
describe "_cleanUpEntity", ->
|
||||||
|
@ -193,7 +193,9 @@ describe 'ProjectEntityHandler', ->
|
||||||
|
|
||||||
describe "a file", ->
|
describe "a file", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@ProjectEntityHandler._cleanUpEntity @project, _id: @entity_id, 'file', done
|
@path = "/file/system/path.png"
|
||||||
|
@entity = _id: @entity_id
|
||||||
|
@ProjectEntityHandler._cleanUpEntity @project, @entity, 'file', @path, done
|
||||||
|
|
||||||
it "should delete the file from FileStoreHandler", ->
|
it "should delete the file from FileStoreHandler", ->
|
||||||
@FileStoreHandler.deleteFile.calledWith(project_id, @entity_id).should.equal true
|
@FileStoreHandler.deleteFile.calledWith(project_id, @entity_id).should.equal true
|
||||||
|
@ -201,38 +203,48 @@ describe 'ProjectEntityHandler', ->
|
||||||
it "should not attempt to delete from the document updater", ->
|
it "should not attempt to delete from the document updater", ->
|
||||||
@documentUpdaterHandler.deleteDoc.called.should.equal false
|
@documentUpdaterHandler.deleteDoc.called.should.equal false
|
||||||
|
|
||||||
|
it "should should send the update to the doc updater", ->
|
||||||
|
oldFiles = [ file: @entity, path: @path ]
|
||||||
|
@documentUpdaterHandler.updateProjectStructure
|
||||||
|
.calledWith(project_id, null, {oldFiles})
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
describe "a doc", ->
|
describe "a doc", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@ProjectEntityHandler._cleanUpDoc = sinon.stub().callsArg(2)
|
@path = "/file/system/path.tex"
|
||||||
@ProjectEntityHandler._cleanUpEntity @project, @entity = {_id: @entity_id}, 'doc', done
|
@ProjectEntityHandler._cleanUpDoc = sinon.stub().callsArg(3)
|
||||||
|
@entity = {_id: @entity_id}
|
||||||
|
@ProjectEntityHandler._cleanUpEntity @project, @entity, 'doc', @path, done
|
||||||
|
|
||||||
it "should clean up the doc", ->
|
it "should clean up the doc", ->
|
||||||
@ProjectEntityHandler._cleanUpDoc
|
@ProjectEntityHandler._cleanUpDoc
|
||||||
.calledWith(@project, @entity)
|
.calledWith(@project, @entity, @path)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "a folder", ->
|
describe "a folder", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@folder =
|
@folder =
|
||||||
folders: [
|
folders: [
|
||||||
fileRefs: [ @file1 = {_id: "file-id-1" } ]
|
name: "subfolder"
|
||||||
docs: [ @doc1 = { _id: "doc-id-1" } ]
|
fileRefs: [ @file1 = { _id: "file-id-1", name: "file-name-1"} ]
|
||||||
|
docs: [ @doc1 = { _id: "doc-id-1", name: "doc-name-1" } ]
|
||||||
folders: []
|
folders: []
|
||||||
]
|
]
|
||||||
fileRefs: [ @file2 = { _id: "file-id-2" } ]
|
fileRefs: [ @file2 = { _id: "file-id-2", name: "file-name-2" } ]
|
||||||
docs: [ @doc2 = { _id: "doc-id-2" } ]
|
docs: [ @doc2 = { _id: "doc-id-2", name: "doc-name-2" } ]
|
||||||
|
|
||||||
@ProjectEntityHandler._cleanUpDoc = sinon.stub().callsArg(2)
|
@ProjectEntityHandler._cleanUpDoc = sinon.stub().callsArg(3)
|
||||||
@ProjectEntityHandler._cleanUpFile = sinon.stub().callsArg(2)
|
@ProjectEntityHandler._cleanUpFile = sinon.stub().callsArg(3)
|
||||||
@ProjectEntityHandler._cleanUpEntity @project, @folder, "folder", done
|
path = "/folder"
|
||||||
|
@ProjectEntityHandler._cleanUpEntity @project, @folder, "folder", path, done
|
||||||
|
|
||||||
it "should clean up all sub files", ->
|
it "should clean up all sub files", ->
|
||||||
@ProjectEntityHandler._cleanUpFile.calledWith(@project, @file1).should.equal true
|
@ProjectEntityHandler._cleanUpFile.calledWith(@project, @file1, "/folder/subfolder/file-name-1").should.equal true
|
||||||
@ProjectEntityHandler._cleanUpFile.calledWith(@project, @file2).should.equal true
|
@ProjectEntityHandler._cleanUpFile.calledWith(@project, @file2, "/folder/file-name-2").should.equal true
|
||||||
|
|
||||||
it "should clean up all sub docs", ->
|
it "should clean up all sub docs", ->
|
||||||
@ProjectEntityHandler._cleanUpDoc.calledWith(@project, @doc1).should.equal true
|
@ProjectEntityHandler._cleanUpDoc.calledWith(@project, @doc1, "/folder/subfolder/doc-name-1").should.equal true
|
||||||
@ProjectEntityHandler._cleanUpDoc.calledWith(@project, @doc2).should.equal true
|
@ProjectEntityHandler._cleanUpDoc.calledWith(@project, @doc2, "/folder/doc-name-2").should.equal true
|
||||||
|
|
||||||
describe 'moveEntity', ->
|
describe 'moveEntity', ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@ -1116,6 +1128,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
@doc =
|
@doc =
|
||||||
_id: ObjectId()
|
_id: ObjectId()
|
||||||
name: "test.tex"
|
name: "test.tex"
|
||||||
|
@path = "/path/to/doc"
|
||||||
@ProjectEntityHandler.unsetRootDoc = sinon.stub().callsArg(1)
|
@ProjectEntityHandler.unsetRootDoc = sinon.stub().callsArg(1)
|
||||||
@ProjectEntityHandler._insertDeletedDocReference = sinon.stub().callsArg(2)
|
@ProjectEntityHandler._insertDeletedDocReference = sinon.stub().callsArg(2)
|
||||||
@documentUpdaterHandler.deleteDoc = sinon.stub().callsArg(2)
|
@documentUpdaterHandler.deleteDoc = sinon.stub().callsArg(2)
|
||||||
|
@ -1125,7 +1138,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
describe "when the doc is the root doc", ->
|
describe "when the doc is the root doc", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@project.rootDoc_id = @doc._id
|
@project.rootDoc_id = @doc._id
|
||||||
@ProjectEntityHandler._cleanUpDoc @project, @doc, @callback
|
@ProjectEntityHandler._cleanUpDoc @project, @doc, @path, @callback
|
||||||
|
|
||||||
it "should unset the root doc", ->
|
it "should unset the root doc", ->
|
||||||
@ProjectEntityHandler.unsetRootDoc
|
@ProjectEntityHandler.unsetRootDoc
|
||||||
|
@ -1146,13 +1159,19 @@ describe 'ProjectEntityHandler', ->
|
||||||
.calledWith(project_id, @doc._id.toString())
|
.calledWith(project_id, @doc._id.toString())
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
it "should should send the update to the doc updater", ->
|
||||||
|
oldDocs = [ doc: @doc, path: @path ]
|
||||||
|
@documentUpdaterHandler.updateProjectStructure
|
||||||
|
.calledWith(project_id, null, {oldDocs})
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
it "should call the callback", ->
|
it "should call the callback", ->
|
||||||
@callback.called.should.equal true
|
@callback.called.should.equal true
|
||||||
|
|
||||||
describe "when the doc is not the root doc", ->
|
describe "when the doc is not the root doc", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@project.rootDoc_id = ObjectId()
|
@project.rootDoc_id = ObjectId()
|
||||||
@ProjectEntityHandler._cleanUpDoc @project, @doc, @callback
|
@ProjectEntityHandler._cleanUpDoc @project, @doc, @path, @callback
|
||||||
|
|
||||||
it "should not unset the root doc", ->
|
it "should not unset the root doc", ->
|
||||||
@ProjectEntityHandler.unsetRootDoc.called.should.equal false
|
@ProjectEntityHandler.unsetRootDoc.called.should.equal false
|
||||||
|
|
Loading…
Reference in a new issue