Эх сурвалжийг харах

Send source of update to doc updater on setDocument request

James Allen 12 жил өмнө
parent
commit
7e9318814d

+ 4 - 2
services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee

@@ -116,14 +116,16 @@ module.exports = DocumentUpdaterHandler =
 				logger.error project_id:project_id, doc_id:doc_id, url: url, "doc updater returned a non-success status code: #{res.statusCode}"
 				callback new Error("doc updater returned a non-success status code: #{res.statusCode}")
 
-	setDocument : (project_id, doc_id, docLines, callback = (error) ->)->
+	setDocument : (project_id, doc_id, docLines, source, callback = (error) ->)->
 		timer = new metrics.Timer("set-document")
 		url = "#{settings.apis.documentupdater.url}/project/#{project_id}/doc/#{doc_id}"
 		body =
 			url: url
 			json:
 				lines: docLines
-		logger.log project_id:project_id, doc_id: doc_id, "setting doc in document updater"
+			headers:
+				"x-sl-update-source": source
+		logger.log project_id:project_id, doc_id: doc_id, source: source, "setting doc in document updater"
 		request.post body, (error, res, body)->
 			timer.done()
 			if error?

+ 1 - 2
services/web/app/coffee/Features/Editor/EditorController.coffee

@@ -161,9 +161,8 @@ module.exports = EditorController =
 				callback()
 
 	setDoc: (project_id, doc_id, docLines, source, callback = (err)->)->
-		DocumentUpdaterHandler.setDocument project_id, doc_id, docLines, (err)=>
+		DocumentUpdaterHandler.setDocument project_id, doc_id, docLines, source, (err)=>
 			logger.log project_id:project_id, doc_id:doc_id, "notifying users that the document has been updated"
-			EditorRealTimeController.emitToRoom(project_id, "entireDocUpdate", doc_id, source)
 			DocumentUpdaterHandler.flushDocToMongo project_id, doc_id, callback
 
 	addDoc: (project_id, folder_id, docName, docLines, source, callback = (error, doc)->)->

+ 6 - 3
services/web/test/UnitTests/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee

@@ -213,11 +213,12 @@ describe 'Flushing documents :', ->
 	describe "setDocument", ->
 		beforeEach ->
 			@callback = sinon.stub()
+			@source = "dropbox"
 
 		describe "successfully", ->
 			beforeEach ->
 				@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 204}, "")
-				@handler.setDocument @project_id, @doc_id, @lines, @callback
+				@handler.setDocument @project_id, @doc_id, @lines, @source, @callback
 
 			it 'should set the document in the document updater', ->
 				url = "#{@settings.apis.documentupdater.url}/project/#{@project_id}/doc/#{@doc_id}"
@@ -226,6 +227,8 @@ describe 'Flushing documents :', ->
 						url: url
 						json:
 							lines: @lines
+						headers:
+							"x-sl-update-source": @source
 					})
 					.should.equal true
 
@@ -235,7 +238,7 @@ describe 'Flushing documents :', ->
 		describe "when the document updater API returns an error", ->
 			beforeEach ->
 				@request.post = sinon.stub().callsArgWith(1, @error = new Error("something went wrong"), null, null)
-				@handler.setDocument @project_id, @doc_id, @lines, @callback
+				@handler.setDocument @project_id, @doc_id, @lines, @source, @callback
 
 			it "should return an error to the callback", ->
 				@callback.calledWith(@error).should.equal true
@@ -243,7 +246,7 @@ describe 'Flushing documents :', ->
 		describe "when the document updater returns a failure error code", ->
 			beforeEach ->
 				@request.post = sinon.stub().callsArgWith(1, null, { statusCode: 500 }, "")
-				@handler.setDocument @project_id, @doc_id, @lines, @callback
+				@handler.setDocument @project_id, @doc_id, @lines, @source, @callback
 
 			it "should return the callback with an error", ->
 				@callback

+ 3 - 9
services/web/test/UnitTests/coffee/Editor/EditorControllerTests.coffee

@@ -415,22 +415,16 @@ describe "EditorController", ->
 		beforeEach ->
 			@docLines = ["foo", "bar"]
 			@DocumentUpdaterHandler.flushDocToMongo = sinon.stub().callsArg(2)
-			@DocumentUpdaterHandler.setDocument = sinon.stub().callsArg(3)
-			@EditorRealTimeController.emitToRoom = sinon.stub()
+			@DocumentUpdaterHandler.setDocument = sinon.stub().callsArg(4)
 
 		it 'should send the document to the documentUpdaterHandler', (done)->
-			@DocumentUpdaterHandler.setDocument = sinon.stub().withArgs(@project_id, @doc_id, @docLines).callsArg(3)
+			@DocumentUpdaterHandler.setDocument = sinon.stub().withArgs(@project_id, @doc_id, @docLines, @source).callsArg(4)
 			@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)->
 				done()
 
-		it 'should send the update to the connected users', (done)->
-			@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)=>
-				@EditorRealTimeController.emitToRoom.calledWith(@project_id, "entireDocUpdate", @doc_id, @source).should.equal true
-				done()
-
 		it 'should send the new doc lines to the doucment updater', (done)->
 			@DocumentUpdaterHandler.setDocument = ->
-			mock = sinon.mock(@DocumentUpdaterHandler).expects("setDocument").withArgs(@project_id, @doc_id, @docLines).once().callsArg(3)
+			mock = sinon.mock(@DocumentUpdaterHandler).expects("setDocument").withArgs(@project_id, @doc_id, @docLines, @source).once().callsArg(4)
 
 			@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)=>
 				mock.verify()