mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-28 22:21:32 +00:00
pass userId into _clean methods in ProjectEntityHandler
This commit is contained in:
parent
99a52d48c8
commit
2ac74b9adc
2 changed files with 38 additions and 30 deletions
|
@ -423,7 +423,7 @@ module.exports = ProjectEntityHandler =
|
|||
return callback(error) if error?
|
||||
projectLocator.findElement {project: project, element_id: entity_id, type: entityType}, (error, entity, path)=>
|
||||
return callback(error) if error?
|
||||
ProjectEntityHandler._cleanUpEntity project, entity, entityType, path.fileSystem, (error) ->
|
||||
ProjectEntityHandler._cleanUpEntity project, null, entity, entityType, path.fileSystem, (error) ->
|
||||
return callback(error) if error?
|
||||
tpdsUpdateSender.deleteEntity project_id:project_id, path:path.fileSystem, project_name:project.name, (error) ->
|
||||
return callback(error) if error?
|
||||
|
@ -456,17 +456,17 @@ module.exports = ProjectEntityHandler =
|
|||
return callback(error) if error?
|
||||
DocumentUpdaterHandler.updateProjectStructure project_id, userId, {oldDocs, newDocs, oldFiles, newFiles}, callback
|
||||
|
||||
_cleanUpEntity: (project, entity, entityType, path, callback = (error) ->) ->
|
||||
_cleanUpEntity: (project, userId, entity, entityType, path, callback = (error) ->) ->
|
||||
if(entityType.indexOf("file") != -1)
|
||||
ProjectEntityHandler._cleanUpFile project, entity, path, callback
|
||||
ProjectEntityHandler._cleanUpFile project, userId, entity, path, callback
|
||||
else if (entityType.indexOf("doc") != -1)
|
||||
ProjectEntityHandler._cleanUpDoc project, entity, path, callback
|
||||
ProjectEntityHandler._cleanUpDoc project, userId, entity, path, callback
|
||||
else if (entityType.indexOf("folder") != -1)
|
||||
ProjectEntityHandler._cleanUpFolder project, entity, path, callback
|
||||
ProjectEntityHandler._cleanUpFolder project, userId, entity, path, callback
|
||||
else
|
||||
callback()
|
||||
|
||||
_cleanUpDoc: (project, doc, path, callback = (error) ->) ->
|
||||
_cleanUpDoc: (project, userId, doc, path, callback = (error) ->) ->
|
||||
project_id = project._id.toString()
|
||||
doc_id = doc._id.toString()
|
||||
unsetRootDocIfRequired = (callback) =>
|
||||
|
@ -484,32 +484,32 @@ module.exports = ProjectEntityHandler =
|
|||
DocstoreManager.deleteDoc project_id, doc_id, (error) ->
|
||||
return callback(error) if error?
|
||||
changes = oldDocs: [ {doc, path} ]
|
||||
DocumentUpdaterHandler.updateProjectStructure project_id, null, changes, callback
|
||||
DocumentUpdaterHandler.updateProjectStructure project_id, userId, changes, callback
|
||||
|
||||
_cleanUpFile: (project, file, path, callback = (error) ->) ->
|
||||
_cleanUpFile: (project, userId, file, path, callback = (error) ->) ->
|
||||
project_id = project._id.toString()
|
||||
file_id = file._id.toString()
|
||||
FileStoreHandler.deleteFile project_id, file_id, (error) ->
|
||||
return callback(error) if error?
|
||||
changes = oldFiles: [ {file, path} ]
|
||||
DocumentUpdaterHandler.updateProjectStructure project_id, null, changes, callback
|
||||
DocumentUpdaterHandler.updateProjectStructure project_id, userId, changes, callback
|
||||
|
||||
_cleanUpFolder: (project, folder, folderPath, callback = (error) ->) ->
|
||||
_cleanUpFolder: (project, userId, folder, folderPath, callback = (error) ->) ->
|
||||
jobs = []
|
||||
for doc in folder.docs
|
||||
do (doc) ->
|
||||
docPath = path.join(folderPath, doc.name)
|
||||
jobs.push (callback) -> ProjectEntityHandler._cleanUpDoc project, doc, docPath, callback
|
||||
jobs.push (callback) -> ProjectEntityHandler._cleanUpDoc project, userId, doc, docPath, callback
|
||||
|
||||
for file in folder.fileRefs
|
||||
do (file) ->
|
||||
filePath = path.join(folderPath, file.name)
|
||||
jobs.push (callback) -> ProjectEntityHandler._cleanUpFile project, file, filePath, callback
|
||||
jobs.push (callback) -> ProjectEntityHandler._cleanUpFile project, userId, file, filePath, callback
|
||||
|
||||
for childFolder in folder.folders
|
||||
do (childFolder) ->
|
||||
folderPath = path.join(folderPath, childFolder.name)
|
||||
jobs.push (callback) -> ProjectEntityHandler._cleanUpFolder project, childFolder, folderPath, callback
|
||||
jobs.push (callback) -> ProjectEntityHandler._cleanUpFolder project, userId, childFolder, folderPath, callback
|
||||
|
||||
async.series jobs, callback
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ describe 'ProjectEntityHandler', ->
|
|||
@ProjectGetter.getProject.callsArgWith(2, null, @project)
|
||||
@tpdsUpdateSender.deleteEntity = sinon.stub().callsArg(1)
|
||||
@ProjectEntityHandler._removeElementFromMongoArray = sinon.stub().callsArg(3)
|
||||
@ProjectEntityHandler._cleanUpEntity = sinon.stub().callsArg(4)
|
||||
@ProjectEntityHandler._cleanUpEntity = sinon.stub().callsArg(5)
|
||||
@path = mongo: "mongo.path", fileSystem: "/file/system/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", ->
|
||||
@ProjectEntityHandler._cleanUpEntity
|
||||
.calledWith(@project, @entity, @type, @path.fileSystem)
|
||||
.calledWith(@project, null, @entity, @type, @path.fileSystem)
|
||||
.should.equal true
|
||||
|
||||
describe "_cleanUpEntity", ->
|
||||
|
@ -195,7 +195,7 @@ describe 'ProjectEntityHandler', ->
|
|||
beforeEach (done) ->
|
||||
@path = "/file/system/path.png"
|
||||
@entity = _id: @entity_id
|
||||
@ProjectEntityHandler._cleanUpEntity @project, @entity, 'file', @path, done
|
||||
@ProjectEntityHandler._cleanUpEntity @project, userId, @entity, 'file', @path, done
|
||||
|
||||
it "should delete the file from FileStoreHandler", ->
|
||||
@FileStoreHandler.deleteFile.calledWith(project_id, @entity_id).should.equal true
|
||||
|
@ -206,19 +206,19 @@ describe 'ProjectEntityHandler', ->
|
|||
it "should should send the update to the doc updater", ->
|
||||
oldFiles = [ file: @entity, path: @path ]
|
||||
@documentUpdaterHandler.updateProjectStructure
|
||||
.calledWith(project_id, null, {oldFiles})
|
||||
.calledWith(project_id, userId, {oldFiles})
|
||||
.should.equal true
|
||||
|
||||
describe "a doc", ->
|
||||
beforeEach (done) ->
|
||||
@path = "/file/system/path.tex"
|
||||
@ProjectEntityHandler._cleanUpDoc = sinon.stub().callsArg(3)
|
||||
@ProjectEntityHandler._cleanUpDoc = sinon.stub().callsArg(4)
|
||||
@entity = {_id: @entity_id}
|
||||
@ProjectEntityHandler._cleanUpEntity @project, @entity, 'doc', @path, done
|
||||
@ProjectEntityHandler._cleanUpEntity @project, userId, @entity, 'doc', @path, done
|
||||
|
||||
it "should clean up the doc", ->
|
||||
@ProjectEntityHandler._cleanUpDoc
|
||||
.calledWith(@project, @entity, @path)
|
||||
.calledWith(@project, userId, @entity, @path)
|
||||
.should.equal true
|
||||
|
||||
describe "a folder", ->
|
||||
|
@ -233,18 +233,26 @@ describe 'ProjectEntityHandler', ->
|
|||
fileRefs: [ @file2 = { _id: "file-id-2", name: "file-name-2" } ]
|
||||
docs: [ @doc2 = { _id: "doc-id-2", name: "doc-name-2" } ]
|
||||
|
||||
@ProjectEntityHandler._cleanUpDoc = sinon.stub().callsArg(3)
|
||||
@ProjectEntityHandler._cleanUpFile = sinon.stub().callsArg(3)
|
||||
@ProjectEntityHandler._cleanUpDoc = sinon.stub().callsArg(4)
|
||||
@ProjectEntityHandler._cleanUpFile = sinon.stub().callsArg(4)
|
||||
path = "/folder"
|
||||
@ProjectEntityHandler._cleanUpEntity @project, @folder, "folder", path, done
|
||||
@ProjectEntityHandler._cleanUpEntity @project, userId, @folder, "folder", path, done
|
||||
|
||||
it "should clean up all sub files", ->
|
||||
@ProjectEntityHandler._cleanUpFile.calledWith(@project, @file1, "/folder/subfolder/file-name-1").should.equal true
|
||||
@ProjectEntityHandler._cleanUpFile.calledWith(@project, @file2, "/folder/file-name-2").should.equal true
|
||||
@ProjectEntityHandler._cleanUpFile
|
||||
.calledWith(@project, userId, @file1, "/folder/subfolder/file-name-1")
|
||||
.should.equal true
|
||||
@ProjectEntityHandler._cleanUpFile
|
||||
.calledWith(@project, userId, @file2, "/folder/file-name-2")
|
||||
.should.equal true
|
||||
|
||||
it "should clean up all sub docs", ->
|
||||
@ProjectEntityHandler._cleanUpDoc.calledWith(@project, @doc1, "/folder/subfolder/doc-name-1").should.equal true
|
||||
@ProjectEntityHandler._cleanUpDoc.calledWith(@project, @doc2, "/folder/doc-name-2").should.equal true
|
||||
@ProjectEntityHandler._cleanUpDoc
|
||||
.calledWith(@project, userId, @doc1, "/folder/subfolder/doc-name-1")
|
||||
.should.equal true
|
||||
@ProjectEntityHandler._cleanUpDoc
|
||||
.calledWith(@project, userId, @doc2, "/folder/doc-name-2")
|
||||
.should.equal true
|
||||
|
||||
describe 'moveEntity', ->
|
||||
beforeEach ->
|
||||
|
@ -1138,7 +1146,7 @@ describe 'ProjectEntityHandler', ->
|
|||
describe "when the doc is the root doc", ->
|
||||
beforeEach ->
|
||||
@project.rootDoc_id = @doc._id
|
||||
@ProjectEntityHandler._cleanUpDoc @project, @doc, @path, @callback
|
||||
@ProjectEntityHandler._cleanUpDoc @project, userId, @doc, @path, @callback
|
||||
|
||||
it "should unset the root doc", ->
|
||||
@ProjectEntityHandler.unsetRootDoc
|
||||
|
@ -1162,7 +1170,7 @@ describe 'ProjectEntityHandler', ->
|
|||
it "should should send the update to the doc updater", ->
|
||||
oldDocs = [ doc: @doc, path: @path ]
|
||||
@documentUpdaterHandler.updateProjectStructure
|
||||
.calledWith(project_id, null, {oldDocs})
|
||||
.calledWith(project_id, userId, {oldDocs})
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback", ->
|
||||
|
@ -1171,7 +1179,7 @@ describe 'ProjectEntityHandler', ->
|
|||
describe "when the doc is not the root doc", ->
|
||||
beforeEach ->
|
||||
@project.rootDoc_id = ObjectId()
|
||||
@ProjectEntityHandler._cleanUpDoc @project, @doc, @path, @callback
|
||||
@ProjectEntityHandler._cleanUpDoc @project, userId, @doc, @path, @callback
|
||||
|
||||
it "should not unset the root doc", ->
|
||||
@ProjectEntityHandler.unsetRootDoc.called.should.equal false
|
||||
|
|
Loading…
Reference in a new issue