make project names unique for zip uploads and template imports

This commit is contained in:
Brian Gough 2018-10-12 12:29:37 +01:00
parent 59cf0aa3cb
commit a640397052
3 changed files with 14 additions and 5 deletions

View file

@ -67,6 +67,10 @@ module.exports = ProjectDetailsHandler =
else
return callback()
generateUniqueName: (user_id, name, callback = (error, newName) -> ) ->
timestamp = new Date().toISOString().replace(/T(\d+):(\d+):(\d+)\..*/,' $1$2$3') # strip out unwanted characters
ProjectDetailsHandler.ensureProjectNameIsUnique user_id, name, [" #{timestamp}"], callback
_addSuffixToProjectName: (name, suffix = '') ->
# append the suffix and truncate the project title if needed
truncatedLength = ProjectDetailsHandler.MAX_PROJECT_NAME_LENGTH - suffix.length

View file

@ -4,9 +4,12 @@ ArchiveManager = require "./ArchiveManager"
FileSystemImportManager = require "./FileSystemImportManager"
ProjectCreationHandler = require "../Project/ProjectCreationHandler"
ProjectRootDocManager = require "../Project/ProjectRootDocManager"
ProjectDetailsHandler = require "../Project/ProjectDetailsHandler"
module.exports = ProjectUploadHandler =
createProjectFromZipArchive: (owner_id, name, zipPath, callback = (error, project) ->) ->
createProjectFromZipArchive: (owner_id, proposedName, zipPath, callback = (error, project) ->) ->
ProjectDetailsHandler.generateUniqueName owner_id, proposedName, (error, name) =>
return callback(error) if error?
ProjectCreationHandler.createBlankProject owner_id, name, (error, project) =>
return callback(error) if error?
@insertZipArchiveIntoFolder owner_id, project._id, project.rootFolder[0]._id, zipPath, (error) ->

View file

@ -15,6 +15,7 @@ describe "ProjectUploadManager", ->
"./ArchiveManager" : @ArchiveManager = {}
"../Project/ProjectCreationHandler" : @ProjectCreationHandler = {}
"../Project/ProjectRootDocManager" : @ProjectRootDocManager = {}
"../Project/ProjectDetailsHandler" : @ProjectDetailsHandler = {}
"rimraf" : @rimraf = sinon.stub().callsArg(1)
describe "createProjectFromZipArchive", ->
@ -26,6 +27,7 @@ describe "ProjectUploadManager", ->
@project =
_id: @project_id
rootFolder: [ _id: @root_folder_id ]
@ProjectDetailsHandler.generateUniqueName = sinon.stub().callsArgWith(2, null, @name)
@ProjectCreationHandler.createBlankProject = sinon.stub().callsArgWith(2, null, @project)
@ProjectUploadManager.insertZipArchiveIntoFolder = sinon.stub().callsArg(4)
@ProjectRootDocManager.setRootDocAutomatically = sinon.stub().callsArg(1)