From 06966f67db97f0463dfee1fc7da982b95b78d1bd Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Wed, 20 Sep 2017 09:35:19 +0100 Subject: [PATCH] Differentiate project members by source, include token members --- .../Collaborators/CollaboratorsHandler.coffee | 14 ++++++++++++-- .../CollaboratorsHandlerTests.coffee | 18 +++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee b/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee index 8c6209eb3f..e7adb6df3f 100644 --- a/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee +++ b/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee @@ -10,6 +10,9 @@ Errors = require "../Errors/Errors" EmailHelper = require "../Helpers/EmailHelper" ProjectEditorHandler = require "../Project/ProjectEditorHandler" +Sources = + INVITE: 'invite' + TOKEN: 'token' module.exports = CollaboratorsHandler = @@ -18,11 +21,18 @@ module.exports = CollaboratorsHandler = return callback(error) if error? return callback new Errors.NotFoundError("no project found with id #{project_id}") if !project? members = [] + # Project owner members.push { id: project.owner_ref.toString(), privilegeLevel: PrivilegeLevels.OWNER } + # Invited members for member_id in project.readOnly_refs or [] - members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_ONLY } + members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_ONLY, source: Sources.INVITE } for member_id in project.collaberator_refs or [] - members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_AND_WRITE } + members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_AND_WRITE, source: Sources.INVITE } + # Token access + for member_id in project.tokenAccessReadOnly_refs or [] + members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_ONLY, source: Sources.TOKEN } + for member_id in project.tokenAccessReadAndWrite_refs or [] + members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_AND_WRITE, source: Sources.TOKEN } return callback null, members getMemberIds: (project_id, callback = (error, member_ids) ->) -> diff --git a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee index 8f8720aaf2..e5928f44b5 100644 --- a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee @@ -41,10 +41,10 @@ describe "CollaboratorsHandler", -> @callback .calledWith(null, [ { id: "owner-ref", privilegeLevel: "owner" } - { id: "read-only-ref-1", privilegeLevel: "readOnly" } - { id: "read-only-ref-2", privilegeLevel: "readOnly" } - { id: "read-write-ref-1", privilegeLevel: "readAndWrite" } - { id: "read-write-ref-2", privilegeLevel: "readAndWrite" } + { id: "read-only-ref-1", privilegeLevel: "readOnly", source: 'invite'} + { id: "read-only-ref-2", privilegeLevel: "readOnly", source: 'invite'} + { id: "read-write-ref-1", privilegeLevel: "readAndWrite", source: 'invite'} + { id: "read-write-ref-2", privilegeLevel: "readAndWrite", source: 'invite' } ]) .should.equal true @@ -74,11 +74,11 @@ describe "CollaboratorsHandler", -> beforeEach -> @CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub() @CollaboratorHandler.getMemberIdsWithPrivilegeLevels.withArgs(@project_id).yields(null, [ - { id: "read-only-ref-1", privilegeLevel: "readOnly" } - { id: "read-only-ref-2", privilegeLevel: "readOnly" } - { id: "read-write-ref-1", privilegeLevel: "readAndWrite" } - { id: "read-write-ref-2", privilegeLevel: "readAndWrite" } - { id: "doesnt-exist", privilegeLevel: "readAndWrite" } + { id: "read-only-ref-1", privilegeLevel: "readOnly", source: 'invite' } + { id: "read-only-ref-2", privilegeLevel: "readOnly", source: 'invite' } + { id: "read-write-ref-1", privilegeLevel: "readAndWrite", source: 'invite' } + { id: "read-write-ref-2", privilegeLevel: "readAndWrite", source: 'invite' } + { id: "doesnt-exist", privilegeLevel: "readAndWrite", source: 'invite' } ]) @UserGetter.getUserById = sinon.stub() @UserGetter.getUserById.withArgs("read-only-ref-1").yields(null, { _id: "read-only-ref-1" })