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

Send user_id on Dropbox requests through to doc updater

James Allen 10 лет назад
Родитель
Сommit
6143b2218c

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

@@ -116,7 +116,7 @@ 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, source, callback = (error) ->)->
+	setDocument : (project_id, doc_id, user_id, docLines, source, callback = (error) ->)->
 		timer = new metrics.Timer("set-document")
 		url = "#{settings.apis.documentupdater.url}/project/#{project_id}/doc/#{doc_id}"
 		body =
@@ -124,7 +124,8 @@ module.exports = DocumentUpdaterHandler =
 			json:
 				lines: docLines
 				source: source
-		logger.log project_id:project_id, doc_id: doc_id, source: source, "setting doc in document updater"
+				user_id: user_id
+		logger.log project_id:project_id, doc_id: doc_id, source: source, user_id: user_id, "setting doc in document updater"
 		request.post body, (error, res, body)->
 			timer.done()
 			if error?

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

@@ -13,8 +13,8 @@ LockManager = require("../../infrastructure/LockManager")
 _ = require('underscore')
 
 module.exports = EditorController =
-	setDoc: (project_id, doc_id, docLines, source, callback = (err)->)->
-		DocumentUpdaterHandler.setDocument project_id, doc_id, docLines, source, (err)=>
+	setDoc: (project_id, doc_id, user_id, docLines, source, callback = (err)->)->
+		DocumentUpdaterHandler.setDocument project_id, doc_id, user_id, docLines, source, (err)=>
 			logger.log project_id:project_id, doc_id:doc_id, "notifying users that the document has been updated"
 			DocumentUpdaterHandler.flushDocToMongo project_id, doc_id, callback
 

+ 1 - 1
services/web/app/coffee/Features/ThirdPartyDataStore/TpdsController.coffee

@@ -45,7 +45,7 @@ module.exports =
 		path = "/" + req.params[0] # UpdateMerger expects leading slash
 		source = req.headers["x-sl-update-source"] or "unknown"
 		logger.log project_id: project_id, path: path, source: source, "received project contents update"
-		UpdateMerger.mergeUpdate project_id, path, req, source, (error) ->
+		UpdateMerger.mergeUpdate null, project_id, path, req, source, (error) ->
 			return next(error) if error?
 			res.sendStatus(200)
 			

+ 1 - 1
services/web/app/coffee/Features/ThirdPartyDataStore/TpdsUpdateHandler.coffee

@@ -27,7 +27,7 @@ module.exports =
 			FileTypeManager.shouldIgnore path, (err, shouldIgnore)->
 				if shouldIgnore
 					return callback()
-				updateMerger.mergeUpdate project._id, path, updateRequest, source, callback
+				updateMerger.mergeUpdate user_id, project._id, path, updateRequest, source, callback
 
 
 	deleteUpdate: (user_id, projectName, path, source, callback)->	

+ 4 - 4
services/web/app/coffee/Features/ThirdPartyDataStore/UpdateMerger.coffee

@@ -8,7 +8,7 @@ uuid = require('node-uuid')
 fs = require('fs')
 
 module.exports =
-	mergeUpdate: (project_id, path, updateRequest, source, callback = (error) ->)->
+	mergeUpdate: (user_id, project_id, path, updateRequest, source, callback = (error) ->)->
 		self = @
 		logger.log project_id:project_id, path:path, "merging update from tpds"
 		projectLocator.findElementByPath project_id, path, (err, element)=>
@@ -30,7 +30,7 @@ module.exports =
 					if isFile
 						self.p.processFile project_id, elementId, fsPath, path, source, callback
 					else
-						self.p.processDoc project_id, elementId, fsPath, path, source, callback
+						self.p.processDoc project_id, elementId, user_id, fsPath, path, source, callback
 
 	deleteUpdate: (project_id, path, source, callback)->
 		projectLocator.findElementByPath project_id, path, (err, element)->
@@ -49,14 +49,14 @@ module.exports =
 
 	p:
 
-		processDoc: (project_id, doc_id, fsPath, path, source, callback)->
+		processDoc: (project_id, doc_id, user_id, fsPath, path, source, callback)->
 			readFileIntoTextArray fsPath, (err, docLines)->
 				if err?
 					logger.err project_id:project_id, doc_id:doc_id, fsPath:fsPath, "error reading file into text array for process doc update"
 					return callback(err)
 				logger.log docLines:docLines, doc_id:doc_id, project_id:project_id, "processing doc update from tpds"
 				if doc_id?
