Просмотр исходного кода

Merge pull request #920 from sharelatex/mm-gallery-exports

Add gallery fields to export controller and handler
Alasdair Smith 8 лет назад
Родитель
Сommit
42cef8e393

+ 10 - 4
services/web/app/coffee/Features/Exports/ExportsController.coffee

@@ -13,13 +13,19 @@ module.exports =
 			user_id: user_id
 		}
 
-		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()
+		if req.body
+			export_params.first_name = req.body.firstName.trim() if req.body.firstName
+			export_params.last_name = req.body.lastName.trim() if req.body.lastName
+			# additional parameters for gallery exports
+			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?
-			logger.log 
+			logger.log
 				user_id:user_id
 				project_id: project_id
 				brand_variation_id:brand_variation_id

+ 6 - 3
services/web/app/coffee/Features/Exports/ExportsHandler.coffee

@@ -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

+ 13 - 1
services/web/test/acceptance/coffee/ExportsTests.coffee

@@ -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

+ 49 - 5
services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee

@@ -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,11 +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})
-		@controller.exportProject @req, send:(body) =>
-			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(

+ 20 - 0
services/web/test/unit/coffee/Exports/ExportsHandlerTests.coffee

@@ -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