mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
Boards Report was empty while the Cards report beside it listed cards from thousands of boards. It published userBoardIds(this.userId) - the boards the ADMIN is personally a member of - and on an instance whose admin is not a board member that is nothing at all. Until the pagination fix the pane hid this: it rendered every board in minimongo, which the All Boards page had already put there. The Files report was scoped the same way, to the cards the admin can access. Both now cover the whole instance, like Cards, Broken cards, Rules, Impersonation and Recovery already did. The membership selector was what kept those two publications honest, so both gained an isAdmin guard at the top - boardsReport asked only for a logged-in user before - and both count methods count the same set they page. Files and Rules also name their page now, like the other reports: opening one card puts its attachments in minimongo and opening a rules editor puts that board's rules there, and neither belongs in a report page. The Files page is sorted by name - paging with no sort is paging over natural order, where a document can appear on two pages or on none - and that sort has an index now. Thanks to xet7 !
142 lines
4.7 KiB
JavaScript
142 lines
4.7 KiB
JavaScript
import Boards from '/models/boards';
|
|
import Actions from '/models/actions';
|
|
import Triggers from '/models/triggers';
|
|
import Rules from '/models/rules';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { publishReportPage } from '/models/lib/reportPageIndex';
|
|
|
|
Meteor.publish('rules', async function(ruleId) {
|
|
check(ruleId, String);
|
|
|
|
if (!this.userId) {
|
|
return this.ready();
|
|
}
|
|
|
|
const rule = await ReactiveCache.getRule(ruleId);
|
|
if (!rule) {
|
|
return this.ready();
|
|
}
|
|
|
|
const board = await ReactiveCache.getBoard(rule.boardId);
|
|
if (!board || !board.isVisibleBy({ _id: this.userId })) {
|
|
return this.ready();
|
|
}
|
|
|
|
const ret = await ReactiveCache.getRules(
|
|
{
|
|
_id: ruleId,
|
|
},
|
|
{},
|
|
true,
|
|
);
|
|
return ret;
|
|
});
|
|
|
|
// Board-scoped publication of a board's rules together with their triggers and
|
|
// actions, for anyone who can see the board (not just global admins). This backs
|
|
// the fullscreen Rules page, the workflow view, the board/card buttons and the
|
|
// rules-list editor.
|
|
Meteor.publish('boardRules', async function(boardId) {
|
|
check(boardId, String);
|
|
if (!this.userId) {
|
|
return this.ready();
|
|
}
|
|
const board = await ReactiveCache.getBoard(boardId);
|
|
if (!board || !board.isVisibleBy({ _id: this.userId })) {
|
|
return this.ready();
|
|
}
|
|
return [
|
|
Rules.find({ boardId }),
|
|
Triggers.find({ boardId }),
|
|
Actions.find({ boardId }),
|
|
];
|
|
});
|
|
|
|
Meteor.publish('allRules', async function() {
|
|
if (!this.userId || !(await ReactiveCache.getUser(this.userId)).isAdmin) {
|
|
return this.ready();
|
|
}
|
|
|
|
const ret = await ReactiveCache.getRules({}, {}, true);
|
|
return ret;
|
|
});
|
|
|
|
Meteor.publish('allTriggers', async function() {
|
|
if (!this.userId || !(await ReactiveCache.getUser(this.userId)).isAdmin) {
|
|
return this.ready();
|
|
}
|
|
|
|
const ret = await ReactiveCache.getTriggers({}, {}, true);
|
|
return ret;
|
|
});
|
|
|
|
Meteor.publish('allActions', async function() {
|
|
if (!this.userId || !(await ReactiveCache.getUser(this.userId)).isAdmin) {
|
|
return this.ready();
|
|
}
|
|
|
|
const ret = await ReactiveCache.getActions({}, {}, true);
|
|
return ret;
|
|
});
|
|
|
|
Meteor.publish('rulesReport', async function(searchTerm = '', limit, skip = 0) {
|
|
check(searchTerm, Match.OneOf(String, null, undefined));
|
|
check(limit, Number);
|
|
check(skip, Match.OneOf(Number, null, undefined));
|
|
if (!this.userId || !(await ReactiveCache.getUser(this.userId)).isAdmin) {
|
|
return this.ready();
|
|
}
|
|
|
|
const query = {};
|
|
if (searchTerm) {
|
|
query.title = new RegExp(searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
|
|
}
|
|
|
|
// Publish the page MANUALLY (fetch + this.added + this.ready). Returning a sorted+
|
|
// limited cursor makes Meteor set up a LIMITED live observe, which hangs on
|
|
// FerretDB's OpLog for this query, so the subscription never becomes ready and the
|
|
// report is stuck on the loading spinner forever (same as attachmentsList). This
|
|
// admin report re-subscribes on every page/search change, so it needs no live cursor.
|
|
const rules = await ReactiveCache.getRules(
|
|
query,
|
|
{ sort: { boardId: 1 }, limit, skip: skip || 0 },
|
|
false,
|
|
);
|
|
const actionIds = [];
|
|
const triggerIds = [];
|
|
const boardIds = [];
|
|
rules.forEach(rule => {
|
|
actionIds.push(rule.actionId);
|
|
triggerIds.push(rule.triggerId);
|
|
boardIds.push(rule.boardId);
|
|
});
|
|
|
|
const actions = await ReactiveCache.getActions({ _id: { $in: actionIds } }, {}, false);
|
|
const triggers = await ReactiveCache.getTriggers({ _id: { $in: triggerIds } }, {}, false);
|
|
const boards = await ReactiveCache.getBoards({ _id: { $in: boardIds } }, { fields: { title: 1 } }, false);
|
|
|
|
for (const doc of rules) { const { _id, ...fields } = doc; this.added('rules', _id, fields); }
|
|
for (const doc of actions) { const { _id, ...fields } = doc; this.added('actions', _id, fields); }
|
|
for (const doc of triggers) { const { _id, ...fields } = doc; this.added('triggers', _id, fields); }
|
|
for (const doc of boards) { const { _id, ...fields } = doc; this.added('boards', _id, fields); }
|
|
// WHICH rules this page is: a board's own rules are in minimongo whenever its
|
|
// rules editor has been opened.
|
|
publishReportPage(this, 'report-rules', rules);
|
|
this.ready();
|
|
});
|
|
|
|
Meteor.methods({
|
|
async getRulesReportCount(searchTerm = '') {
|
|
check(searchTerm, Match.OneOf(String, null, undefined));
|
|
if (!this.userId || !(await ReactiveCache.getUser(this.userId)).isAdmin) {
|
|
throw new Meteor.Error('not-authorized');
|
|
}
|
|
const query = {};
|
|
if (searchTerm) {
|
|
query.title = new RegExp(searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
|
|
}
|
|
const cursor = await ReactiveCache.getRules(query, {}, true);
|
|
return typeof cursor.countAsync === 'function' ? await cursor.countAsync() : cursor.count();
|
|
},
|
|
});
|