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

Send an empty string for every nameless user

Chrystal Griffiths 7 лет назад
Родитель
Сommit
cb12e1c6f6

+ 17 - 19
services/real-time/app/coffee/WebsocketController.coffee

@@ -145,26 +145,24 @@ module.exports = WebsocketController =
 				cursorData.id      = client.id
 				cursorData.user_id = user_id if user_id?
 				cursorData.email   = email   if email?
-				if first_name or last_name
-					cursorData.name = if first_name && last_name
-						"#{first_name} #{last_name}"
-					else if first_name
-						first_name
-					else if last_name
-						last_name
-					ConnectedUsersManager.updateUserPosition(project_id, client.id, {
-						first_name: first_name,
-						last_name:  last_name,
-						email:      email,
-						_id:        user_id
-					}, {
-						row:    cursorData.row,
-						column: cursorData.column,
-						doc_id: cursorData.doc_id
-					}, callback)
+				cursorData.name = if first_name && last_name
+					"#{first_name} #{last_name}"
+				else if first_name
+					first_name
+				else if last_name
+					last_name
 				else
-					cursorData.name = "Anonymous"
-					callback()
+					""
+				ConnectedUsersManager.updateUserPosition(project_id, client.id, {
+					first_name: first_name,
+					last_name:  last_name,
+					email:      email,
+					_id:        user_id
+				}, {
+					row:    cursorData.row,
+					column: cursorData.column,
+					doc_id: cursorData.doc_id
+				}, callback)
 				WebsocketLoadBalancer.emitToRoom(project_id, "clientTracking.clientUpdated", cursorData)
 
 	getConnectedUsers: (client, callback = (error, users) ->) ->

+ 27 - 7
services/real-time/test/unit/coffee/WebsocketControllerTests.coffee

@@ -426,7 +426,7 @@ describe 'WebsocketController', ->
 					doc_id: @doc_id
 				}).should.equal true
 				done()
-				
+
 			it "should increment the update-client-position metric at 0.1 frequency", ->
 				@metrics.inc.calledWith("editor.update-client-position", 0.1).should.equal true
 
@@ -509,6 +509,30 @@ describe 'WebsocketController', ->
 
 			it "should increment the update-client-position metric at 0.1 frequency", ->
 				@metrics.inc.calledWith("editor.update-client-position", 0.1).should.equal true
+		describe "with a logged in user who has no names set", ->
+			beforeEach ->
+				@clientParams = {
+					project_id: @project_id
+					first_name: undefined
+					last_name: undefined
+					email: @email = "joe@example.com"
+					user_id: @user_id = "user-id-123"
+				}
+				@client.get = (param, callback) => callback null, @clientParams[param]
+				@WebsocketController.updateClientPosition @client, @update
+
+			it "should send the update to the project name with no name", ->
+				@WebsocketLoadBalancer.emitToRoom
+					.calledWith(@project_id, "clientTracking.clientUpdated", {
+						doc_id: @doc_id,
+						id: @client.id,
+						user_id: @user_id,
+						name: "",
+						row: @row,
+						column: @column,
+						email: @email
+					})
+					.should.equal true
 
 
 		describe "with an anonymous user", ->
@@ -519,20 +543,16 @@ describe 'WebsocketController', ->
 				@client.get = (param, callback) => callback null, @clientParams[param]
 				@WebsocketController.updateClientPosition @client, @update
 
-			it "should send the update to the project room with an anonymous name", ->
+			it "should send the update to the project room with no name", ->
 				@WebsocketLoadBalancer.emitToRoom
 					.calledWith(@project_id, "clientTracking.clientUpdated", {
 						doc_id: @doc_id,
 						id: @client.id
-						name: "Anonymous"
+						name: ""
 						row: @row
 						column: @column
 					})
 					.should.equal true
-				
-			it "should not send cursor data to the connected user manager", (done)->
-				@ConnectedUsersManager.updateUserPosition.called.should.equal false
-				done()
 
 	describe "applyOtUpdate", ->
 		beforeEach ->