Merge pull request #3912 from Emile840/master

Organizations and teams are taken into account when displaying board in « All boards page »
This commit is contained in:
Lauri Ojansivu 2021-07-24 21:15:24 +03:00 committed by GitHub
commit 508915462d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 9 deletions

View file

@ -87,16 +87,52 @@ BlazeComponent.extendComponent({
boards() { boards() {
const query = { const query = {
archived: false, //archived: false,
//type: { $in: ['board','template-container'] }, ////type: { $in: ['board','template-container'] },
type: 'board', //type: 'board',
$and: [
{ archived: false },
{ type: 'board' },
{ $or:[] }
]
}; };
if (FlowRouter.getRouteName() === 'home') if (FlowRouter.getRouteName() === 'home'){
query['members.userId'] = Meteor.userId(); 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'; else query.permission = 'public';
return Boards.find(query, { return Boards.find(query, {
sort: { sort: 1 /* boards default sorting */ }, //sort: { sort: 1 /* boards default sorting */ },
}); });
}, },
isStarred() { isStarred() {

View file

@ -13,6 +13,17 @@ Meteor.publish('boards', function() {
const { starredBoards = [] } = (Users.findOne(userId) || {}).profile || {}; const { starredBoards = [] } = (Users.findOne(userId) || {}).profile || {};
check(starredBoards, [String]); 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( return Boards.find(
{ {
archived: false, archived: false,
@ -22,6 +33,8 @@ Meteor.publish('boards', function() {
permission: 'public', permission: 'public',
}, },
{ members: { $elemMatch: { userId, isActive: true } } }, { 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); check(isArchived, Boolean);
const thisUserId = this.userId; const thisUserId = this.userId;
const $or = [{ permission: 'public' }]; 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) { if (thisUserId) {
$or.push({ $or.push({members: { $elemMatch: { userId: thisUserId, isActive: true } }});
members: { $elemMatch: { userId: thisUserId, isActive: true } }, $or.push({'orgs.orgId': {$in : orgsIds}});
}); $or.push({'teams.teamId': {$in : teamsIds}});
} }
this.cursor( this.cursor(

View file

@ -23,6 +23,8 @@ Meteor.publish('user-admin', function() {
return Meteor.users.find(this.userId, { return Meteor.users.find(this.userId, {
fields: { fields: {
isAdmin: 1, isAdmin: 1,
teams: 1,
orgs: 1,
}, },
}); });
}); });
@ -34,6 +36,8 @@ Meteor.publish('user-authenticationMethod', function(match) {
{ {
fields: { fields: {
authenticationMethod: 1, authenticationMethod: 1,
teams: 1,
orgs: 1,
}, },
}, },
); );