mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 05:05:27 -05:00
iterate over owned projects in a more robust way
This commit is contained in:
parent
6b80d3563d
commit
8f8694ad94
1 changed files with 5 additions and 3 deletions
|
@ -78,12 +78,14 @@ module.exports = ProjectDetailsHandler =
|
||||||
# with a unique name. But that requires thinking through how we would handle incoming projects from
|
# with a unique name. But that requires thinking through how we would handle incoming projects from
|
||||||
# dropbox for example.
|
# dropbox for example.
|
||||||
ensureProjectNameIsUnique: (user_id, name, suffixes = [], callback = (error, name, changed)->) ->
|
ensureProjectNameIsUnique: (user_id, name, suffixes = [], callback = (error, name, changed)->) ->
|
||||||
ProjectGetter.findAllUsersProjects user_id, {name: 1}, (error, allUsersProjects) ->
|
ProjectGetter.findAllUsersProjects user_id, {name: 1}, (error, allUsersProjectNames) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
{owned, readAndWrite, readOnly, tokenReadAndWrite, tokenReadOnly} = allUsersProjects
|
# allUsersProjectNames is returned as a hash {owned: [name1, name2, ...], readOnly: [....]}
|
||||||
|
# collect all of the names and flatten them into a single array
|
||||||
|
projectNameList = _.flatten(_.values(allUsersProjectNames))
|
||||||
# create a set of all project names
|
# create a set of all project names
|
||||||
allProjectNames = new Set()
|
allProjectNames = new Set()
|
||||||
for projectName in owned.concat(readAndWrite, readOnly, tokenReadAndWrite, tokenReadOnly)
|
for projectName in projectNameList
|
||||||
allProjectNames.add(projectName)
|
allProjectNames.add(projectName)
|
||||||
isUnique = (x) -> !allProjectNames.has(x)
|
isUnique = (x) -> !allProjectNames.has(x)
|
||||||
# check if the supplied name is already unique
|
# check if the supplied name is already unique
|
||||||
|
|
Loading…
Reference in a new issue