Merge branch 'master' into search-debug

This commit is contained in:
John Supplee 2021-12-21 02:42:54 +02:00
commit 6ef612d04e
11 changed files with 323 additions and 124 deletions

View file

@ -5,6 +5,7 @@ import {
TYPE_TEMPLATE_BOARD,
TYPE_TEMPLATE_CONTAINER,
} from '/config/const';
import Users from "./users";
const escapeForRegex = require('escape-string-regexp');
Boards = new Mongo.Collection('boards');
@ -1479,7 +1480,17 @@ Boards.userSearch = (
return Boards.find(selector, projection);
};
Boards.userBoards = (userId, archived = false, selector = {}) => {
Boards.userBoards = (
userId,
archived = false,
selector = {},
projection = {},
) => {
const user = Users.findOne(userId);
if (!user) {
return [];
}
if (typeof archived === 'boolean') {
selector.archived = archived;
}
@ -1487,15 +1498,20 @@ Boards.userBoards = (userId, archived = false, selector = {}) => {
selector.type = 'board';
}
selector.$or = [{ permission: 'public' }];
if (userId) {
selector.$or.push({ members: { $elemMatch: { userId, isActive: true } } });
}
return Boards.find(selector);
selector.$or = [
{ permission: 'public' },
{ members: { $elemMatch: { userId, isActive: true } } },
{ 'orgs.orgId': { $in: user.orgIds() } },
{ 'teams.teamId': { $in : user.teamIds() } },
];
return Boards.find(selector, projection);
};
Boards.userBoardIds = (userId, archived = false, selector = {}) => {
return Boards.userBoards(userId, archived, selector).map(board => {
return Boards.userBoards(userId, archived, selector, {
fields: { _id: 1 },
}).map(board => {
return board._id;
});
};

View file

@ -519,6 +519,18 @@ Users.helpers({
}
return '';
},
teamIds() {
if (this.teams) {
return this.teams.map(team => { return team.teamId });
}
return [];
},
orgIds() {
if (this.orgs) {
return this.orgs.map(org => { return org.orgId });
}
return [];
},
orgsUserBelongs() {
if (this.orgs) {
return this.orgs.map(function(org){return org.orgDisplayName}).sort().join(',');
@ -544,32 +556,16 @@ Users.helpers({
return '';
},
boards() {
return Boards.find(
{
'members.userId': this._id,
},
{
sort: {
sort: 1 /* boards default sorting */,
},
},
);
return Boards.userBoards(this._id, null, {}, { sort: { sort: 1 } })
},
starredBoards() {
const { starredBoards = [] } = this.profile || {};
return Boards.find(
{
archived: false,
_id: {
$in: starredBoards,
},
},
{
sort: {
sort: 1 /* boards default sorting */,
},
},
return Boards.userBoards(
this._id,
false,
{ _id: { $in: starredBoards } },
{ sort: { sort: 1 } }
);
},
@ -580,18 +576,11 @@ Users.helpers({
invitedBoards() {
const { invitedBoards = [] } = this.profile || {};
return Boards.find(
{
archived: false,
_id: {
$in: invitedBoards,
},
},
{
sort: {
sort: 1 /* boards default sorting */,
},
},
return Boards.userBoards(
this._id,
false,
{ _id: { $in: invitedBoards } },
{ sort: { sort: 1 } }
);
},