check for duplicates in addFolder

This commit is contained in:
Brian Gough 2018-01-19 12:02:04 +00:00
parent b537747ccd
commit c6cca79737

View file

@ -341,7 +341,7 @@ module.exports = ProjectEntityHandler =
callback(null, folders, lastFolder) callback(null, folders, lastFolder)
addFolder: (project_id, parentFolder_id, folderName, callback) -> addFolder: (project_id, parentFolder_id, folderName, callback) ->
ProjectGetter.getProjectWithOnlyFolders project_id, (err, project)=> ProjectGetter.getProject project_id, {}, (err, project)=>
if err? if err?
logger.err project_id:project_id, err:err, "error getting project for add folder" logger.err project_id:project_id, err:err, "error getting project for add folder"
return callback(err) return callback(err)
@ -459,17 +459,20 @@ 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, entPath)=> projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (error, entity, entPath)=>
return callback(error) if error? return callback(error) if error?
endPath = path.join(path.dirname(entPath.fileSystem), newName) ProjectEntityHandler.checkElementName entity, newName, (err) =>
conditions = {_id:project_id} return callback(err) if err?
update = "$set":{} endPath = path.join(path.dirname(entPath.fileSystem), newName)
namePath = entPath.mongo+".name" conditions = {_id:project_id}
update["$set"][namePath] = newName update = "$set":{}
tpdsUpdateSender.moveEntity({project_id:project_id, startPath:entPath.fileSystem, endPath:endPath, project_name:project.name, rev:entity.rev}) namePath = entPath.mongo+".name"
Project.findOneAndUpdate conditions, update, { "new": true}, (error, newProject) -> update["$set"][namePath] = newName
return callback(error) if error? # FIXME check if this would create a duplicate file!
ProjectEntityHandler.getAllEntitiesFromProject newProject, (error, newDocs, newFiles) => tpdsUpdateSender.moveEntity({project_id:project_id, startPath:entPath.fileSystem, endPath:endPath, project_name:project.name, rev:entity.rev})
Project.findOneAndUpdate conditions, update, { "new": true}, (error, newProject) ->
return callback(error) if error? return callback(error) if error?
DocumentUpdaterHandler.updateProjectStructure project_id, userId, {oldDocs, newDocs, oldFiles, newFiles}, callback ProjectEntityHandler.getAllEntitiesFromProject newProject, (error, newDocs, newFiles) =>
return callback(error) if error?
DocumentUpdaterHandler.updateProjectStructure project_id, userId, {oldDocs, newDocs, oldFiles, newFiles}, callback
_cleanUpEntity: (project, entity, entityType, path, userId, callback = (error) ->) -> _cleanUpEntity: (project, entity, entityType, path, userId, callback = (error) ->) ->
if(entityType.indexOf("file") != -1) if(entityType.indexOf("file") != -1)