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

Filter "comments" if restricted user.

Shane Kilkelly 7 лет назад
Родитель
Сommit
6df88ebc49

+ 4 - 1
services/real-time/app/coffee/WebsocketController.coffee

@@ -85,7 +85,7 @@ module.exports = WebsocketController =
 
 
 	joinDoc: (client, doc_id, fromVersion = -1, options, callback = (error, doclines, version, ops, ranges) ->) ->
 	joinDoc: (client, doc_id, fromVersion = -1, options, callback = (error, doclines, version, ops, ranges) ->) ->
 		metrics.inc "editor.join-doc"
 		metrics.inc "editor.join-doc"
-		Utils.getClientAttributes client, ["project_id", "user_id"], (error, {project_id, user_id}) ->
+		Utils.getClientAttributes client, ["project_id", "user_id", "is_restricted_user"], (error, {project_id, user_id, is_restricted_user}) ->
 			return callback(error) if error?
 			return callback(error) if error?
 			return callback(new Error("no project_id found on client")) if !project_id?
 			return callback(new Error("no project_id found on client")) if !project_id?
 			logger.log {user_id, project_id, doc_id, fromVersion, client_id: client.id}, "client joining doc"
 			logger.log {user_id, project_id, doc_id, fromVersion, client_id: client.id}, "client joining doc"
@@ -99,6 +99,9 @@ module.exports = WebsocketController =
 					DocumentUpdaterManager.getDocument project_id, doc_id, fromVersion, (error, lines, version, ranges, ops) ->
 					DocumentUpdaterManager.getDocument project_id, doc_id, fromVersion, (error, lines, version, ranges, ops) ->
 						return callback(error) if error?
 						return callback(error) if error?
 
 
+						if is_restricted_user and ranges?.comments?
+							ranges.comments = []
+
 						# Encode any binary bits of data so it can go via WebSockets
 						# Encode any binary bits of data so it can go via WebSockets
 						# See http://ecmanaut.blogspot.co.uk/2006/07/encoding-decoding-utf8-in-javascript.html
 						# See http://ecmanaut.blogspot.co.uk/2006/07/encoding-decoding-utf8-in-javascript.html
 						encodeForWebsockets = (text) -> unescape(encodeURIComponent(text))
 						encodeForWebsockets = (text) -> unescape(encodeURIComponent(text))

+ 11 - 0
services/real-time/test/unit/coffee/WebsocketControllerTests.coffee

@@ -238,6 +238,7 @@ describe 'WebsocketController', ->
 			@options = {}
 			@options = {}
 
 
 			@client.params.project_id = @project_id
 			@client.params.project_id = @project_id
+			@client.params.is_restricted_user = false
 			@AuthorizationManager.addAccessToDoc = sinon.stub()
 			@AuthorizationManager.addAccessToDoc = sinon.stub()
 			@AuthorizationManager.assertClientCanViewProject = sinon.stub().callsArgWith(1, null)
 			@AuthorizationManager.assertClientCanViewProject = sinon.stub().callsArgWith(1, null)
 			@DocumentUpdaterManager.getDocument = sinon.stub().callsArgWith(3, null, @doc_lines, @version, @ranges, @ops)
 			@DocumentUpdaterManager.getDocument = sinon.stub().callsArgWith(3, null, @doc_lines, @version, @ranges, @ops)
@@ -338,6 +339,16 @@ describe 'WebsocketController', ->
 			it "should not call the DocumentUpdaterManager", ->
 			it "should not call the DocumentUpdaterManager", ->
 				@DocumentUpdaterManager.getDocument.called.should.equal false
 				@DocumentUpdaterManager.getDocument.called.should.equal false
 
 
+		describe "with a restricted client", ->
+			beforeEach ->
+				@ranges.comments = [{op: {a: 1}}, {op: {a: 2}}]
+				@client.params.is_restricted_user = true
+				@WebsocketController.joinDoc @client, @doc_id, -1, @options, @callback
+
+			it "should overwrite ranges.comments with an empty list", ->
+				ranges = @callback.args[0][4]
+				expect(ranges.comments).to.deep.equal []
+
 	describe "leaveDoc", ->
 	describe "leaveDoc", ->
 		beforeEach ->
 		beforeEach ->
 			@doc_id = "doc-id-123"
 			@doc_id = "doc-id-123"