Add optional gallery fields to export request

Support the optional (well, gallery-only) fields `title`, `description`, `author`, `license`, and `show_source` in export requests.
This commit is contained in:
Michael Mazour 2018-09-13 12:14:06 +01:00
parent 1f976a0e04
commit 10fcdd6daf
5 changed files with 96 additions and 15 deletions

View file

@ -16,6 +16,13 @@ module.exports =
if req.body && req.body.firstName && req.body.lastName
export_params.first_name = req.body.firstName.trim()
export_params.last_name = req.body.lastName.trim()
# additional parameters for gallery exports
if req.body
export_params.title = req.body.title.trim() if req.body.title
export_params.description = req.body.description.trim() if req.body.description
export_params.author = req.body.author.trim() if req.body.author
export_params.license = req.body.license.trim() if req.body.license
export_params.show_source = req.body.show_source if req.body.show_source
ExportsHandler.exportProject export_params, (err, export_data) ->
return next(err) if err?

View file

@ -20,9 +20,7 @@ module.exports = ExportsHandler = self =
callback null, export_data
_buildExport: (export_params, callback=(err, export_data) ->) ->
project_id = export_params.project_id
user_id = export_params.user_id
brand_variation_id = export_params.brand_variation_id
{project_id, user_id, brand_variation_id, title, description, author, license, show_source} = export_params
jobs =
project: (cb) ->
ProjectGetter.getProject project_id, cb
@ -60,6 +58,11 @@ module.exports = ExportsHandler = self =
metadata:
compiler: project.compiler
imageName: project.imageName
title: title
description: description
author: author
license: license
show_source: show_source
user:
id: user_id
firstName: user.first_name

View file

@ -30,7 +30,13 @@ describe 'Exports', ->
@owner.request {
method: 'POST',
url: "/project/#{@project_id}/export/#{@brand_variation_id}",
json: {},
json: true,
body:
title: 'title'
description: 'description'
author: 'author'
license: 'other'
show_source: true
}, (error, response, body) =>
throw error if error?
expect(response.statusCode).to.equal 200
@ -42,6 +48,12 @@ describe 'Exports', ->
# project details should match
expect(project.id).to.equal @project_id
expect(project.rootDocPath).to.equal '/main.tex'
# gallery details should match
expect(project.metadata.title).to.equal 'title'
expect(project.metadata.description).to.equal 'description'
expect(project.metadata.author).to.equal 'author'
expect(project.metadata.license).to.equal 'other'
expect(project.metadata.show_source).to.equal true
# version should match what was retrieved from project-history
expect(project.historyVersion).to.equal @version
# user details should match

View file

@ -10,6 +10,13 @@ describe 'ExportsController', ->
project_id = "123njdskj9jlk"
user_id = "123nd3ijdks"
brand_variation_id = 22
firstName = 'first'
lastName = 'last'
title = "title"
description = "description"
author = "author"
license = "other"
show_source = true
beforeEach ->
@handler =
@ -18,6 +25,9 @@ describe 'ExportsController', ->
params:
project_id: project_id
brand_variation_id: brand_variation_id
body:
firstName: firstName
lastName: lastName
session:
user:
_id:user_id
@ -32,16 +42,45 @@ describe 'ExportsController', ->
err:->
'../Authentication/AuthenticationController': @AuthenticationController
it 'should ask the handler to perform the export', (done) ->
@handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897})
expected =
project_id: project_id
user_id: user_id
brand_variation_id: brand_variation_id
@controller.exportProject @req, send:(body) =>
expect(@handler.exportProject.args[0][0]).to.deep.equal expected
expect(body).to.deep.equal {export_v1_id: 897}
done()
describe "without gallery fields",->
it 'should ask the handler to perform the export', (done) ->
@handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897})
expected =
project_id: project_id
user_id: user_id
brand_variation_id: brand_variation_id
first_name: firstName
last_name: lastName
@controller.exportProject @req, send:(body) =>
expect(@handler.exportProject.args[0][0]).to.deep.equal expected
expect(body).to.deep.equal {export_v1_id: 897}
done()
describe "with gallery fields",->
beforeEach ->
@req.body.title = title
@req.body.description = description
@req.body.author = author
@req.body.license = license
@req.body.show_source = true
it 'should ask the handler to perform the export', (done) ->
@handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897})
expected =
project_id: project_id
user_id: user_id
brand_variation_id: brand_variation_id
first_name: firstName
last_name: lastName
title: title
description: description
author: author
license: license
show_source: show_source
@controller.exportProject @req, send:(body) =>
expect(@handler.exportProject.args[0][0]).to.deep.equal expected
expect(body).to.deep.equal {export_v1_id: 897}
done()
it 'should ask the handler to return the status of an export', (done) ->
@handler.fetchExport = sinon.stub().yields(

View file

@ -27,10 +27,20 @@ describe 'ExportsHandler', ->
@project_history_id = 987
@user_id = "user-id-456"
@brand_variation_id = 789
@title = "title"
@description = "description"
@author = "author"
@license = "other"
@show_source = true
@export_params = {
project_id: @project_id,
brand_variation_id: @brand_variation_id,
user_id: @user_id
title: @title
description: @description
author: @author
license: @license
show_source: @show_source
}
@callback = sinon.stub()
@ -105,6 +115,11 @@ describe 'ExportsHandler', ->
metadata:
compiler: 'pdflatex'
imageName: 'mock-image-name'
title: @title
description: @description
author: @author
license: @license
show_source: @show_source
user:
id: @user_id
firstName: @user.first_name
@ -140,6 +155,11 @@ describe 'ExportsHandler', ->
metadata:
compiler: 'pdflatex'
imageName: 'mock-image-name'
title: @title
description: @description
author: @author
license: @license
show_source: @show_source
user:
id: @user_id
firstName: @custom_first_name