From dcf601fe8023a6d62e2e1da69fe9c9ba39ba10ac Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 12 Oct 2017 15:47:29 +0100 Subject: [PATCH] Only show token-based projects if accessLevel is set to token-based --- .../Collaborators/CollaboratorsHandler.coffee | 18 +++++++++++------- .../Features/Project/ProjectGetter.coffee | 1 - .../CollaboratorsHandlerTests.coffee | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee b/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee index 9e44214990..2749fab545 100644 --- a/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee +++ b/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee @@ -133,15 +133,19 @@ module.exports = CollaboratorsHandler = getProjectsUserIsMemberOf: (user_id, fields, callback = (error, {readAndWrite:[],readOnly:[],tokenReadAndWrite:[],tokenReadOnly:[]}) ->) -> async.mapLimit( [ - 'collaberator_refs', - 'readOnly_refs', - 'tokenAccessReadAndWrite_refs', - 'tokenAccessReadOnly_refs' + {collaberator_refs: user_id}, + {readOnly_refs: user_id}, + { + tokenAccessReadAndWrite_refs: user_id, + publicAccesLevel: PublicAccessLevels.TOKEN_BASED + }, + { + tokenAccessReadOnly_refs: user_id, + publicAccesLevel: PublicAccessLevels.TOKEN_BASED + } ] , 2 - , (key, cb) -> - query = {} - query[key] = user_id + , (query, cb) -> Project.find query, fields, cb , (error, results) -> return callback(error) if error? diff --git a/services/web/app/coffee/Features/Project/ProjectGetter.coffee b/services/web/app/coffee/Features/Project/ProjectGetter.coffee index 3c00d09ae6..bcc597a763 100644 --- a/services/web/app/coffee/Features/Project/ProjectGetter.coffee +++ b/services/web/app/coffee/Features/Project/ProjectGetter.coffee @@ -56,7 +56,6 @@ module.exports = ProjectGetter = return callback(error) if error? CollaboratorsHandler.getProjectsUserIsMemberOf user_id, fields, (error, projects) -> return callback(error) if error? - # TODO: Add token projects too callback null, ownedProjects, projects.readAndWrite, projects.readOnly, projects.tokenReadAndWrite, projects.tokenReadOnly diff --git a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee index fd0bb157a7..5c68fd9ef6 100644 --- a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee @@ -196,8 +196,8 @@ describe "CollaboratorsHandler", -> @Project.find = sinon.stub() @Project.find.withArgs({collaberator_refs:@user_id}, @fields).yields(null, ["mock-read-write-project-1", "mock-read-write-project-2"]) @Project.find.withArgs({readOnly_refs:@user_id}, @fields).yields(null, ["mock-read-only-project-1", "mock-read-only-project-2"]) - @Project.find.withArgs({tokenAccessReadAndWrite_refs:@user_id}, @fields).yields(null, ["mock-token-read-write-project-1", "mock-token-read-write-project-2"]) - @Project.find.withArgs({tokenAccessReadOnly_refs:@user_id}, @fields).yields(null, ["mock-token-read-only-project-1", "mock-token-read-only-project-2"]) + @Project.find.withArgs({tokenAccessReadAndWrite_refs:@user_id, publicAccesLevel: 'tokenBased'}, @fields).yields(null, ["mock-token-read-write-project-1", "mock-token-read-write-project-2"]) + @Project.find.withArgs({tokenAccessReadOnly_refs:@user_id, publicAccesLevel: 'tokenBased'}, @fields).yields(null, ["mock-token-read-only-project-1", "mock-token-read-only-project-2"]) @CollaboratorHandler.getProjectsUserIsMemberOf @user_id, @fields, @callback it "should call the callback with the projects", ->