Merge pull request #648 from sharelatex/hb-export-status

Export status endpoint
This commit is contained in:
Timothée Alby 2018-06-14 13:59:11 +02:00 committed by GitHub
commit 55112dc7dc
5 changed files with 69 additions and 0 deletions

View file

@ -27,3 +27,13 @@ module.exports =
"exported project" "exported project"
res.send export_v1_id: export_data.v1_id res.send export_v1_id: export_data.v1_id
exportStatus: (req, res) ->
{export_id} = req.params
ExportsHandler.fetchExport export_id, (err, export_json) ->
return next(err) if err?
parsed_export = JSON.parse(export_json)
json = {
status_summary: parsed_export.status_summary,
status_detail: parsed_export.status_detail
}
res.send export_json: json

View file

@ -98,3 +98,18 @@ module.exports = ExportsHandler = self =
err = new Error("project history version returned a failure status code: #{res.statusCode}") err = new Error("project history version returned a failure status code: #{res.statusCode}")
logger.err err:err, project_id:project_id, "project history version returned failure status code: #{res.statusCode}" logger.err err:err, project_id:project_id, "project history version returned failure status code: #{res.statusCode}"
callback err callback err
fetchExport: (export_id, callback=(err, export_json) ->) ->
request.get {
url: "#{settings.apis.v1.url}/api/v1/sharelatex/exports/#{export_id}"
auth: {user: settings.apis.v1.user, pass: settings.apis.v1.pass }
}, (err, res, body) ->
if err?
logger.err err:err, export:export_id, "error making request to v1 export"
callback err
else if 200 <= res.statusCode < 300
callback null, body
else
err = new Error("v1 export returned a failure status code: #{res.statusCode}")
logger.err err:err, export:export_id, "v1 export returned failure status code: #{res.statusCode}"
callback err

View file

@ -227,6 +227,7 @@ module.exports = class Router
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.post '/project/:project_id/export/:brand_variation_id', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportProject
webRouter.get '/project/:project_id/export/:export_id', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportStatus
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

View file

@ -37,3 +37,15 @@ describe 'ExportsController', ->
@controller.exportProject @req, send:(body) => @controller.exportProject @req, send:(body) =>
expect(body).to.deep.equal {export_v1_id: 897} expect(body).to.deep.equal {export_v1_id: 897}
done() done()
it 'should ask the handler to return the status of an export', (done) ->
@handler.fetchExport = sinon.stub().yields(
null,
"{\"id\":897, \"status_summary\":\"completed\"}")
@req.params = {project_id: project_id, export_id: 897}
@controller.exportStatus @req, send:(body) =>
expect(body).to.deep.equal {export_json: {
status_summary: 'completed', status_detail: undefined
}}
done()

View file

@ -235,3 +235,34 @@ describe 'ExportsHandler', ->
it "should return the error", -> it "should return the error", ->
(@callback.args[0][0] instanceof Error) (@callback.args[0][0] instanceof Error)
.should.equal true .should.equal true
describe 'fetchExport', ->
beforeEach (done) ->
@settings.apis =
v1:
url: 'http://localhost:5000'
user: 'overleaf'
pass: 'pass'
@export_id = 897
@body = "{\"id\":897, \"status_summary\":\"completed\"}"
@stubGet = sinon.stub().yields(null, {statusCode: 200}, { body: @body })
done()
describe "when all goes well", ->
beforeEach (done) ->
@stubRequest.get = @stubGet
@ExportsHandler.fetchExport @export_id, (error, body) =>
@callback(error, body)
done()
it 'should issue the request', ->
expect(@stubGet.getCall(0).args[0]).to.deep.equal
url: @settings.apis.v1.url + '/api/v1/sharelatex/exports/' + @export_id
auth:
user: @settings.apis.v1.user
pass: @settings.apis.v1.pass
it 'should return the v1 export id', ->
@callback.calledWith(null, { body: @body })
.should.equal true