wekan/server/publications/rules.js
Harry Adel 71eb01e233 Update ReactiveCache call sites to use async/await for Meteor 3.0
Part 3 of ReactiveCache async migration:
- Add await before all ReactiveCache.getX() calls
- Make functions containing ReactiveCache calls async
- Convert forEach/map/filter loops with async callbacks to for...of
- Update model helpers, Meteor methods, JsonRoutes handlers
- Update collection hooks (.before/.after insert/update/remove)
- Update .allow() callbacks to async

Files updated across models/ and server/ directories:
- Model files: cards, boards, lists, swimlanes, activities, users,
  checklists, checklistItems, customFields, attachments, integrations,
  cardComments, settings files, creators, exporters, and more
- Server files: publications, methods, notifications, routes, migrations
2026-02-01 00:54:38 +02:00

84 lines
2.1 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';
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(this.userId)) {
return this.ready();
}
const ret = await ReactiveCache.getRules(
{
_id: ruleId,
},
{},
true,
);
return ret;
});
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() {
if (!this.userId || !(await ReactiveCache.getUser(this.userId)).isAdmin) {
return this.ready();
}
const rules = await ReactiveCache.getRules({}, {}, true);
const actionIds = [];
const triggerIds = [];
const boardIds = [];
rules.forEach(rule => {
actionIds.push(rule.actionId);
triggerIds.push(rule.triggerId);
boardIds.push(rule.boardId);
});
const ret = [
rules,
await ReactiveCache.getActions({ _id: { $in: actionIds } }, {}, true),
await ReactiveCache.getTriggers({ _id: { $in: triggerIds } }, {}, true),
await ReactiveCache.getBoards({ _id: { $in: boardIds } }, { fields: { title: 1 } }, true),
];
return ret;
});