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

archive in track changes as well as docstore

Henry Oswald 11 лет назад
Родитель
Сommit
2c32126f68

+ 10 - 4
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)
 

+ 13 - 1
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)

+ 22 - 4
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)=>

+ 15 - 0
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()