diff --git a/services/web/app/coffee/Features/Exports/ExportsController.coffee b/services/web/app/coffee/Features/Exports/ExportsController.coffee new file mode 100644 index 0000000000..cda2296249 --- /dev/null +++ b/services/web/app/coffee/Features/Exports/ExportsController.coffee @@ -0,0 +1,18 @@ +ExportsHandler = require("./ExportsHandler") +AuthenticationController = require("../Authentication/AuthenticationController") +logger = require("logger-sharelatex") + +module.exports = + + exportProject: (req, res) -> + {project_id, brand_variation_id} = req.params + user_id = AuthenticationController.getLoggedInUserId(req) + ExportsHandler.exportProject project_id, user_id, brand_variation_id, (err, export_data) -> + logger.log + user_id:user_id + project_id: project_id + brand_variation_id:brand_variation_id + export_v1_id:export_data.v1_id + "exported project" + res.send export_v1_id: export_data.v1_id + diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 7ec4dafbf4..e6b2692f7c 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -26,6 +26,7 @@ HealthCheckController = require("./Features/HealthCheck/HealthCheckController") ProjectDownloadsController = require "./Features/Downloads/ProjectDownloadsController" FileStoreController = require("./Features/FileStore/FileStoreController") HistoryController = require("./Features/History/HistoryController") +ExportsController = require("./Features/Exports/ExportsController") PasswordResetRouter = require("./Features/PasswordReset/PasswordResetRouter") StaticPagesRouter = require("./Features/StaticPages/StaticPagesRouter") ChatController = require("./Features/Chat/ChatController") @@ -205,6 +206,7 @@ module.exports = class Router webRouter.post "/project/:project_id/restore_file", AuthorizationMiddlewear.ensureUserCanWriteProjectContent, HistoryController.restoreFileFromV2 privateApiRouter.post "/project/:Project_id/history/resync", AuthenticationController.httpAuth, HistoryController.resyncProjectHistory + webRouter.post '/project/:project_id/export/:brand_variation_id', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportProject webRouter.get '/Project/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects diff --git a/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee b/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee new file mode 100644 index 0000000000..821eb5b4e0 --- /dev/null +++ b/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee @@ -0,0 +1,39 @@ +SandboxedModule = require('sandboxed-module') +assert = require('assert') +chai = require('chai') +expect = chai.expect +sinon = require('sinon') +modulePath = require('path').join __dirname, '../../../../app/js/Features/Exports/ExportsController.js' + + +describe 'ExportsController', -> + project_id = "123njdskj9jlk" + user_id = "123nd3ijdks" + brand_variation_id = 22 + + beforeEach -> + @handler = + getUserNotifications: sinon.stub().callsArgWith(1) + @req = + params: + project_id: project_id + brand_variation_id: brand_variation_id + session: + user: + _id:user_id + i18n: + translate:-> + @AuthenticationController = + getLoggedInUserId: sinon.stub().returns(@req.session.user._id) + @controller = SandboxedModule.require modulePath, requires: + "./ExportsHandler":@handler + 'logger-sharelatex': + log:-> + 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()