-					editorController.setDoc project_id, doc_id, docLines, source, (err)->
+					editorController.setDoc project_id, doc_id, user_id, docLines, source, (err)->
 						callback()
 				else
 					setupNewEntity project_id, path, (err, folder, fileName)->

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

@@ -15,6 +15,7 @@ describe 'Flushing documents :', ->
 		@doc_id = "doc-id-394"
 		@lines = ["one", "two", "three"]
 		@version = 42
+		@user_id = "mock-user-id-123"
 		@project =
 			_id: @project_id
 
@@ -218,7 +219,7 @@ describe 'Flushing documents :', ->
 		describe "successfully", ->
 			beforeEach ->
 				@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 204}, "")
-				@handler.setDocument @project_id, @doc_id, @lines, @source, @callback
+				@handler.setDocument @project_id, @doc_id, @user_id, @lines, @source, @callback
 
 			it 'should set the document in the document updater', ->
 				url = "#{@settings.apis.documentupdater.url}/project/#{@project_id}/doc/#{@doc_id}"
@@ -228,6 +229,7 @@ describe 'Flushing documents :', ->
 						json:
 							lines: @lines
 							source: @source
+							user_id: @user_id
 					})
 					.should.equal true
 
@@ -237,7 +239,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, @source, @callback
+				@handler.setDocument @project_id, @doc_id, @user_id, @lines, @source, @callback
 
 			it "should return an error to the callback", ->
 				@callback.calledWith(@error).should.equal true
@@ -245,7 +247,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, @source, @callback
+				@handler.setDocument @project_id, @doc_id, @user_id, @lines, @source, @callback
 
 			it "should return the callback with an error", ->
 				@callback

+ 6 - 6
services/web/test/UnitTests/coffee/Editor/EditorControllerTests.coffee

@@ -98,23 +98,23 @@ describe "EditorController", ->
 		beforeEach ->
 			@docLines = ["foo", "bar"]
 			@DocumentUpdaterHandler.flushDocToMongo = sinon.stub().callsArg(2)
-			@DocumentUpdaterHandler.setDocument = sinon.stub().callsArg(4)
+			@DocumentUpdaterHandler.setDocument = sinon.stub().callsArg(5)
 
 		it 'should send the document to the documentUpdaterHandler', (done)->
-			@DocumentUpdaterHandler.setDocument = sinon.stub().withArgs(@project_id, @doc_id, @docLines, @source).callsArg(4)
-			@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)->
+			@DocumentUpdaterHandler.setDocument = sinon.stub().withArgs(@project_id, @doc_id, @user_id, @docLines, @source).callsArg(5)
+			@EditorController.setDoc @project_id, @doc_id, @user_id, @docLines, @source, (err)->
 				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, @source).once().callsArg(4)
+			mock = sinon.mock(@DocumentUpdaterHandler).expects("setDocument").withArgs(@project_id, @doc_id, @user_id, @docLines, @source).once().callsArg(5)
 
-			@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)=>
+			@EditorController.setDoc @project_id, @doc_id, @user_id, @docLines, @source, (err)=>
 				mock.verify()
 				done()
 
 		it 'should flush the doc to mongo', (done)->
-			@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)=>
+			@EditorController.setDoc @project_id, @doc_id, @user_id, @docLines, @source, (err)=>
 				@DocumentUpdaterHandler.flushDocToMongo.calledWith(@project_id, @doc_id).should.equal true
 				done()
 

+ 2 - 2
services/web/test/UnitTests/coffee/ThirdPartyDataStore/TpdsControllerTests.coffee

@@ -76,7 +76,7 @@ describe 'TpdsController', ->
 			
 	describe 'updateProjectContents', ->
 		beforeEach ->
-			@UpdateMerger.mergeUpdate = sinon.stub().callsArg(4)
+			@UpdateMerger.mergeUpdate = sinon.stub().callsArg(5)
 			@req =
 				params:
 					0: @path = "chapters/main.tex"
@@ -92,7 +92,7 @@ describe 'TpdsController', ->
 			
 		it "should merge the update", ->
 			@UpdateMerger.mergeUpdate
-				.calledWith(@project_id, "/" + @path, @req, @source)
+				.calledWith(null, @project_id, "/" + @path, @req, @source)
 				.should.equal true
 				
 		it "should return a success", ->

+ 2 - 2
services/web/test/UnitTests/coffee/ThirdPartyDataStore/TpdsUpdateHandlerTests.coffee

@@ -8,7 +8,7 @@ describe 'TpdsUpdateHandler', ->
 		@requestQueuer = {}
 		@updateMerger = 
 			deleteUpdate: (user_id, path, source, cb)->cb()
