mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
make project names unique for zip uploads and template imports
This commit is contained in:
parent
59cf0aa3cb
commit
a640397052
3 changed files with 14 additions and 5 deletions
|
@ -67,6 +67,10 @@ module.exports = ProjectDetailsHandler =
|
||||||
else
|
else
|
||||||
return callback()
|
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 = '') ->
|
_addSuffixToProjectName: (name, suffix = '') ->
|
||||||
# append the suffix and truncate the project title if needed
|
# append the suffix and truncate the project title if needed
|
||||||
truncatedLength = ProjectDetailsHandler.MAX_PROJECT_NAME_LENGTH - suffix.length
|
truncatedLength = ProjectDetailsHandler.MAX_PROJECT_NAME_LENGTH - suffix.length
|
||||||
|
|
|
@ -4,16 +4,19 @@ ArchiveManager = require "./ArchiveManager"
|
||||||
FileSystemImportManager = require "./FileSystemImportManager"
|
FileSystemImportManager = require "./FileSystemImportManager"
|
||||||
ProjectCreationHandler = require "../Project/ProjectCreationHandler"
|
ProjectCreationHandler = require "../Project/ProjectCreationHandler"
|
||||||
ProjectRootDocManager = require "../Project/ProjectRootDocManager"
|
ProjectRootDocManager = require "../Project/ProjectRootDocManager"
|
||||||
|
ProjectDetailsHandler = require "../Project/ProjectDetailsHandler"
|
||||||
|
|
||||||
module.exports = ProjectUploadHandler =
|
module.exports = ProjectUploadHandler =
|
||||||
createProjectFromZipArchive: (owner_id, name, zipPath, callback = (error, project) ->) ->
|
createProjectFromZipArchive: (owner_id, proposedName, zipPath, callback = (error, project) ->) ->
|
||||||
ProjectCreationHandler.createBlankProject owner_id, name, (error, project) =>
|
ProjectDetailsHandler.generateUniqueName owner_id, proposedName, (error, name) =>
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
@insertZipArchiveIntoFolder owner_id, project._id, project.rootFolder[0]._id, zipPath, (error) ->
|
ProjectCreationHandler.createBlankProject owner_id, name, (error, project) =>
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
ProjectRootDocManager.setRootDocAutomatically project._id, (error) ->
|
@insertZipArchiveIntoFolder owner_id, project._id, project.rootFolder[0]._id, zipPath, (error) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
callback(error, project)
|
ProjectRootDocManager.setRootDocAutomatically project._id, (error) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
callback(error, project)
|
||||||
|
|
||||||
insertZipArchiveIntoFolder: (owner_id, project_id, folder_id, path, callback = (error) ->) ->
|
insertZipArchiveIntoFolder: (owner_id, project_id, folder_id, path, callback = (error) ->) ->
|
||||||
destination = @_getDestinationDirectory path
|
destination = @_getDestinationDirectory path
|
||||||
|
|
|
@ -15,6 +15,7 @@ describe "ProjectUploadManager", ->
|
||||||
"./ArchiveManager" : @ArchiveManager = {}
|
"./ArchiveManager" : @ArchiveManager = {}
|
||||||
"../Project/ProjectCreationHandler" : @ProjectCreationHandler = {}
|
"../Project/ProjectCreationHandler" : @ProjectCreationHandler = {}
|
||||||
"../Project/ProjectRootDocManager" : @ProjectRootDocManager = {}
|
"../Project/ProjectRootDocManager" : @ProjectRootDocManager = {}
|
||||||
|
"../Project/ProjectDetailsHandler" : @ProjectDetailsHandler = {}
|
||||||
"rimraf" : @rimraf = sinon.stub().callsArg(1)
|
"rimraf" : @rimraf = sinon.stub().callsArg(1)
|
||||||
|
|
||||||
describe "createProjectFromZipArchive", ->
|
describe "createProjectFromZipArchive", ->
|
||||||
|
@ -26,6 +27,7 @@ describe "ProjectUploadManager", ->
|
||||||
@project =
|
@project =
|
||||||
_id: @project_id
|
_id: @project_id
|
||||||
rootFolder: [ _id: @root_folder_id ]
|
rootFolder: [ _id: @root_folder_id ]
|
||||||
|
@ProjectDetailsHandler.generateUniqueName = sinon.stub().callsArgWith(2, null, @name)
|
||||||
@ProjectCreationHandler.createBlankProject = sinon.stub().callsArgWith(2, null, @project)
|
@ProjectCreationHandler.createBlankProject = sinon.stub().callsArgWith(2, null, @project)
|
||||||
@ProjectUploadManager.insertZipArchiveIntoFolder = sinon.stub().callsArg(4)
|
@ProjectUploadManager.insertZipArchiveIntoFolder = sinon.stub().callsArg(4)
|
||||||
@ProjectRootDocManager.setRootDocAutomatically = sinon.stub().callsArg(1)
|
@ProjectRootDocManager.setRootDocAutomatically = sinon.stub().callsArg(1)
|
||||||
|
|
Loading…
Reference in a new issue