mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-13 21:53:43 +01:00
Merge pull request #1015 from sharelatex/pr-create-projects-with-brand-variation-id
Create projects with brand variation id
This commit is contained in:
@@ -46,3 +46,14 @@ module.exports =
|
||||
else
|
||||
logger.err project_id:project_id, languageCode:languageCode, "tryed to set unsafe language"
|
||||
callback()
|
||||
|
||||
setBrandVariationId: (project_id, brandVariationId, callback = ()->)->
|
||||
logger.log project_id:project_id, brandVariationId:brandVariationId, "setting the brand variation id"
|
||||
if !brandVariationId? or brandVariationId == ""
|
||||
return callback()
|
||||
conditions = {_id:project_id}
|
||||
update = {brandVariationId}
|
||||
Project.update conditions, update, {}, (err)->
|
||||
if err?
|
||||
logger.err err:err, "error setting brandVariationId"
|
||||
callback()
|
||||
|
||||
@@ -33,6 +33,7 @@ module.exports = TemplatesController =
|
||||
data.name = req.query.templateName
|
||||
data.compiler = ENGINE_TO_COMPILER_MAP[req.query.latexEngine]
|
||||
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)->
|
||||
@@ -55,6 +56,7 @@ module.exports = TemplatesController =
|
||||
mainFile: req.body.mainFile
|
||||
templateId: req.body.templateId
|
||||
templateVersionId: req.body.templateVersionId
|
||||
brandVariationId: req.body.brandVariationId
|
||||
image: 'wl_texlive:2018.1'
|
||||
},
|
||||
req,
|
||||
@@ -78,15 +80,16 @@ module.exports = TemplatesController =
|
||||
setCompiler project._id, options.compiler, ->
|
||||
setImage project._id, options.image, ->
|
||||
setMainFile project._id, options.mainFile, ->
|
||||
fs.unlink dumpPath, ->
|
||||
delete req.session.templateData
|
||||
conditions = {_id:project._id}
|
||||
update = {
|
||||
fromV1TemplateId:options.templateId,
|
||||
fromV1TemplateVersionId:options.templateVersionId
|
||||
}
|
||||
Project.update conditions, update, {}, (err)->
|
||||
res.redirect "/project/#{project._id}"
|
||||
setBrandVariationId project._id, options.brandVariationId, ->
|
||||
fs.unlink dumpPath, ->
|
||||
delete req.session.templateData
|
||||
conditions = {_id:project._id}
|
||||
update = {
|
||||
fromV1TemplateId:options.templateId,
|
||||
fromV1TemplateVersionId:options.templateVersionId
|
||||
}
|
||||
Project.update conditions, update, {}, (err)->
|
||||
res.redirect "/project/#{project._id}"
|
||||
|
||||
setCompiler = (project_id, compiler, callback)->
|
||||
if compiler?
|
||||
@@ -105,3 +108,10 @@ setMainFile = (project_id, mainFile, callback) ->
|
||||
ProjectRootDocManager.setRootDocFromName project_id, mainFile, callback
|
||||
else
|
||||
callback()
|
||||
|
||||
setBrandVariationId = (project_id, brandVariationId, callback) ->
|
||||
if brandVariationId?
|
||||
ProjectOptionsHandler.setBrandVariationId project_id, brandVariationId, callback
|
||||
else
|
||||
callback()
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ ProjectSchema = new Schema
|
||||
deletedDocs : [DeletedDocSchema]
|
||||
deletedFiles : [DeletedFileSchema]
|
||||
imageName : { type: String }
|
||||
brandVariationId : { type: String }
|
||||
track_changes : { type: Object }
|
||||
tokens :
|
||||
readOnly : {
|
||||
|
||||
@@ -25,3 +25,5 @@ block content
|
||||
input(type="hidden" name="templateName" value=name)
|
||||
input(type="hidden" name="compiler" value=compiler)
|
||||
input(type="hidden" name="mainFile" value=mainFile)
|
||||
if brandVariationId
|
||||
input(type="hidden" name="brandVariationId" value=brandVariationId)
|
||||
|
||||
@@ -4,7 +4,7 @@ should = chai.should()
|
||||
modulePath = "../../../../app/js/Features/Project/ProjectOptionsHandler.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe 'creating a project', ->
|
||||
describe 'ProjectOptionsHandler', ->
|
||||
project_id = "4eecaffcbffa66588e000008"
|
||||
|
||||
beforeEach ->
|
||||
@@ -77,3 +77,23 @@ describe 'creating a project', ->
|
||||
@projectModel.update.called.should.equal true
|
||||
done()
|
||||
@projectModel.update.args[0][3]()
|
||||
|
||||
describe "setting the brandVariationId", ->
|
||||
it 'should perform and update on mongo', (done)->
|
||||
@handler.setBrandVariationId project_id, "123", (err)=>
|
||||
args = @projectModel.update.args[0]
|
||||
args[0]._id.should.equal project_id
|
||||
args[1].brandVariationId.should.equal "123"
|
||||
done()
|
||||
@projectModel.update.args[0][3]()
|
||||
|
||||
|
||||
it 'should not perform and update on mongo if there is no brand variation', (done)->
|
||||
@handler.setBrandVariationId project_id, null, (err)=>
|
||||
@projectModel.update.called.should.equal false
|
||||
done()
|
||||
|
||||
it 'should not perform and update on mongo if brand variation is an empty string', (done)->
|
||||
@handler.setBrandVariationId project_id, "", (err)=>
|
||||
@projectModel.update.called.should.equal false
|
||||
done()
|
||||
|
||||
@@ -8,7 +8,7 @@ modulePath = '../../../../app/js/Features/Templates/TemplatesController'
|
||||
|
||||
describe 'TemplatesController', ->
|
||||
|
||||
project_id = "213432"
|
||||
@project_id = "213432"
|
||||
|
||||
beforeEach ->
|
||||
@request = sinon.stub()
|
||||
@@ -20,11 +20,12 @@ describe 'TemplatesController', ->
|
||||
unlink : sinon.stub()
|
||||
createWriteStream : sinon.stub().returns(on:(_, cb)->cb())
|
||||
}
|
||||
@ProjectUploadManager = {createProjectFromZipArchive : sinon.stub().callsArgWith(3, null, {_id:project_id})}
|
||||
@ProjectUploadManager = {createProjectFromZipArchive : sinon.stub().callsArgWith(3, null, {_id:@project_id})}
|
||||
@dumpFolder = "dump/path"
|
||||
@ProjectOptionsHandler = {
|
||||
setCompiler:sinon.stub().callsArgWith(2)
|
||||
setImageName:sinon.stub().callsArgWith(2)
|
||||
setBrandVariationId:sinon.stub().callsArgWith(2)
|
||||
}
|
||||
@uuid = "1234"
|
||||
@ProjectRootDocManager = {
|
||||
@@ -83,3 +84,45 @@ describe 'TemplatesController', ->
|
||||
done()
|
||||
res = redirect:redirect
|
||||
@controller.createProjectFromV1Template @req, res
|
||||
|
||||
it "should set project options based on payload data", (done)->
|
||||
@compiler = "pdflatex"
|
||||
@mainFile = "main.tex"
|
||||
@templateVersionId = 15
|
||||
@brandVariationId = "123"
|
||||
|
||||
@req.body =
|
||||
templateVersionId: @templateVersionId
|
||||
name: @templateName
|
||||
compiler: @compiler
|
||||
mainFile: @mainFile
|
||||
brandVariationId: @brandVariationId
|
||||
|
||||
redirect = =>
|
||||
@ProjectOptionsHandler.setCompiler.calledWith(@project_id, @compiler).should.equal true
|
||||
@ProjectOptionsHandler.setBrandVariationId.calledWith(@project_id, @brandVariationId).should.equal true
|
||||
@ProjectRootDocManager.setRootDocFromName.calledWith(@project_id, @mainFile).should.equal true
|
||||
done()
|
||||
res = redirect:redirect
|
||||
@controller.createProjectFromV1Template @req, res
|
||||
|
||||
it "should only set project options which are defined in the payload", (done)->
|
||||
@compiler = "pdflatex"
|
||||
@templateVersionId = 15
|
||||
@brandVariationId = "123"
|
||||
|
||||
@req.body =
|
||||
templateVersionId: @templateVersionId
|
||||
name: @templateName
|
||||
compiler: @compiler
|
||||
brandVariationId: @brandVariationId
|
||||
|
||||
redirect = =>
|
||||
# Payload doesn't refine a main file, so `setRootDocFromName` should not be called
|
||||
@ProjectOptionsHandler.setCompiler.calledWith(@project_id, @compiler).should.equal true
|
||||
@ProjectOptionsHandler.setBrandVariationId.calledWith(@project_id, @brandVariationId).should.equal true
|
||||
@ProjectRootDocManager.setRootDocFromName.called.should.equal false
|
||||
done()
|
||||
res = redirect:redirect
|
||||
@controller.createProjectFromV1Template @req, res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user