mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 17:03:43 -05:00
Merge pull request #535 from sharelatex/bg-fix-project-structure-updates-for-folder-delete
fix project structure version when deleting folder
This commit is contained in:
commit
3144922bcd
2 changed files with 47 additions and 24 deletions
|
@ -405,6 +405,8 @@ module.exports = ProjectEntityUpdateHandler = self =
|
||||||
DocumentUpdaterHandler.resyncProjectHistory project_id, projectHistoryId, docs, files, callback
|
DocumentUpdaterHandler.resyncProjectHistory project_id, projectHistoryId, docs, files, callback
|
||||||
|
|
||||||
_cleanUpEntity: (project, entity, entityType, path, userId, callback = (error) ->) ->
|
_cleanUpEntity: (project, entity, entityType, path, userId, callback = (error) ->) ->
|
||||||
|
self._updateProjectStructureWithDeletedEntity project, entity, entityType, path, userId, (error) ->
|
||||||
|
return callback(error) if error?
|
||||||
if(entityType.indexOf("file") != -1)
|
if(entityType.indexOf("file") != -1)
|
||||||
self._cleanUpFile project, entity, path, userId, callback
|
self._cleanUpFile project, entity, path, userId, callback
|
||||||
else if (entityType.indexOf("doc") != -1)
|
else if (entityType.indexOf("doc") != -1)
|
||||||
|
@ -414,6 +416,31 @@ module.exports = ProjectEntityUpdateHandler = self =
|
||||||
else
|
else
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
|
# Note: the _cleanUpEntity code and _updateProjectStructureWithDeletedEntity
|
||||||
|
# methods both need to recursively iterate over the entities in folder.
|
||||||
|
# These are currently using separate implementations of the recursion. In
|
||||||
|
# future, these could be simplified using a common project entity iterator.
|
||||||
|
_updateProjectStructureWithDeletedEntity: (project, entity, entityType, entityPath, userId, callback = (error) ->) ->
|
||||||
|
# compute the changes to the project structure
|
||||||
|
if(entityType.indexOf("file") != -1)
|
||||||
|
changes = oldFiles: [ {file: entity, path: entityPath} ]
|
||||||
|
else if (entityType.indexOf("doc") != -1)
|
||||||
|
changes = oldDocs: [ {doc: entity, path: entityPath} ]
|
||||||
|
else if (entityType.indexOf("folder") != -1)
|
||||||
|
changes = {oldDocs: [], oldFiles: []}
|
||||||
|
_recurseFolder = (folder, folderPath) ->
|
||||||
|
for doc in folder.docs
|
||||||
|
changes.oldDocs.push {doc, path: path.join(folderPath, doc.name)}
|
||||||
|
for file in folder.fileRefs
|
||||||
|
changes.oldFiles.push {file, path: path.join(folderPath, file.name)}
|
||||||
|
for childFolder in folder.folders
|
||||||
|
_recurseFolder(childFolder, path.join(folderPath, childFolder.name))
|
||||||
|
_recurseFolder entity, entityPath
|
||||||
|
# now send the project structure changes to the docupdater
|
||||||
|
project_id = project._id.toString()
|
||||||
|
projectHistoryId = project.overleaf?.history?.id
|
||||||
|
DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, changes, callback
|
||||||
|
|
||||||
_cleanUpDoc: (project, doc, path, userId, callback = (error) ->) ->
|
_cleanUpDoc: (project, doc, path, userId, callback = (error) ->) ->
|
||||||
project_id = project._id.toString()
|
project_id = project._id.toString()
|
||||||
doc_id = doc._id.toString()
|
doc_id = doc._id.toString()
|
||||||
|
@ -429,21 +456,10 @@ module.exports = ProjectEntityUpdateHandler = self =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
DocumentUpdaterHandler.deleteDoc project_id, doc_id, (error) ->
|
DocumentUpdaterHandler.deleteDoc project_id, doc_id, (error) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
DocstoreManager.deleteDoc project_id, doc_id, (error) ->
|
DocstoreManager.deleteDoc project_id, doc_id, callback
|
||||||
return callback(error) if error?
|
|
||||||
changes = oldDocs: [ {doc, path} ]
|
|
||||||
projectHistoryId = project.overleaf?.history?.id
|
|
||||||
DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, changes, callback
|
|
||||||
|
|
||||||
_cleanUpFile: (project, file, path, userId, callback = (error) ->) ->
|
_cleanUpFile: (project, file, path, userId, callback = (error) ->) ->
|
||||||
ProjectEntityMongoUpdateHandler._insertDeletedFileReference project._id, file, (error) ->
|
ProjectEntityMongoUpdateHandler._insertDeletedFileReference project._id, file, callback
|
||||||
return callback(error) if error?
|
|
||||||
project_id = project._id.toString()
|
|
||||||
projectHistoryId = project.overleaf?.history?.id
|
|
||||||
changes = oldFiles: [ {file, path} ]
|
|
||||||
# we are now keeping a copy of every file versio so we no longer delete
|
|
||||||
# the file from the filestore
|
|
||||||
DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, changes, callback
|
|
||||||
|
|
||||||
_cleanUpFolder: (project, folder, folderPath, userId, callback = (error) ->) ->
|
_cleanUpFolder: (project, folder, folderPath, userId, callback = (error) ->) ->
|
||||||
jobs = []
|
jobs = []
|
||||||
|
|
|
@ -872,6 +872,12 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
.calledWith(@project, @entity, @path, userId)
|
.calledWith(@project, @entity, @path, userId)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
it "should should send the update to the doc updater", ->
|
||||||
|
oldDocs = [ doc: @entity, path: @path ]
|
||||||
|
@DocumentUpdaterHandler.updateProjectStructure
|
||||||
|
.calledWith(project_id, projectHistoryId, userId, {oldDocs})
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
describe "a folder", ->
|
describe "a folder", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@folder =
|
@folder =
|
||||||
|
@ -905,6 +911,13 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
.calledWith(@project, @doc2, "/folder/doc-name-2", userId)
|
.calledWith(@project, @doc2, "/folder/doc-name-2", userId)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
it "should should send one update to the doc updater for all docs and files", ->
|
||||||
|
oldFiles = [ {file: @file2, path: "/folder/file-name-2"}, {file: @file1, path: "/folder/subfolder/file-name-1"} ]
|
||||||
|
oldDocs = [ {doc: @doc2, path: "/folder/doc-name-2"}, { doc: @doc1, path: "/folder/subfolder/doc-name-1"} ]
|
||||||
|
@DocumentUpdaterHandler.updateProjectStructure
|
||||||
|
.calledWith(project_id, projectHistoryId, userId, {oldFiles, oldDocs})
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
describe "_cleanUpDoc", ->
|
describe "_cleanUpDoc", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@doc =
|
@doc =
|
||||||
|
@ -941,12 +954,6 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
.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, projectHistoryId, userId, {oldDocs})
|
|
||||||
.should.equal true
|
|
||||||
|
|
||||||
it "should call the callback", ->
|
it "should call the callback", ->
|
||||||
@callback.called.should.equal true
|
@callback.called.should.equal true
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue