Add a getInvitedMemberIds function

Limited to only members who were invited to the project, not users
who have access via a token.
This commit is contained in:
Shane Kilkelly 2017-09-20 09:36:56 +01:00
parent fc202439ab
commit cf54989e6a
2 changed files with 19 additions and 1 deletions

View file

@ -40,6 +40,11 @@ module.exports = CollaboratorsHandler =
return callback(error) if error? return callback(error) if error?
return callback null, members.map (m) -> m.id return callback null, members.map (m) -> m.id
getInvitedMemberIds: (project_id, callback = (error, member_ids) ->) ->
CollaboratorsHandler.getMemberIdsWithPrivilegeLevels project_id, (error, members) ->
return callback(error) if error?
return callback null, members.filter((m) -> m.source == Sources.INVITE).map((m) -> m.id)
USER_PROJECTION: { USER_PROJECTION: {
_id: 1, _id: 1,
email: 1, email: 1,

View file

@ -62,7 +62,7 @@ describe "CollaboratorsHandler", ->
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub() @CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub()
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels @CollaboratorHandler.getMemberIdsWithPrivilegeLevels
.withArgs(@project_id) .withArgs(@project_id)
.yields(null, [{id: "member-id-1"}, {id: "member-id-2"}]) .yields(null, [{id: "member-id-1", source: 'invite'}, {id: "member-id-2", source: 'token'}])
@CollaboratorHandler.getMemberIds @project_id, @callback @CollaboratorHandler.getMemberIds @project_id, @callback
it "should return the ids", -> it "should return the ids", ->
@ -70,6 +70,19 @@ describe "CollaboratorsHandler", ->
.calledWith(null, ["member-id-1", "member-id-2"]) .calledWith(null, ["member-id-1", "member-id-2"])
.should.equal true .should.equal true
describe "getInvitedMemberIds", ->
beforeEach ->
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub()
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels
.withArgs(@project_id)
.yields(null, [{id: "member-id-1", source: 'invite'}, {id: "member-id-2", source: 'token'}])
@CollaboratorHandler.getInvitedMemberIds @project_id, @callback
it "should return the invited ids", ->
@callback
.calledWith(null, ["member-id-1"])
.should.equal true
describe "getMembersWithPrivilegeLevels", -> describe "getMembersWithPrivilegeLevels", ->
beforeEach -> beforeEach ->
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub() @CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub()