فهرست منبع

Rename functions to make distinction between invited/token members

Shane Kilkelly 9 سال پیش
والد
کامیت
ef7e1ceabf

+ 1 - 1
services/web/app/coffee/Features/Collaborators/CollaboratorsController.coffee

@@ -33,7 +33,7 @@ module.exports = CollaboratorsController =
 	getAllMembers: (req, res, next) ->
 		projectId = req.params.Project_id
 		logger.log {projectId}, "getting all active members for project"
-		CollaboratorsHandler.getAllMembers projectId, (err, members) ->
+		CollaboratorsHandler.getAllInvitedMembers projectId, (err, members) ->
 			if err?
 				logger.err {projectId}, "error getting members for project"
 				return next(err)

+ 4 - 4
services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee

@@ -99,11 +99,11 @@ module.exports = CollaboratorsHandler =
 			return callback(error) if error?
 			return callback null, count - 1 # Don't count project owner
 
-	isUserMemberOfProject: (user_id, project_id, callback = (error, isMember, privilegeLevel) ->) ->
+	isUserInvitedMemberOfProject: (user_id, project_id, callback = (error, isMember, privilegeLevel) ->) ->
 		CollaboratorsHandler.getMemberIdsWithPrivilegeLevels project_id, (error, members = []) ->
 			return callback(error) if error?
 			for member in members
-				if member.id.toString() == user_id.toString()
+				if member.id.toString() == user_id.toString() and member.source == Sources.INVITE
 					return callback null, true, member.privilegeLevel
 			return callback null, false, null
 
@@ -186,9 +186,9 @@ module.exports = CollaboratorsHandler =
 						logger.error {err: error, project_id, user_id}, "error flushing to TPDS after adding collaborator"
 				callback()
 
-	getAllMembers: (projectId, callback=(err, members)->) ->
+	getAllInvitedMembers: (projectId, callback=(err, members)->) ->
 		logger.log {projectId}, "fetching all members"
-		CollaboratorsHandler.getMembersWithPrivilegeLevels projectId, (error, rawMembers) ->
+		CollaboratorsHandler.getInvitedMembersWithPrivilegeLevels projectId, (error, rawMembers) ->
 			if error?
 				logger.err {projectId, error}, "error getting members for project"
 				return callback(error)

+ 1 - 1
services/web/app/coffee/Features/Collaborators/CollaboratorsInviteController.coffee

@@ -114,7 +114,7 @@ module.exports = CollaboratorsInviteController =
 			res.render "project/invite/not-valid", {title: "Invalid Invite"}
 		# check if the user is already a member of the project
 		currentUser = AuthenticationController.getSessionUser(req)
-		CollaboratorsHandler.isUserMemberOfProject currentUser._id, projectId, (err, isMember, _privilegeLevel) ->
+		CollaboratorsHandler.isUserInvitedMemberOfProject currentUser._id, projectId, (err, isMember, _privilegeLevel) ->
 			if err?
 				logger.err {err, projectId}, "error checking if user is member of project"
 				return next(err)

+ 4 - 4
services/web/test/UnitTests/coffee/Collaborators/CollaboratorsControllerTests.coffee

@@ -82,7 +82,7 @@ describe "CollaboratorsController", ->
 			@res.json = sinon.stub()
 			@next = sinon.stub()
 			@members = [{a: 1}]
-			@CollaboratorsHandler.getAllMembers = sinon.stub().callsArgWith(1, null, @members)
+			@CollaboratorsHandler.getAllInvitedMembers = sinon.stub().callsArgWith(1, null, @members)
 			@CollaboratorsController.getAllMembers(@req, @res, @next)
 
 		it 'should not produce an error', ->
@@ -93,13 +93,13 @@ describe "CollaboratorsController", ->
 			@res.json.calledWith({members: @members}).should.equal true
 
 		it 'should call CollaboratorsHandler.getAllMembers', ->
-			@CollaboratorsHandler.getAllMembers.callCount.should.equal 1
+			@CollaboratorsHandler.getAllInvitedMembers.callCount.should.equal 1
 
-		describe 'when CollaboratorsHandler.getAllMembers produces an error', ->
+		describe 'when CollaboratorsHandler.getAllInvitedMembers produces an error', ->
 			beforeEach ->
 				@res.json = sinon.stub()
 				@next = sinon.stub()
-				@CollaboratorsHandler.getAllMembers = sinon.stub().callsArgWith(1, new Error('woops'))
+				@CollaboratorsHandler.getAllInvitedMembers = sinon.stub().callsArgWith(1, new Error('woops'))
 				@CollaboratorsController.getAllMembers(@req, @res, @next)
 
 			it 'should produce an error', ->

+ 14 - 14
services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee

@@ -157,17 +157,17 @@ describe "CollaboratorsHandler", ->
 				expect(level).to.equal false
 				done()
 
-	describe "isUserMemberOfProject", ->
+	describe "isUserInvitedMemberOfProject", ->
 		beforeEach ->
 			@CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub()
 
 		describe "when user is a member of the project", ->
 			beforeEach ->
 				@CollaboratorHandler.getMemberIdsWithPrivilegeLevels.withArgs(@project_id).yields(null, [
-					{ id: "not-the-user", privilegeLevel: "readOnly" }
-					{ id: @user_id, privilegeLevel: "readAndWrite" }
+					{ id: "not-the-user", privilegeLevel: "readOnly", source: 'invite' }
+					{ id: @user_id, privilegeLevel: "readAndWrite", source: 'invite' }
 				])
-				@CollaboratorHandler.isUserMemberOfProject @user_id, @project_id, @callback
+				@CollaboratorHandler.isUserInvitedMemberOfProject @user_id, @project_id, @callback
 
 			it "should return true and the privilegeLevel", ->
 				@callback
@@ -179,7 +179,7 @@ describe "CollaboratorsHandler", ->
 				@CollaboratorHandler.getMemberIdsWithPrivilegeLevels.withArgs(@project_id).yields(null, [
 					{ id: "not-the-user", privilegeLevel: "readOnly" }
 				])
-				@CollaboratorHandler.isUserMemberOfProject @user_id, @project_id, @callback
+				@CollaboratorHandler.isUserInvitedMemberOfProject @user_id, @project_id, @callback
 
 			it "should return false", ->
 				@callback
@@ -314,7 +314,7 @@ describe "CollaboratorsHandler", ->
 					.calledWith(project_id, @user_id)
 					.should.equal true
 
-	describe 'getAllMembers', ->
+	describe 'getAllInvitedMembers', ->
 
 		beforeEach ->
 			@owning_user = {_id: 'owner-id', email: 'owner@example.com', features: {a: 1}}
@@ -323,14 +323,14 @@ describe "CollaboratorsHandler", ->
 				{user: @owning_user,    privilegeLevel: "owner"},
 				{user: @readwrite_user, privilegeLevel: "readAndWrite"}
 			]
-			@CollaboratorHandler.getMembersWithPrivilegeLevels = sinon.stub().callsArgWith(1, null, @members)
+			@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels = sinon.stub().callsArgWith(1, null, @members)
 			@ProjectEditorHandler.buildOwnerAndMembersViews = sinon.stub().returns(@views = {
 				owner: @owning_user,
 				ownerFeatures: @owning_user.features,
 				members: [ {_id: @readwrite_user._id, email: @readwrite_user.email} ]
 			})
 			@callback = sinon.stub()
-			@CollaboratorHandler.getAllMembers @project_id, @callback
+			@CollaboratorHandler.getAllInvitedMembers @project_id, @callback
 
 		it 'should not produce an error', ->
 			@callback.callCount.should.equal 1
@@ -341,8 +341,8 @@ describe "CollaboratorsHandler", ->
 			expect(@callback.firstCall.args[1]).to.deep.equal @views.members
 
 		it 'should call getMembersWithPrivileges', ->
-			@CollaboratorHandler.getMembersWithPrivilegeLevels.callCount.should.equal 1
-			@CollaboratorHandler.getMembersWithPrivilegeLevels.firstCall.args[0].should.equal @project_id
+			@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels.callCount.should.equal 1
+			@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels.firstCall.args[0].should.equal @project_id
 
 		it 'should call ProjectEditorHandler.buildOwnerAndMembersViews', ->
 			@ProjectEditorHandler.buildOwnerAndMembersViews.callCount.should.equal 1
@@ -351,14 +351,14 @@ describe "CollaboratorsHandler", ->
 		describe 'when getMembersWithPrivileges produces an error', ->
 
 			beforeEach ->
-				@CollaboratorHandler.getMembersWithPrivilegeLevels = sinon.stub().callsArgWith(1, new Error('woops'))
+				@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels = sinon.stub().callsArgWith(1, new Error('woops'))
 				@ProjectEditorHandler.buildOwnerAndMembersViews = sinon.stub().returns(@views = {
 					owner: @owning_user,
 					ownerFeatures: @owning_user.features,
 					members: [ {_id: @readwrite_user._id, email: @readwrite_user.email} ]
 				})
 				@callback = sinon.stub()
-				@CollaboratorHandler.getAllMembers @project_id, @callback
+				@CollaboratorHandler.getAllInvitedMembers @project_id, @callback
 
 			it 'should produce an error', ->
 				@callback.callCount.should.equal 1
@@ -366,8 +366,8 @@ describe "CollaboratorsHandler", ->
 				expect(@callback.firstCall.args[0]).to.be.instanceof Error
 
 			it 'should call getMembersWithPrivileges', ->
-				@CollaboratorHandler.getMembersWithPrivilegeLevels.callCount.should.equal 1
-				@CollaboratorHandler.getMembersWithPrivilegeLevels.firstCall.args[0].should.equal @project_id
+				@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels.callCount.should.equal 1
+				@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels.firstCall.args[0].should.equal @project_id
 
 			it 'should not call ProjectEditorHandler.buildOwnerAndMembersViews', ->
 				@ProjectEditorHandler.buildOwnerAndMembersViews.callCount.should.equal 0

+ 34 - 34
services/web/test/UnitTests/coffee/Collaborators/CollaboratorsInviteControllerTests.coffee

@@ -317,7 +317,7 @@ describe "CollaboratorsInviteController", ->
 				last_name: "Doe"
 				email: "john@example.com"
 
-			@CollaboratorsHandler.isUserMemberOfProject = sinon.stub().callsArgWith(2, null, false, null)
+			@CollaboratorsHandler.isUserInvitedMemberOfProject = sinon.stub().callsArgWith(2, null, false, null)
 			@CollaboratorsInviteHandler.getInviteByToken = sinon.stub().callsArgWith(2, null, @invite)
 			@ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, @fakeProject)
 			@UserGetter.getUser.callsArgWith(2, null, @owner)
@@ -337,9 +337,9 @@ describe "CollaboratorsInviteController", ->
 			it 'should not call next', ->
 				@next.callCount.should.equal 0
 
-			it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
-				@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+			it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should call getInviteByToken', ->
 				@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -356,7 +356,7 @@ describe "CollaboratorsInviteController", ->
 		describe 'when user is already a member of the project', ->
 
 			beforeEach ->
-				@CollaboratorsHandler.isUserMemberOfProject = sinon.stub().callsArgWith(2, null, true, null)
+				@CollaboratorsHandler.isUserInvitedMemberOfProject = sinon.stub().callsArgWith(2, null, true, null)
 				@CollaboratorsInviteController.viewInvite @req, @res, @next
 
 			it 'should redirect to the project page', ->
@@ -366,9 +366,9 @@ describe "CollaboratorsInviteController", ->
 			it 'should not call next with an error', ->
 				@next.callCount.should.equal 0
 
-			it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
-				@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+			it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should not call getInviteByToken', ->
 				@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 0
@@ -379,19 +379,19 @@ describe "CollaboratorsInviteController", ->
 			it 'should not call ProjectGetter.getProject', ->
 				@ProjectGetter.getProject.callCount.should.equal 0
 
-		describe 'when isUserMemberOfProject produces an error', ->
+		describe 'when isUserInvitedMemberOfProject produces an error', ->
 
 			beforeEach ->
-				@CollaboratorsHandler.isUserMemberOfProject = sinon.stub().callsArgWith(2, new Error('woops'))
+				@CollaboratorsHandler.isUserInvitedMemberOfProject = sinon.stub().callsArgWith(2, new Error('woops'))
 				@CollaboratorsInviteController.viewInvite @req, @res, @next
 
 			it 'should call next with an error', ->
 				@next.callCount.should.equal 1
 				expect(@next.firstCall.args[0]).to.be.instanceof Error
 
-			it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
-				@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+			it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should not call getInviteByToken', ->
 				@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 0
@@ -413,13 +413,13 @@ describe "CollaboratorsInviteController", ->
 				@next.callCount.should.equal 1
 				@next.calledWith(@err).should.equal true
 
-			it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
-				@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+			it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should call getInviteByToken', ->
 				@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should not call User.getUser', ->
 				@UserGetter.getUser.callCount.should.equal 0
@@ -440,13 +440,13 @@ describe "CollaboratorsInviteController", ->
 			it 'should not call next', ->
 				@next.callCount.should.equal 0
 
-			it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
-				@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+			it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should call getInviteByToken', ->
 				@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should not call User.getUser', ->
 				@UserGetter.getUser.callCount.should.equal 0
@@ -464,9 +464,9 @@ describe "CollaboratorsInviteController", ->
 				@next.callCount.should.equal 1
 				expect(@next.firstCall.args[0]).to.be.instanceof Error
 
-			it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
-				@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+			it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should call getInviteByToken', ->
 				@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -491,9 +491,9 @@ describe "CollaboratorsInviteController", ->
 			it 'should not call next', ->
 				@next.callCount.should.equal 0
 
-			it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
-				@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+			it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should call getInviteByToken', ->
 				@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -515,9 +515,9 @@ describe "CollaboratorsInviteController", ->
 				@next.callCount.should.equal 1
 				expect(@next.firstCall.args[0]).to.be.instanceof Error
 
-			it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
-				@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+			it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should call getInviteByToken', ->
 				@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -542,9 +542,9 @@ describe "CollaboratorsInviteController", ->
 			it 'should not call next', ->
 				@next.callCount.should.equal 0
 
-			it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
-				@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
-				@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
+			it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
+				@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
 
 			it 'should call getInviteByToken', ->
 				@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -791,4 +791,4 @@ describe "CollaboratorsInviteController", ->
 			@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, true)
 			@CollaboratorsInviteController._checkRateLimit @sendingUserId, (err, result)=>
 				@RateLimiter.addCount.args[0][0].throttle.should.equal(10)
-				done()
+				done()