Merge branch 'dcl-i1261b'

GitOrigin-RevId: 2d6c318e12220f39309238a2c7c76650cefa8be6
This commit is contained in:
Douglas Lovell 2019-03-05 11:25:06 -03:00 committed by James Allen
parent 44dd7c1c75
commit ce8695c951
4 changed files with 11 additions and 7 deletions

View file

@ -17,13 +17,14 @@ module.exports = TemplatesController =
data.templateId = templateId
data.name = req.query.templateName
data.compiler = ProjectHelper.compilerFromV1Engine(req.query.latexEngine)
data.imageName = req.query.texImage
data.mainFile = req.query.mainFile
data.brandVariationId = req.query.brandVariationId
res.render path.resolve(__dirname, "../../../views/project/editor/new_from_template"), data
createProjectFromV1Template: (req, res, next)->
user_id = AuthenticationController.getLoggedInUserId(req)
TemplatesManager.createProjectFromV1Template req.body.brandVariationId, req.body.compiler, req.body.mainFile, req.body.templateId, req.body.templateName, req.body.templateVersionId, user_id, (err, project) ->
TemplatesManager.createProjectFromV1Template req.body.brandVariationId, req.body.compiler, req.body.mainFile, req.body.templateId, req.body.templateName, req.body.templateVersionId, user_id, req.body.imageName, (err, project) ->
return next err if err?
delete req.session.templateData
res.redirect "/project/#{project._id}"

View file

@ -11,7 +11,7 @@ settings = require "settings-sharelatex"
uuid = require "uuid"
module.exports = TemplatesManager =
createProjectFromV1Template: (brandVariationId, compiler, mainFile, templateId, templateName, templateVersionId, user_id, callback) ->
createProjectFromV1Template: (brandVariationId, compiler, mainFile, templateId, templateName, templateVersionId, user_id, imageName, callback) ->
zipUrl = "#{settings.apis.v1.url}/api/v1/sharelatex/templates/#{templateVersionId}"
zipReq = request zipUrl, {
auth:
@ -34,7 +34,7 @@ module.exports = TemplatesManager =
return callback err
async.series [
(cb) -> TemplatesManager._setCompiler project._id, compiler, cb
(cb) -> TemplatesManager._setImage project._id, "wl_texlive:2018.1", cb
(cb) -> TemplatesManager._setImage project._id, imageName, cb
(cb) -> TemplatesManager._setMainFile project._id, mainFile, cb
(cb) -> TemplatesManager._setBrandVariationId project._id, brandVariationId, cb
], (err) ->
@ -54,7 +54,7 @@ module.exports = TemplatesManager =
ProjectOptionsHandler.setCompiler project_id, compiler, callback
_setImage: (project_id, imageName, callback) ->
return callback() unless imageName?
imageName ||= "wl_texlive:2018.1"
ProjectOptionsHandler.setImageName project_id, imageName, callback
_setMainFile: (project_id, mainFile, callback) ->

View file

@ -24,6 +24,7 @@ block content
input(type="hidden" name="templateVersionId" value=templateVersionId)
input(type="hidden" name="templateName" value=name)
input(type="hidden" name="compiler" value=compiler)
input(type="hidden" name="imageName" value=imageName)
input(type="hidden" name="mainFile" value=mainFile)
if brandVariationId
input(type="hidden" name="brandVariationId" value=brandVariationId)

View file

@ -15,6 +15,7 @@ describe 'TemplatesManager', ->
@project_id = "project-id"
@brandVariationId = "brand-variation-id"
@compiler = "pdflatex"
@imageName = "TL2017"
@mainFile = "main.tex"
@templateId = "template-id"
@templateName = "template name"
@ -78,7 +79,7 @@ describe 'TemplatesManager', ->
describe "when all options passed", ->
beforeEach ->
@TemplatesManager.createProjectFromV1Template @brandVariationId, @compiler, @mainFile, @templateId, @templateName, @templateVersionId, @user_id, @callback
@TemplatesManager.createProjectFromV1Template @brandVariationId, @compiler, @mainFile, @templateId, @templateName, @templateVersionId, @user_id, @imageName, @callback
it "should fetch zip from v1 based on template id", ->
@request.should.have.been.calledWith "#{@v1Url}/api/v1/sharelatex/templates/#{@templateVersionId}"
@ -94,7 +95,7 @@ describe 'TemplatesManager', ->
it "should set project options when passed", ->
@ProjectOptionsHandler.setCompiler.should.have.been.calledWithMatch @project_id, @compiler
@ProjectOptionsHandler.setImageName.should.have.been.calledWithMatch @project_id, "wl_texlive:2018.1"
@ProjectOptionsHandler.setImageName.should.have.been.calledWithMatch @project_id, @imageName
@ProjectRootDocManager.setRootDocFromName.should.have.been.calledWithMatch @project_id, @mainFile
@ProjectOptionsHandler.setBrandVariationId.should.have.been.calledWithMatch @project_id, @brandVariationId
@ -103,9 +104,10 @@ describe 'TemplatesManager', ->
describe "when some options not set", ->
beforeEach ->
@TemplatesManager.createProjectFromV1Template null, null, null, @templateId, @templateName, @templateVersionId, @user_id, @callback
@TemplatesManager.createProjectFromV1Template null, null, null, @templateId, @templateName, @templateVersionId, @user_id, null, @callback
it "should not set missing project options", ->
@ProjectOptionsHandler.setCompiler.called.should.equal false
@ProjectRootDocManager.setRootDocFromName.called.should.equal false
@ProjectOptionsHandler.setBrandVariationId.called.should.equal false
@ProjectOptionsHandler.setImageName.should.have.been.calledWithMatch @project_id, "wl_texlive:2018.1"