diff --git a/services/web/app/coffee/Features/InactiveData/InactiveProjectManager.coffee b/services/web/app/coffee/Features/InactiveData/InactiveProjectManager.coffee index 7885107c92..c73be84517 100644 --- a/services/web/app/coffee/Features/InactiveData/InactiveProjectManager.coffee +++ b/services/web/app/coffee/Features/InactiveData/InactiveProjectManager.coffee @@ -5,6 +5,8 @@ DocstoreManager = require("../Docstore/DocstoreManager") ProjectGetter = require("../Project/ProjectGetter") ProjectUpdateHandler = require("../Project/ProjectUpdateHandler") Project = require("../../models/Project").Project +TrackChangesManager = require("../TrackChanges/TrackChangesManager") + MILISECONDS_IN_DAY = 86400000 module.exports = InactiveProjectManager = @@ -48,9 +50,13 @@ module.exports = InactiveProjectManager = deactivateProject: (project_id, callback)-> logger.log project_id:project_id, "deactivating inactive project" - DocstoreManager.archiveProject project_id, (err)-> + jobs = [ + (cb)-> DocstoreManager.archiveProject project_id, cb + (cb)-> TrackChangesManager.archiveProject project_id, cb + (cb)-> ProjectUpdateHandler.markAsInactive project_id, cb + ] + async.series jobs, (err)-> if err? - logger.err err:err, project_id:project_id, "error deactivating project in docstore" - return callback(err) - ProjectUpdateHandler.markAsInactive project_id, callback + logger.err err:err, project_id:project_id, "error deactivating project" + callback(err) diff --git a/services/web/app/coffee/Features/TrackChanges/TrackChangesManager.coffee b/services/web/app/coffee/Features/TrackChanges/TrackChangesManager.coffee index 49fa956cf6..ddcfe3e44a 100644 --- a/services/web/app/coffee/Features/TrackChanges/TrackChangesManager.coffee +++ b/services/web/app/coffee/Features/TrackChanges/TrackChangesManager.coffee @@ -11,6 +11,18 @@ module.exports = TrackChangesManager = if 200 <= res.statusCode < 300 callback(null) else - error = new Error("track-changes api responded with non-success code: #{res.statusCode}") + error = new Error("track-changes api responded with non-success code: #{res.statusCode} #{url}") logger.error err: error, project_id: project_id, "error flushing project in track-changes api" + callback(error) + + archiveProject: (project_id, callback = ()->)-> + logger.log project_id: project_id, "archving project in track-changes api" + url = "#{settings.apis.trackchanges.url}/project/#{project_id}/archive" + request.post url, (error, res, body) -> + return callback(error) if error? + if 200 <= res.statusCode < 300 + callback(null) + else + error = new Error("track-changes api responded with non-success code: #{res.statusCode} #{url}") + logger.error err: error, project_id: project_id, "error archving project in track-changes api" callback(error) \ No newline at end of file diff --git a/services/web/test/UnitTests/coffee/InactiveData/InactiveProjectManagerTests.coffee b/services/web/test/UnitTests/coffee/InactiveData/InactiveProjectManagerTests.coffee index 6befd7f70f..40ef0ce906 100644 --- a/services/web/test/UnitTests/coffee/InactiveData/InactiveProjectManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/InactiveData/InactiveProjectManagerTests.coffee @@ -19,6 +19,8 @@ describe "InactiveProjectManager", -> markAsInactive:sinon.stub() @ProjectGetter = getProject:sinon.stub() + @TrackChangesManager = + archiveProject:sinon.stub() @InactiveProjectManager = SandboxedModule.require modulePath, requires: "settings-sharelatex":@settings "logger-sharelatex": @@ -27,7 +29,7 @@ describe "InactiveProjectManager", -> "../Docstore/DocstoreManager":@DocstoreManager "../Project/ProjectUpdateHandler":@ProjectUpdateHandler "../Project/ProjectGetter":@ProjectGetter - + "../TrackChanges/TrackChangesManager":@TrackChangesManager @project_id = "1234" describe "reactivateProjectIfRequired", -> @@ -64,19 +66,35 @@ describe "InactiveProjectManager", -> describe "deactivateProject", -> - beforeEach -> - it "should call unarchiveProject and markAsInactive", (done)-> @DocstoreManager.archiveProject.callsArgWith(1) + @TrackChangesManager.archiveProject.callsArgWith(1) + @ProjectUpdateHandler.markAsInactive.callsArgWith(1) @InactiveProjectManager.deactivateProject @project_id, (err)=> @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true + @TrackChangesManager.archiveProject.calledWith(@project_id).should.equal true @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal true done() - it "should not call markAsInactive if there was a problem unarchiving", (done)-> + it "should not call markAsInactive if there was a problem archiving in docstore", (done)-> @DocstoreManager.archiveProject.callsArgWith(1, "errorrr") + @TrackChangesManager.archiveProject.callsArgWith(1) + + @ProjectUpdateHandler.markAsInactive.callsArgWith(1) + + @InactiveProjectManager.deactivateProject @project_id, (err)=> + err.should.equal "errorrr" + @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true + @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal false + done() + + + it "should not call markAsInactive if there was a problem archiving in track changes", (done)-> + @DocstoreManager.archiveProject.callsArgWith(1) + @TrackChangesManager.archiveProject.callsArgWith(1, "errorrr") + @ProjectUpdateHandler.markAsInactive.callsArgWith(1) @InactiveProjectManager.deactivateProject @project_id, (err)=> diff --git a/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesManagerTests.coffee b/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesManagerTests.coffee index 7dad07e48b..90b36f89c5 100644 --- a/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesManagerTests.coffee @@ -1,4 +1,5 @@ chai = require('chai') +expect = chai.expect chai.should() sinon = require("sinon") modulePath = "../../../../app/js/Features/TrackChanges/TrackChangesManager" @@ -15,6 +16,7 @@ describe "TrackChangesManager", -> "logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()} @project_id = "project-id-123" @callback = sinon.stub() + @request.post = sinon.stub() describe "flushProject", -> describe "with a successful response code", -> @@ -46,3 +48,16 @@ describe "TrackChangesManager", -> }, "error flushing project in track-changes api") .should.equal true + describe "ArchiveProject", -> + + it "should call the post endpoint", (done)-> + @request.post.callsArgWith(1, null, {}) + @TrackChangesManager.archiveProject @project_id, (err)=> + @request.post.calledWith("#{@settings.apis.trackchanges.url}/project/#{@project_id}/archive") + done() + + it "should return an error on a non success", (done)-> + @request.post.callsArgWith(1, null, {statusCode:500}) + @TrackChangesManager.archiveProject @project_id, (err)=> + expect(err).to.exist + done() \ No newline at end of file