-			mergeUpdate:(user_id, path, update, source, cb)->cb()
+			mergeUpdate:(user_id, project_id, path, update, source, cb)->cb()
 		@editorController = {}
 		@project_id = "dsjajilknaksdn"
 		@project = {_id:@project_id, name:"projectNameHere"}
@@ -36,7 +36,7 @@ describe 'TpdsUpdateHandler', ->
 			path = "/path/here"
 			update = {}
 			@updateMerger.mergeUpdate = sinon.stub()
-			@updateMerger.mergeUpdate.withArgs(@project_id, path, update, @source).callsArg(4)
+			@updateMerger.mergeUpdate.withArgs(@user_id, @project_id, path, update, @source).callsArg(5)
 			@handler.newUpdate @user_id, @project.name, path, update, @source, =>
 				@projectCreationHandler.createBlankProject.called.should.equal false
 				done()

+ 9 - 8
services/web/test/UnitTests/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee

@@ -24,6 +24,7 @@ describe 'UpdateMerger :', ->
 				log: ->
 				err: ->
 		@project_id = "project_id_here"
+		@user_id = "mock-user-id"
 		@source = "dropbox"
 		@update = new BufferedStream()
 		@update.headers = {}
@@ -37,7 +38,7 @@ describe 'UpdateMerger :', ->
 
 		it 'should get the element id', (done)->
 			@projectLocator.findElementByPath = sinon.spy()
-			@updateMerger.mergeUpdate @project_id, @path, @update, @source, =>
+			@updateMerger.mergeUpdate @user_id, @project_id, @path, @update, @source, =>
 			@projectLocator.findElementByPath.calledWith(@project_id, @path).should.equal true
 			done()
 
@@ -45,12 +46,12 @@ describe 'UpdateMerger :', ->
 			doc_id = "231312s"
 			@FileTypeManager.isBinary.callsArgWith(2, null, false)
 			@projectLocator.findElementByPath = (_, __, cb)->cb(null, {_id:doc_id})
-			@updateMerger.p.processDoc = sinon.stub().callsArgWith(5)
+			@updateMerger.p.processDoc = sinon.stub().callsArgWith(6)
 			filePath = "/folder/doc.tex"
 
-			@updateMerger.mergeUpdate @project_id, filePath, @update, @source, =>
+			@updateMerger.mergeUpdate @user_id, @project_id, filePath, @update, @source, =>
 				@FileTypeManager.isBinary.calledWith(filePath, @fsPath).should.equal true
-				@updateMerger.p.processDoc.calledWith(@project_id, doc_id, @fsPath, filePath, @source).should.equal true
+				@updateMerger.p.processDoc.calledWith(@project_id, doc_id, @user_id, @fsPath, filePath, @source).should.equal true
 				@fs.unlink.calledWith(@fsPath).should.equal true
 				done()
 
@@ -61,7 +62,7 @@ describe 'UpdateMerger :', ->
 			@updateMerger.p.processFile = sinon.stub().callsArgWith(5)
 			filePath = "/folder/file1.png"
 
-			@updateMerger.mergeUpdate @project_id, filePath, @update, @source, =>
+			@updateMerger.mergeUpdate @user_id, @project_id, filePath, @update, @source, =>
 				@updateMerger.p.processFile.calledWith(@project_id, file_id, @fsPath, filePath, @source).should.equal true
 				@FileTypeManager.isBinary.calledWith(filePath, @fsPath).should.equal true
 				@fs.unlink.calledWith(@fsPath).should.equal true
@@ -77,12 +78,12 @@ describe 'UpdateMerger :', ->
 
 		it 'should set the doc text in the editor controller', (done)->
 			@editorController.setDoc = ->
-			mock = sinon.mock(@editorController).expects("setDoc").withArgs(@project_id, @doc_id, @splitDocLines, @source).callsArg(4)
+			mock = sinon.mock(@editorController).expects("setDoc").withArgs(@project_id, @doc_id, @user_id, @splitDocLines, @source).callsArg(5)
 
 			@update.write(@docLines)
 			@update.end()
 
-			@updateMerger.p.processDoc @project_id, @doc_id, @update, "path", @source, ->
+			@updateMerger.p.processDoc @project_id, @doc_id, @user_id, @update, "path", @source, ->
 				mock.verify()
 				done()
 
@@ -97,7 +98,7 @@ describe 'UpdateMerger :', ->
 			@update.write(@docLines)
 			@update.end()
 
-			@updateMerger.p.processDoc @project_id, undefined, @update, path, @source, ->
+			@updateMerger.p.processDoc @project_id, undefined, @user_id, @update, path, @source, ->
 				mock.verify()
 				done()