check for duplicates on move

This commit is contained in:
Brian Gough 2018-01-18 16:42:26 +00:00
parent 3881eb1d78
commit 4f5a5cb677

View file

@ -395,7 +395,7 @@ module.exports = ProjectEntityHandler =
return callback(err) if err? return callback(err) if err?
projectLocator.findElement {project, element_id: entity_id, type: entityType}, (err, entity, entityPath)-> projectLocator.findElement {project, element_id: entity_id, type: entityType}, (err, entity, entityPath)->
return callback(err) if err? return callback(err) if err?
self._checkValidMove project, entityType, entityPath, destFolderId, (error) -> self._checkValidMove project, entityType, entity, entityPath, destFolderId, (error) ->
return callback(error) if error? return callback(error) if error?
self.getAllEntitiesFromProject project, (error, oldDocs, oldFiles) => self.getAllEntitiesFromProject project, (error, oldDocs, oldFiles) =>
return callback(error) if error? return callback(error) if error?
@ -414,19 +414,20 @@ 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
_checkValidMove: (project, entityType, entityPath, destFolderId, callback = (error) ->) -> _checkValidMove: (project, entityType, entity, entityPath, destFolderId, callback = (error) ->) ->
return callback() if !entityType.match(/folder/)
projectLocator.findElement { project, element_id: destFolderId, type:"folder"}, (err, destEntity, destFolderPath) -> projectLocator.findElement { project, element_id: destFolderId, type:"folder"}, (err, destEntity, destFolderPath) ->
return callback(err) if err? return callback(err) if err?
# check if there is already a doc/file/folder with the same name
# in the destination folder
ProjectEntityHandler.checkElementName destEntity, entity.name, (err)->
return callback(err) if err?
if entityType.match(/folder/)
logger.log destFolderPath: destFolderPath.fileSystem, folderPath: entityPath.fileSystem, "checking folder is not moving into child folder" logger.log destFolderPath: destFolderPath.fileSystem, folderPath: entityPath.fileSystem, "checking folder is not moving into child folder"
isNestedFolder = destFolderPath.fileSystem.slice(0, entityPath.fileSystem.length) == entityPath.fileSystem isNestedFolder = destFolderPath.fileSystem.slice(0, entityPath.fileSystem.length) == entityPath.fileSystem
if isNestedFolder if isNestedFolder
callback(new Error("destination folder is a child folder of me")) return callback(new Error("destination folder is a child folder of me"))
else
callback() callback()
deleteEntity: (project_id, entity_id, entityType, userId, callback = (error) ->)-> deleteEntity: (project_id, entity_id, entityType, userId, callback = (error) ->)->
self = @ self = @
logger.log entity_id:entity_id, entityType:entityType, project_id:project_id, "deleting project entity" logger.log entity_id:entity_id, entityType:entityType, project_id:project_id, "deleting project entity"