wekan/server/publications/rules.js

85 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-04-12 11:44:28 +02:00
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';
2021-04-12 11:44:28 +02:00
Meteor.publish('rules', function(ruleId) {
2018-09-16 01:50:36 +03:00
check(ruleId, String);
if (!this.userId) {
return this.ready();
}
const rule = ReactiveCache.getRule(ruleId);
if (!rule) {
return this.ready();
}
const board = ReactiveCache.getBoard(rule.boardId);
if (!board || !board.isVisibleBy(this.userId)) {
return this.ready();
}
const ret = ReactiveCache.getRules(
{
_id: ruleId,
},
{},
true,
);
return ret;
2018-08-03 19:47:20 +02:00
});
Meteor.publish('allRules', function() {
if (!this.userId || !ReactiveCache.getUser(this.userId).isAdmin) {
return this.ready();
}
const ret = ReactiveCache.getRules({}, {}, true);
return ret;
2018-08-03 19:47:20 +02:00
});
Meteor.publish('allTriggers', function() {
if (!this.userId || !ReactiveCache.getUser(this.userId).isAdmin) {
return this.ready();
}
const ret = ReactiveCache.getTriggers({}, {}, true);
return ret;
2018-08-03 19:47:20 +02:00
});
2018-09-14 16:49:06 +02:00
Meteor.publish('allActions', function() {
if (!this.userId || !ReactiveCache.getUser(this.userId).isAdmin) {
return this.ready();
}
const ret = ReactiveCache.getActions({}, {}, true);
return ret;
2018-09-16 01:50:36 +03:00
});
2021-04-12 11:44:28 +02:00
Meteor.publish('rulesReport', function() {
if (!this.userId || !ReactiveCache.getUser(this.userId).isAdmin) {
return this.ready();
}
const rules = ReactiveCache.getRules({}, {}, true);
2021-04-12 11:44:28 +02:00
const actionIds = [];
const triggerIds = [];
const boardIds = [];
rules.forEach(rule => {
actionIds.push(rule.actionId);
triggerIds.push(rule.triggerId);
boardIds.push(rule.boardId);
});
const ret = [
2021-04-12 11:44:28 +02:00
rules,
ReactiveCache.getActions({ _id: { $in: actionIds } }, {}, true),
ReactiveCache.getTriggers({ _id: { $in: triggerIds } }, {}, true),
ReactiveCache.getBoards({ _id: { $in: boardIds } }, { fields: { title: 1 } }, true),
2021-04-12 11:44:28 +02:00
];
return ret;
2021-04-12 11:44:28 +02:00
});