mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Admin Panel / Settings / Visibility / Rules gets "Boards may show their Rules to members, read-only", off by default (Settings rulesReadOnlyForMembers, site admin only). With it on, a board admin ticks "Show these Rules to board members, read-only" on the board's Rules page (rulesVisibleToMembers). Members of that board then get Rules in Board Settings and see the rules list and each rule's details, with no control that changes a rule; the methods that change rules keep their board-admin checks, so nothing is granted. Without both ticks only board and site admins see the Rules page, which until now drew its list for any member who opened the address. models/lib/rulesReadOnly.js decides 'edit', 'read' or 'none', and client/lib/rulesAccess.js is the one place the Rules page, Board Settings and rule details ask. tests/rulesReadOnly.test.cjs covers both switches, each alone, a non-member, and that a reader's page has no edit control. boardMenuOrder now leaves the reader's alternative branch out of the admin's sequence and pins it alone; instanceFeatures counts the fourth site-admin method; roleHelperRegressions follows the canAdmin check to rulesAccess.js. The new strings are English placeholders until the next translation pass. Thanks to justinr1234 and xet7 ! Fixes #2217.
127 lines
4.4 KiB
JavaScript
127 lines
4.4 KiB
JavaScript
import Boards from '/models/boards';
|
|
import { currentRulesAccess } from '/client/lib/rulesAccess';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import Rules from '/models/rules';
|
|
import { isSubmitKey } from '/models/lib/editorSubmitKey';
|
|
|
|
function boardRuleIds() {
|
|
const boardId = Session.get('currentBoard');
|
|
return ReactiveCache.getRules({ boardId }).map(r => r._id);
|
|
}
|
|
|
|
function getSelected() {
|
|
return Session.get('selectedRuleIds') || [];
|
|
}
|
|
|
|
function setSelected(ids) {
|
|
Session.set('selectedRuleIds', ids);
|
|
}
|
|
|
|
Template.rulesList.onCreated(function () {
|
|
this.autorun(() => {
|
|
const boardId = Session.get('currentBoard');
|
|
if (boardId) this.subscribe('boardRules', boardId);
|
|
});
|
|
this.editingRuleId = new ReactiveVar(null);
|
|
});
|
|
|
|
Template.rulesList.helpers({
|
|
rules() {
|
|
const boardId = Session.get('currentBoard');
|
|
return ReactiveCache.getRules({ boardId });
|
|
},
|
|
canAdmin() {
|
|
// isBoardAdmin is a helper to call: as a bare reference it was always
|
|
// truthy, so every member was shown the rule controls. #2217: one rule
|
|
// for the whole Rules page (client/lib/rulesAccess.js).
|
|
return currentRulesAccess() === 'edit';
|
|
},
|
|
// #2217: the board admin's tick, offered when the Admin Panel allows it.
|
|
rulesForMembersOffered() {
|
|
return !!(ReactiveCache.getCurrentSetting() || {}).rulesReadOnlyForMembers;
|
|
},
|
|
rulesVisibleToMembers() {
|
|
const board = ReactiveCache.getBoard(Session.get('currentBoard'));
|
|
return !!(board && board.rulesVisibleToMembers);
|
|
},
|
|
isSelected() {
|
|
return getSelected().includes(this._id);
|
|
},
|
|
isEditing() {
|
|
return Template.instance().editingRuleId.get() === this._id;
|
|
},
|
|
// #2322: `enabled` defaults to true in the schema (and is absent on any
|
|
// rule document written before this field existed), so only an explicit
|
|
// `false` counts as disabled here - matching the skip check in
|
|
// server/rulesHelper.js's findMatchingRules().
|
|
isEnabled() {
|
|
return this.enabled !== false;
|
|
},
|
|
});
|
|
|
|
Template.rulesList.events({
|
|
'click .js-toggle-rules-visible-to-members'(event) {
|
|
event.preventDefault();
|
|
const board = ReactiveCache.getBoard(Session.get('currentBoard'));
|
|
if (board) Boards.update(board._id, { $set: { rulesVisibleToMembers: !board.rulesVisibleToMembers } });
|
|
},
|
|
'change .js-rule-select'(event) {
|
|
const ruleId = event.currentTarget.getAttribute('data-rule-id');
|
|
const selected = new Set(getSelected());
|
|
if (event.currentTarget.checked) {
|
|
selected.add(ruleId);
|
|
} else {
|
|
selected.delete(ruleId);
|
|
}
|
|
setSelected([...selected]);
|
|
},
|
|
'click .js-rules-select-all'() {
|
|
setSelected(boardRuleIds());
|
|
},
|
|
'click .js-rules-select-none'() {
|
|
setSelected([]);
|
|
},
|
|
'click .js-rules-delete-selected'() {
|
|
getSelected().forEach(ruleId => {
|
|
const rule = ReactiveCache.getRule(ruleId);
|
|
if (rule) {
|
|
// Delete the rule + its trigger + action server-side (see
|
|
// server/rulesButton.js `rules.deleteRule`): three client-side
|
|
// Collection.remove() calls were rejected with 403 "Access denied".
|
|
Meteor.call('rules.deleteRule', rule._id);
|
|
}
|
|
});
|
|
setSelected([]);
|
|
},
|
|
'click .js-rules-export-selected': Popup.open('rulesImportExport'),
|
|
// #2322: flip a rule's enabled/disabled state in place, without touching
|
|
// its trigger/action configuration (server/rulesButton.js rules.setEnabled).
|
|
'click .js-toggle-rule-enabled'(event) {
|
|
const ruleId = event.currentTarget.getAttribute('data-rule-id');
|
|
const rule = ReactiveCache.getRule(ruleId);
|
|
if (!rule) return;
|
|
const nextEnabled = rule.enabled === false;
|
|
Meteor.call('rules.setEnabled', ruleId, nextEnabled);
|
|
},
|
|
// Inline rename of a rule.
|
|
'click .js-edit-rule'(event, tpl) {
|
|
tpl.editingRuleId.set(this._id);
|
|
},
|
|
'keydown .js-edit-rule-input'(event, tpl) {
|
|
if (isSubmitKey(event, { submitOnEnter: !!ReactiveCache.getCurrentUser()?.hasSubmitOnEnter?.() })) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
const title = event.currentTarget.value.trim();
|
|
if (title) Rules.update(this._id, { $set: { title } });
|
|
tpl.editingRuleId.set(null);
|
|
} else if (event.key === 'Escape') {
|
|
tpl.editingRuleId.set(null);
|
|
}
|
|
},
|
|
'blur .js-edit-rule-input'(event, tpl) {
|
|
const title = event.currentTarget.value.trim();
|
|
if (title) Rules.update(this._id, { $set: { title } });
|
|
tpl.editingRuleId.set(null);
|
|
},
|
|
});
|