فهرست منبع

Convert 'anonymous-user' from real-time api in 'null' internally

James Allen 10 سال پیش
والد
کامیت
f182fbf396

+ 2 - 0
services/web/app/coffee/Features/Editor/EditorHttpController.coffee

@@ -15,6 +15,8 @@ module.exports = EditorHttpController =
 	joinProject: (req, res, next) ->
 		project_id = req.params.Project_id
 		user_id = req.query.user_id
+		if user_id == "anonymous-user"
+			user_id = null
 		logger.log {user_id, project_id}, "join project request"
 		Metrics.inc "editor.join-project"
 		EditorHttpController._buildJoinProjectView project_id, user_id, (error, project, privilegeLevel) ->

+ 11 - 0
services/web/test/UnitTests/coffee/Editor/EditorHttpControllerTests.coffee

@@ -77,6 +77,17 @@ describe "EditorHttpController", ->
 				@ProjectDeleter.unmarkAsDeletedByExternalSource 
 					.calledWith(@project_id)
 					.should.equal true
+					
+		describe "with an anonymous user", ->
+			beforeEach ->
+				@req.query =
+					user_id: "anonymous-user"
+				@EditorHttpController.joinProject @req, @res
+			
+			it "should pass the user id as null", ->
+				@EditorHttpController._buildJoinProjectView
+					.calledWith(@project_id, null)
+					.should.equal true
 
 	describe "_buildJoinProjectView", ->
 		beforeEach ->

+ 5 - 1
services/web/test/acceptance/coffee/AuthorizationTests.coffee

@@ -56,9 +56,13 @@ try_admin_access = (user, project_id, test, callback) ->
 try_content_access = (user, project_id, test, callback) ->
 	# The real-time service calls this end point to determine the user's 
 	# permissions.
+	if user.id?
+		user_id = user.id
+	else
+		user_id = "anonymous-user"
 	request.post {
 		url: "/project/#{project_id}/join"
-		qs: {user_id: user.id}
+		qs: {user_id}
 		auth:
 			user: settings.apis.web.user
 			pass: settings.apis.web.pass