From 789d1d1d1cdfee9ee09565813112c586675ad491 Mon Sep 17 00:00:00 2001 From: Emile NDAGIJIMANA Date: Fri, 23 Jul 2021 10:39:42 +0200 Subject: [PATCH] =?UTF-8?q?=C2=AB=20All=20boards=20page=20=C2=BB=20only=20?= =?UTF-8?q?displays=20tables=20to=20which=20the=20current=20user=20has=20a?= =?UTF-8?q?ccess?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/boards/boardsList.js | 48 ++++++++++++++++++++++---- server/publications/boards.js | 30 ++++++++++++++-- server/publications/users.js | 4 +++ 3 files changed, 73 insertions(+), 9 deletions(-) diff --git a/client/components/boards/boardsList.js b/client/components/boards/boardsList.js index 0e0815b05..fba4820ed 100644 --- a/client/components/boards/boardsList.js +++ b/client/components/boards/boardsList.js @@ -87,16 +87,52 @@ BlazeComponent.extendComponent({ boards() { const query = { - archived: false, - //type: { $in: ['board','template-container'] }, - type: 'board', + //archived: false, + ////type: { $in: ['board','template-container'] }, + //type: 'board', + $and: [ + { archived: false }, + { type: 'board' }, + { $or:[] } + ] }; - if (FlowRouter.getRouteName() === 'home') - query['members.userId'] = Meteor.userId(); + if (FlowRouter.getRouteName() === 'home'){ + query.$and[2].$or.push({'members.userId': Meteor.userId()}); + + const currUser = Users.findOne(Meteor.userId()); + + // const currUser = Users.findOne(Meteor.userId(), { + // fields: { + // orgs: 1, + // teams: 1, + // }, + // }); + + let orgIdsUserBelongs = currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : ''; + if(orgIdsUserBelongs && orgIdsUserBelongs != ''){ + let orgsIds = orgIdsUserBelongs.split(','); + // for(let i = 0; i < orgsIds.length; i++){ + // query.$and[2].$or.push({'orgs.orgId': orgsIds[i]}); + // } + + //query.$and[2].$or.push({'orgs': {$elemMatch : {orgId: orgsIds[0]}}}); + query.$and[2].$or.push({'orgs.orgId': {$in : orgsIds}}); + } + + let teamIdsUserBelongs = currUser.teams !== 'undefined' ? currUser.teamIdsUserBelongs() : ''; + if(teamIdsUserBelongs && teamIdsUserBelongs != ''){ + let teamsIds = teamIdsUserBelongs.split(','); + // for(let i = 0; i < teamsIds.length; i++){ + // query.$or[2].$or.push({'teams.teamId': teamsIds[i]}); + // } + //query.$and[2].$or.push({'teams': { $elemMatch : {teamId: teamsIds[0]}}}); + query.$and[2].$or.push({'teams.teamId': {$in : teamsIds}}); + } + } else query.permission = 'public'; return Boards.find(query, { - sort: { sort: 1 /* boards default sorting */ }, + //sort: { sort: 1 /* boards default sorting */ }, }); }, isStarred() { diff --git a/server/publications/boards.js b/server/publications/boards.js index cfe93c0df..12a30e317 100644 --- a/server/publications/boards.js +++ b/server/publications/boards.js @@ -13,6 +13,17 @@ Meteor.publish('boards', function() { const { starredBoards = [] } = (Users.findOne(userId) || {}).profile || {}; check(starredBoards, [String]); + let currUser = Users.findOne(userId); + let orgIdsUserBelongs = currUser!== 'undefined' && currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : ''; + let teamIdsUserBelongs = currUser!== 'undefined' && currUser.teams !== 'undefined' ? currUser.teamIdsUserBelongs() : ''; + let orgsIds = []; + let teamsIds = []; + if(orgIdsUserBelongs && orgIdsUserBelongs != ''){ + orgsIds = orgIdsUserBelongs.split(','); + } + if(teamIdsUserBelongs && teamIdsUserBelongs != ''){ + teamsIds = teamIdsUserBelongs.split(','); + } return Boards.find( { archived: false, @@ -22,6 +33,8 @@ Meteor.publish('boards', function() { permission: 'public', }, { members: { $elemMatch: { userId, isActive: true } } }, + {'orgs.orgId': {$in : orgsIds}}, + {'teams.teamId': {$in : teamsIds}}, ], }, { @@ -82,11 +95,22 @@ Meteor.publishRelations('board', function(boardId, isArchived) { check(isArchived, Boolean); const thisUserId = this.userId; const $or = [{ permission: 'public' }]; + let currUser = (!Match.test(thisUserId, String) || !thisUserId) ? 'undefined' : Users.findOne(thisUserId); + let orgIdsUserBelongs = currUser!== 'undefined' && currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : ''; + let teamIdsUserBelongs = currUser!== 'undefined' && currUser.teams !== 'undefined' ? currUser.teamIdsUserBelongs() : ''; + let orgsIds = []; + let teamsIds = []; + if(orgIdsUserBelongs && orgIdsUserBelongs != ''){ + orgsIds = orgIdsUserBelongs.split(','); + } + if(teamIdsUserBelongs && teamIdsUserBelongs != ''){ + teamsIds = teamIdsUserBelongs.split(','); + } if (thisUserId) { - $or.push({ - members: { $elemMatch: { userId: thisUserId, isActive: true } }, - }); + $or.push({members: { $elemMatch: { userId: thisUserId, isActive: true } }}); + $or.push({'orgs.orgId': {$in : orgsIds}}); + $or.push({'teams.teamId': {$in : teamsIds}}); } this.cursor( diff --git a/server/publications/users.js b/server/publications/users.js index 152669064..fd6147d13 100644 --- a/server/publications/users.js +++ b/server/publications/users.js @@ -23,6 +23,8 @@ Meteor.publish('user-admin', function() { return Meteor.users.find(this.userId, { fields: { isAdmin: 1, + teams: 1, + orgs: 1, }, }); }); @@ -34,6 +36,8 @@ Meteor.publish('user-authenticationMethod', function(match) { { fields: { authenticationMethod: 1, + teams: 1, + orgs: 1, }, }, );