mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 05:15:20 -05:00
Merge pull request #971 from sharelatex/bg-fix-opening-templates-containing-slash
fix invalid project names when opening templates
This commit is contained in:
commit
f278459393
4 changed files with 30 additions and 1 deletions
|
@ -99,6 +99,16 @@ module.exports = ProjectDetailsHandler =
|
|||
# we couldn't make the name unique, something is wrong
|
||||
return callback new Errors.InvalidNameError("Project name could not be made unique")
|
||||
|
||||
fixProjectName: (name) ->
|
||||
if name == ""
|
||||
name = "Untitled"
|
||||
if name.indexOf('/') > -1
|
||||
# v2 does not allow / in a project name
|
||||
name = name.replace(/\//g, '-')
|
||||
if name.length > @MAX_PROJECT_NAME_LENGTH
|
||||
name = name.substr(0, @MAX_PROJECT_NAME_LENGTH)
|
||||
return name
|
||||
|
||||
setPublicAccessLevel : (project_id, newAccessLevel, callback = ->)->
|
||||
logger.log project_id: project_id, level: newAccessLevel, "set public access level"
|
||||
# DEPRECATED: `READ_ONLY` and `READ_AND_WRITE` are still valid in, but should no longer
|
||||
|
|
|
@ -3,6 +3,7 @@ Project = require('../../../js/models/Project').Project
|
|||
ProjectUploadManager = require('../../../js/Features/Uploads/ProjectUploadManager')
|
||||
ProjectOptionsHandler = require('../../../js/Features/Project/ProjectOptionsHandler')
|
||||
ProjectRootDocManager = require('../../../js/Features/Project/ProjectRootDocManager')
|
||||
ProjectDetailsHandler = require('../../../js/Features/Project/ProjectDetailsHandler')
|
||||
AuthenticationController = require('../../../js/Features/Authentication/AuthenticationController')
|
||||
settings = require('settings-sharelatex')
|
||||
fs = require('fs')
|
||||
|
@ -55,6 +56,8 @@ module.exports = TemplatesController =
|
|||
)
|
||||
|
||||
createFromZip: (zipReq, options, req, res)->
|
||||
# remove any invalid characters from template name
|
||||
projectName = ProjectDetailsHandler.fixProjectName(options.templateName)
|
||||
dumpPath = "#{settings.path.dumpFolder}/#{uuid.v4()}"
|
||||
writeStream = fs.createWriteStream(dumpPath)
|
||||
|
||||
|
@ -62,7 +65,7 @@ module.exports = TemplatesController =
|
|||
logger.error err: error, "error getting zip from template API"
|
||||
zipReq.pipe(writeStream)
|
||||
writeStream.on 'close', ->
|
||||
ProjectUploadManager.createProjectFromZipArchive options.currentUserId, options.templateName, dumpPath, (err, project)->
|
||||
ProjectUploadManager.createProjectFromZipArchive options.currentUserId, projectName, dumpPath, (err, project)->
|
||||
if err?
|
||||
logger.err err:err, zipReq:zipReq, "problem building project from zip"
|
||||
return res.sendStatus 500
|
||||
|
|
|
@ -196,6 +196,20 @@ describe 'ProjectDetailsHandler', ->
|
|||
expect(error).to.eql new Errors.InvalidNameError("Project name could not be made unique")
|
||||
done()
|
||||
|
||||
describe "fixProjectName", ->
|
||||
|
||||
it "should change empty names to Untitled", () ->
|
||||
expect(@handler.fixProjectName "").to.equal "Untitled"
|
||||
|
||||
it "should replace / with -", () ->
|
||||
expect(@handler.fixProjectName "foo/bar").to.equal "foo-bar"
|
||||
|
||||
it "should truncate long names", () ->
|
||||
expect(@handler.fixProjectName new Array(1000).join("a")).to.equal "a".repeat(150)
|
||||
|
||||
it "should accept normal names", () ->
|
||||
expect(@handler.fixProjectName "foobar").to.equal "foobar"
|
||||
|
||||
|
||||
describe "setPublicAccessLevel", ->
|
||||
beforeEach ->
|
||||
|
|
|
@ -32,12 +32,14 @@ describe 'TemplatesController', ->
|
|||
}
|
||||
@ProjectDetailsHandler =
|
||||
getProjectDescription:sinon.stub()
|
||||
fixProjectName: sinon.stub().returns(@templateName)
|
||||
@Project =
|
||||
update: sinon.stub().callsArgWith(3, null)
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
'../../../js/Features/Uploads/ProjectUploadManager':@ProjectUploadManager
|
||||
'../../../js/Features/Project/ProjectOptionsHandler':@ProjectOptionsHandler
|
||||
'../../../js/Features/Project/ProjectRootDocManager':@ProjectRootDocManager
|
||||
'../../../js/Features/Project/ProjectDetailsHandler':@ProjectDetailsHandler
|
||||
'../../../js/Features/Authentication/AuthenticationController': @AuthenticationController = {getLoggedInUserId: sinon.stub()}
|
||||
'./TemplatesPublisher':@TemplatesPublisher
|
||||
"logger-sharelatex":
|
||||
|
|
Loading…
Reference in a new issue