Bug fix for #3864 searching archived cards and add new operators for organizations and teams

This commit is contained in:
John Supplee 2021-12-22 00:33:13 +02:00
parent 6ef612d04e
commit aa0dee1fba
8 changed files with 89 additions and 6 deletions

View file

@ -12,9 +12,11 @@ import {
OPERATOR_LIST, OPERATOR_LIST,
OPERATOR_MEMBER, OPERATOR_MEMBER,
OPERATOR_MODIFIED_AT, OPERATOR_MODIFIED_AT,
OPERATOR_ORG,
OPERATOR_SORT, OPERATOR_SORT,
OPERATOR_STATUS, OPERATOR_STATUS,
OPERATOR_SWIMLANE, OPERATOR_SWIMLANE,
OPERATOR_TEAM,
OPERATOR_UNKNOWN, OPERATOR_UNKNOWN,
OPERATOR_USER, OPERATOR_USER,
ORDER_ASCENDING, ORDER_ASCENDING,
@ -161,6 +163,8 @@ export class QueryErrors {
[OPERATOR_ASSIGNEE, 'user-username-not-found'], [OPERATOR_ASSIGNEE, 'user-username-not-found'],
[OPERATOR_MEMBER, 'user-username-not-found'], [OPERATOR_MEMBER, 'user-username-not-found'],
[OPERATOR_CREATOR, 'user-username-not-found'], [OPERATOR_CREATOR, 'user-username-not-found'],
[OPERATOR_ORG, 'org-name-not-found'],
[OPERATOR_TEAM, 'team-name-not-found'],
]; ];
constructor() { constructor() {
@ -313,6 +317,8 @@ export class Query {
'operator-sort': OPERATOR_SORT, 'operator-sort': OPERATOR_SORT,
'operator-limit': OPERATOR_LIMIT, 'operator-limit': OPERATOR_LIMIT,
'operator-debug': OPERATOR_DEBUG, 'operator-debug': OPERATOR_DEBUG,
'operator-org': OPERATOR_ORG,
'operator-team': OPERATOR_TEAM,
}; };
const predicates = { const predicates = {

View file

@ -12,9 +12,11 @@ export const OPERATOR_LIMIT = 'limit';
export const OPERATOR_LIST = 'list'; export const OPERATOR_LIST = 'list';
export const OPERATOR_MEMBER = 'members'; export const OPERATOR_MEMBER = 'members';
export const OPERATOR_MODIFIED_AT = 'modifiedAt'; export const OPERATOR_MODIFIED_AT = 'modifiedAt';
export const OPERATOR_ORG = 'org';
export const OPERATOR_SORT = 'sort'; export const OPERATOR_SORT = 'sort';
export const OPERATOR_STATUS = 'status'; export const OPERATOR_STATUS = 'status';
export const OPERATOR_SWIMLANE = 'swimlane'; export const OPERATOR_SWIMLANE = 'swimlane';
export const OPERATOR_TEAM = 'team';
export const OPERATOR_UNKNOWN = 'unknown'; export const OPERATOR_UNKNOWN = 'unknown';
export const OPERATOR_USER = 'user'; export const OPERATOR_USER = 'user';
export const ORDER_ASCENDING = 'asc'; export const ORDER_ASCENDING = 'asc';

View file

@ -943,6 +943,8 @@
"label-color-not-found": "Label color %s not found.", "label-color-not-found": "Label color %s not found.",
"user-username-not-found": "Username '%s' not found.", "user-username-not-found": "Username '%s' not found.",
"comment-not-found": "Card with comment containing text '%s' not found.", "comment-not-found": "Card with comment containing text '%s' not found.",
"org-name-not-found": "Organization '%s' not found.",
"team-name-not-found": "Team '%s' not found.",
"globalSearch-title": "Search All Boards", "globalSearch-title": "Search All Boards",
"no-cards-found": "No Cards Found", "no-cards-found": "No Cards Found",
"one-card-found": "One Card Found", "one-card-found": "One Card Found",
@ -972,6 +974,8 @@
"operator-has": "has", "operator-has": "has",
"operator-limit": "limit", "operator-limit": "limit",
"operator-debug": "debug", "operator-debug": "debug",
"operator-org": "org",
"operator-team": "team",
"predicate-archived": "archived", "predicate-archived": "archived",
"predicate-open": "open", "predicate-open": "open",
"predicate-ended": "ended", "predicate-ended": "ended",

View file

@ -1501,8 +1501,8 @@ Boards.userBoards = (
selector.$or = [ selector.$or = [
{ permission: 'public' }, { permission: 'public' },
{ members: { $elemMatch: { userId, isActive: true } } }, { members: { $elemMatch: { userId, isActive: true } } },
{ 'orgs.orgId': { $in: user.orgIds() } }, { orgs: { $elemMatch: { orgId: { $in: user.orgIds() }, isActive: true } } },
{ 'teams.teamId': { $in : user.teamIds() } }, { teams: { $elemMatch: { teamId: { $in: user.teamIds() }, isActive: true } } },
]; ];
return Boards.find(selector, projection); return Boards.find(selector, projection);

View file

@ -345,6 +345,17 @@ Lists.mutations({
}, },
}); });
Lists.userArchivedLists = userId => {
return Lists.find({
boardId: { $in: Boards.userBoardIds(userId, null) },
archived: true,
})
};
Lists.userArchivedListIds = () => {
return Lists.userArchivedLists().map(list => { return list._id; });
};
Lists.archivedLists = () => { Lists.archivedLists = () => {
return Lists.find({ archived: true }); return Lists.find({ archived: true });
}; };

