mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
Add project export route and controller
This commit is contained in:
parent
a661084485
commit
e34dd90a1f
3 changed files with 59 additions and 0 deletions
|
@ -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
|
||||||
|
|
|
@ -26,6 +26,7 @@ HealthCheckController = require("./Features/HealthCheck/HealthCheckController")
|
||||||
ProjectDownloadsController = require "./Features/Downloads/ProjectDownloadsController"
|
ProjectDownloadsController = require "./Features/Downloads/ProjectDownloadsController"
|
||||||
FileStoreController = require("./Features/FileStore/FileStoreController")
|
FileStoreController = require("./Features/FileStore/FileStoreController")
|
||||||
HistoryController = require("./Features/History/HistoryController")
|
HistoryController = require("./Features/History/HistoryController")
|
||||||
|
ExportsController = require("./Features/Exports/ExportsController")
|
||||||
PasswordResetRouter = require("./Features/PasswordReset/PasswordResetRouter")
|
PasswordResetRouter = require("./Features/PasswordReset/PasswordResetRouter")
|
||||||
StaticPagesRouter = require("./Features/StaticPages/StaticPagesRouter")
|
StaticPagesRouter = require("./Features/StaticPages/StaticPagesRouter")
|
||||||
ChatController = require("./Features/Chat/ChatController")
|
ChatController = require("./Features/Chat/ChatController")
|
||||||
|
@ -205,6 +206,7 @@ module.exports = class Router
|
||||||
webRouter.post "/project/:project_id/restore_file", AuthorizationMiddlewear.ensureUserCanWriteProjectContent, HistoryController.restoreFileFromV2
|
webRouter.post "/project/:project_id/restore_file", AuthorizationMiddlewear.ensureUserCanWriteProjectContent, HistoryController.restoreFileFromV2
|
||||||
privateApiRouter.post "/project/:Project_id/history/resync", AuthenticationController.httpAuth, HistoryController.resyncProjectHistory
|
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/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject
|
||||||
webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects
|
webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects
|
||||||
|
|
|
@ -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()
|
Loading…
Reference in a new issue