mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
check for duplicates in putElement
This commit is contained in:
parent
81406d1f49
commit
82a9fc97d9
1 changed files with 28 additions and 14 deletions
|
@ -170,7 +170,8 @@ module.exports = ProjectEntityHandler =
|
||||||
if project_or_id._id? # project
|
if project_or_id._id? # project
|
||||||
return cb(null, project_or_id)
|
return cb(null, project_or_id)
|
||||||
else # id
|
else # id
|
||||||
return ProjectGetter.getProjectWithOnlyFolders project_or_id, cb
|
# need to retrieve full project structure to check for duplicates
|
||||||
|
return ProjectGetter.getProject project_or_id, {}, cb
|
||||||
getProject (error, project) ->
|
getProject (error, project) ->
|
||||||
if err?
|
if err?
|
||||||
logger.err project_id:project_id, err:err, "error getting project for add doc"
|
logger.err project_id:project_id, err:err, "error getting project for add doc"
|
||||||
|
@ -207,7 +208,7 @@ module.exports = ProjectEntityHandler =
|
||||||
ProjectEntityHandler.addDoc project_id, null, name, lines, callback
|
ProjectEntityHandler.addDoc project_id, null, name, lines, callback
|
||||||
|
|
||||||
addFileWithoutUpdatingHistory: (project_id, folder_id, fileName, path, userId, callback = (error, fileRef, folder_id, path, fileStoreUrl) ->)->
|
addFileWithoutUpdatingHistory: (project_id, folder_id, fileName, path, userId, callback = (error, fileRef, folder_id, path, fileStoreUrl) ->)->
|
||||||
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 file"
|
logger.err project_id:project_id, err:err, "error getting project for add file"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
|
@ -606,6 +607,8 @@ module.exports = ProjectEntityHandler =
|
||||||
newPath =
|
newPath =
|
||||||
fileSystem: "#{path.fileSystem}/#{element.name}"
|
fileSystem: "#{path.fileSystem}/#{element.name}"
|
||||||
mongo: path.mongo
|
mongo: path.mongo
|
||||||
|
ProjectEntityHandler.checkElementName folder, element.name, (err) =>
|
||||||
|
return callback(err) if err?
|
||||||
id = element._id+''
|
id = element._id+''
|
||||||
element._id = require('mongoose').Types.ObjectId(id)
|
element._id = require('mongoose').Types.ObjectId(id)
|
||||||
conditions = _id:project._id
|
conditions = _id:project._id
|
||||||
|
@ -619,6 +622,17 @@ module.exports = ProjectEntityHandler =
|
||||||
return callback(err)
|
return callback(err)
|
||||||
callback(err, {path:newPath}, project)
|
callback(err, {path:newPath}, project)
|
||||||
|
|
||||||
|
checkElementName: (folder, name, callback = (err) ->) ->
|
||||||
|
# check if the name is already taken by a doc, file or
|
||||||
|
# folder. If so, return an error "file already exists".
|
||||||
|
err = new Errors.InvalidNameError("file already exists")
|
||||||
|
for doc in folder?.docs or []
|
||||||
|
return callback(err) if doc.name is name
|
||||||
|
for file in folder?.fileRefs or []
|
||||||
|
return callback(err) if file.name is name
|
||||||
|
for folder in folder?.folders or []
|
||||||
|
return callback(err) if folder.name is name
|
||||||
|
callback()
|
||||||
|
|
||||||
confirmFolder = (project, folder_id, callback)->
|
confirmFolder = (project, folder_id, callback)->
|
||||||
logger.log folder_id:folder_id, project_id:project._id, "confirming folder in project"
|
logger.log folder_id:folder_id, project_id:project._id, "confirming folder in project"
|
||||||
|
|
Loading…
Reference in a new issue