View file

@ -306,6 +306,17 @@ Swimlanes.mutations({
}, },
}); });
Swimlanes.userArchivedSwimlanes = userId => {
return Swimlanes.find({
boardId: { $in: Boards.userBoardIds(userId, null) },
archived: true,
})
};
Swimlanes.userArchivedSwimlaneIds = () => {
return Swimlanes.userArchivedSwimlanes().map(swim => { return swim._id; });
};
Swimlanes.archivedSwimlanes = () => { Swimlanes.archivedSwimlanes = () => {
return Swimlanes.find({ archived: true }); return Swimlanes.find({ archived: true });
}; };

View file

@ -521,12 +521,14 @@ Users.helpers({
}, },
teamIds() { teamIds() {
if (this.teams) { if (this.teams) {
// TODO: Should the Team collection be queried to determine if the team isActive?
return this.teams.map(team => { return team.teamId }); return this.teams.map(team => { return team.teamId });
} }
return []; return [];
}, },
orgIds() { orgIds() {
if (this.orgs) { if (this.orgs) {
// TODO: Should the Org collection be queried to determine if the organization isActive?
return this.orgs.map(org => { return org.orgId }); return this.orgs.map(org => { return org.orgId });
} }
return []; return [];

View file

@ -24,10 +24,10 @@ import {
OPERATOR_LIMIT, OPERATOR_LIMIT,
OPERATOR_LIST, OPERATOR_LIST,
OPERATOR_MEMBER, OPERATOR_MEMBER,
OPERATOR_MODIFIED_AT, OPERATOR_MODIFIED_AT, OPERATOR_ORG,
OPERATOR_SORT, OPERATOR_SORT,
OPERATOR_STATUS, OPERATOR_STATUS,
OPERATOR_SWIMLANE, OPERATOR_SWIMLANE, OPERATOR_TEAM,
OPERATOR_USER, OPERATOR_USER,
ORDER_ASCENDING, ORDER_ASCENDING,
PREDICATE_ALL, PREDICATE_ALL,
@ -49,6 +49,8 @@ import {
} from '/config/search-const'; } from '/config/search-const';
import { QueryErrors, QueryParams, Query } from '/config/query-classes'; import { QueryErrors, QueryParams, Query } from '/config/query-classes';
import { CARD_TYPES } from '../../config/const'; import { CARD_TYPES } from '../../config/const';
import Org from "../../models/org";
import Team from "../../models/team";
const escapeForRegex = require('escape-string-regexp'); const escapeForRegex = require('escape-string-regexp');
@ -151,6 +153,51 @@ function buildSelector(queryParams) {
} }
}); });
} }
if (queryParams.hasOperator(OPERATOR_ORG)) {
const orgs = [];
queryParams.getPredicates(OPERATOR_ORG).forEach(name => {
const org = Org.findOne({
$or: [
{ orgDisplayName: name },
{ orgShortName: name }
]
});
if (org) {
orgs.push(org._id);
} else {
errors.addNotFound(OPERATOR_ORG, name);
}
});
if (orgs.length) {
boardsSelector.orgs = {
$elemMatch: { orgId: { $in: orgs }, isActive: true }
};
}
}
if (queryParams.hasOperator(OPERATOR_TEAM)) {
const teams = [];
queryParams.getPredicates(OPERATOR_TEAM).forEach(name => {
const team = Team.findOne({
$or: [
{ teamDisplayName: name },
{ teamShortName: name }
]
});
if (team) {
teams.push(team._id);
} else {
errors.addNotFound(OPERATOR_TEAM, name);
}
});
if (teams.length) {
boardsSelector.teams = {
$elemMatch: { teamId: { $in: teams }, isActive: true }
};
}
}
selector = { selector = {
type: 'cardType-card', type: 'cardType-card',
// boardId: { $in: Boards.userBoardIds(userId) }, // boardId: { $in: Boards.userBoardIds(userId) },
@ -169,8 +216,8 @@ function buildSelector(queryParams) {
$in: Boards.userBoardIds(userId, archived, boardsSelector), $in: Boards.userBoardIds(userId, archived, boardsSelector),
}, },
}, },
{ swimlaneId: { $in: Swimlanes.archivedSwimlaneIds() } }, { swimlaneId: { $in: Swimlanes.userArchivedSwimlaneIds(userId) } },
{ listId: { $in: Lists.archivedListIds() } }, { listId: { $in: Lists.userArchivedListIds(userId) } },
{ archived: true }, { archived: true },
], ],
}); });