mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Deleting a rule ran three separate client-side Collection.remove() calls (Rules + Triggers + Actions). Each is gated by a per-collection allow() rule that resolves the board from that document own boardId via Boards.findOneAsync(doc.boardId). When a trigger/action document has no resolvable boardId (legacy rules created before boardId was denormalised, or docs not published to the client), the board resolves to null and allowIsBoardAdmin returns false, so Meteor rejects the mutation with 403 "Access denied" and the delete fails even for a legitimate board admin. Route rule deletion through a new server Meteor method rules.deleteRule, which authorizes ONCE (active board admin or site admin) and removes the rule, its trigger and its action server-side (bypassing the brittle client allow/deny). The permission decision is extracted into the Meteor-free helper models/lib/ruleDeletePermission.js and covered by tests/ruleDeletePermission.test.cjs. No permission is loosened: only board admins and site admins may delete, matching the board-admin gate used to create a rule.
149 lines
4.3 KiB
JavaScript
149 lines
4.3 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
|
import { Utils } from '/client/lib/utils';
|
|
|
|
Template.rulesMain.onCreated(function () {
|
|
this.rulesCurrentTab = new ReactiveVar('rulesList');
|
|
this.ruleName = new ReactiveVar('');
|
|
this.triggerVar = new ReactiveVar();
|
|
this.ruleId = new ReactiveVar();
|
|
|
|
// The Rules page is now a standalone board-scoped route, so subscribe to the
|
|
// board data (lists, swimlanes, labels, members) the trigger/action forms need,
|
|
// in addition to the rules themselves.
|
|
this.autorun(() => {
|
|
const boardId = Session.get('currentBoard');
|
|
if (boardId) {
|
|
this.subscribe('board', boardId, false);
|
|
this.subscribe('boardRules', boardId);
|
|
}
|
|
});
|
|
});
|
|
|
|
Template.rulesMain.helpers({
|
|
rulesCurrentTab() {
|
|
return Template.instance().rulesCurrentTab;
|
|
},
|
|
ruleName() {
|
|
return Template.instance().ruleName;
|
|
},
|
|
triggerVar() {
|
|
return Template.instance().triggerVar;
|
|
},
|
|
ruleId() {
|
|
return Template.instance().ruleId;
|
|
},
|
|
currentBoard() {
|
|
return Utils.getCurrentBoard();
|
|
},
|
|
isWorkflowView() {
|
|
return Session.get('rulesViewMode') === 'workflow';
|
|
},
|
|
});
|
|
|
|
Template.rulesHeaderBar.helpers({
|
|
currentBoard() {
|
|
return Utils.getCurrentBoard();
|
|
},
|
|
isWorkflowView() {
|
|
return Session.get('rulesViewMode') === 'workflow';
|
|
},
|
|
});
|
|
|
|
Template.rulesHeaderBar.events({
|
|
'click .js-rules-back-to-board'(event) {
|
|
event.preventDefault();
|
|
const currentBoard = Utils.getCurrentBoard();
|
|
if (currentBoard) {
|
|
FlowRouter.go('board', {
|
|
id: currentBoard._id,
|
|
slug: currentBoard.slug,
|
|
});
|
|
}
|
|
},
|
|
'click .js-rules-toggle-view'(event) {
|
|
event.preventDefault();
|
|
const mode = Session.get('rulesViewMode') === 'workflow' ? 'list' : 'workflow';
|
|
Session.set('rulesViewMode', mode);
|
|
},
|
|
'click .js-rules-import-export': Popup.open('rulesImportExport'),
|
|
});
|
|
|
|
function sanitizeObject(obj) {
|
|
Object.keys(obj).forEach(key => {
|
|
if (obj[key] === '' || obj[key] === undefined) {
|
|
obj[key] = '*';
|
|
}
|
|
});
|
|
}
|
|
|
|
Template.rulesMain.events({
|
|
'click .js-delete-rule'() {
|
|
const rule = Template.currentData();
|
|
// Delete the rule + its trigger + action in one server call. Doing this
|
|
// client-side as three separate Collection.remove() calls failed with 403
|
|
// "Access denied" whenever a trigger/action document's boardId did not
|
|
// resolve to a board in the allow() rule; the method authorizes once and
|
|
// removes all three server-side.
|
|
Meteor.call('rules.deleteRule', rule._id);
|
|
},
|
|
'click .js-goto-trigger'(event, tpl) {
|
|
event.preventDefault();
|
|
const ruleTitle = tpl.find('#ruleTitle').value;
|
|
if (ruleTitle !== undefined && ruleTitle !== '') {
|
|
tpl.find('#ruleTitle').value = '';
|
|
tpl.ruleName.set(ruleTitle);
|
|
tpl.rulesCurrentTab.set('trigger');
|
|
}
|
|
},
|
|
'click .js-goto-action'(event, tpl) {
|
|
event.preventDefault();
|
|
// Add user to the trigger
|
|
const username = $(event.currentTarget.offsetParent)
|
|
.find('.user-name')
|
|
.val();
|
|
let trigger = tpl.triggerVar.get();
|
|
trigger.userId = '*';
|
|
if (username !== undefined) {
|
|
const userFound = ReactiveCache.getUser({ username });
|
|
if (userFound !== undefined) {
|
|
trigger.userId = userFound._id;
|
|
tpl.triggerVar.set(trigger);
|
|
}
|
|
}
|
|
// Sanitize trigger
|
|
trigger = tpl.triggerVar.get();
|
|
sanitizeObject(trigger);
|
|
tpl.triggerVar.set(trigger);
|
|
tpl.rulesCurrentTab.set('action');
|
|
},
|
|
'click .js-show-user-field'(event) {
|
|
event.preventDefault();
|
|
$(event.currentTarget.offsetParent)
|
|
.find('.user-details')
|
|
.removeClass('hide-element');
|
|
},
|
|
'click .js-goto-rules'(event, tpl) {
|
|
event.preventDefault();
|
|
tpl.rulesCurrentTab.set('rulesList');
|
|
},
|
|
'click .js-goback'(event, tpl) {
|
|
event.preventDefault();
|
|
if (
|
|
tpl.rulesCurrentTab.get() === 'trigger' ||
|
|
tpl.rulesCurrentTab.get() === 'ruleDetails'
|
|
) {
|
|
tpl.rulesCurrentTab.set('rulesList');
|
|
}
|
|
if (tpl.rulesCurrentTab.get() === 'action') {
|
|
tpl.rulesCurrentTab.set('trigger');
|
|
}
|
|
},
|
|
'click .js-goto-details'(event, tpl) {
|
|
event.preventDefault();
|
|
const rule = Template.currentData();
|
|
tpl.ruleId.set(rule._id);
|
|
tpl.rulesCurrentTab.set('ruleDetails');
|
|
},
|
|
});
|