Files
wekan/client/components/rules/ruleDetails.js
T
Lauri Ojansivu f4a3690256 Rules can be shown to board members, read-only, when the Admin Panel allows it.
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.
2026-10-14 14:23:31 +03:00

70 lines
2.5 KiB
JavaScript

import { currentRulesAccess } from '/client/lib/rulesAccess';
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
import { localizeStoredRuleDescription } from '/models/lib/ruleDescriptionLocalization';
function localizedDescription(description) {
const sources = TAPi18n.getDefaultTranslations('r-');
const translations = Object.entries(sources).map(([key, source]) => ({
source,
translated: TAPi18n.__(key),
}));
return localizeStoredRuleDescription(description, translations);
}
function upperFirst(value) {
return value ? value.charAt(0).toUpperCase() + value.slice(1) : '';
}
Template.ruleDetails.onCreated(function () {
this.subscribe('allRules');
this.subscribe('allTriggers');
this.subscribe('allActions');
this.subscribe('boards');
});
// #4294 / #2953: the rule's further triggers and actions, in order.
function extraParts(ruleIdVar, kind) {
const rule = ReactiveCache.getRule(ruleIdVar.get());
if (!rule) return [];
const ids = (kind === 'trigger' ? rule.extraTriggerIds : rule.extraActionIds) || [];
return ids.map(id => {
const doc = kind === 'trigger' ? ReactiveCache.getTrigger(id) : ReactiveCache.getAction(id);
return { ruleId: rule._id, kind, id, text: doc ? upperFirst(localizedDescription(doc.description())) : id };
});
}
Template.ruleDetails.helpers({
// #2217: a member who only reads gets no add or remove buttons.
canEditRules() { return currentRulesAccess() === 'edit'; },
currentRuleId() {
return Template.currentData().ruleId.get();
},
ruleDescription() {
const rule = ReactiveCache.getRule(Template.currentData().ruleId.get());
return (rule && rule.description) || '';
},
extraTriggers() {
return extraParts(Template.currentData().ruleId, 'trigger');
},
extraActions() {
return extraParts(Template.currentData().ruleId, 'action');
},
trigger() {
const ruleId = Template.currentData().ruleId;
const rule = ReactiveCache.getRule(ruleId.get());
if (!rule) return '';
const trigger = ReactiveCache.getTrigger(rule.triggerId);
if (!trigger) return '';
return upperFirst(localizedDescription(trigger.description()));
},
action() {
const ruleId = Template.currentData().ruleId;
const rule = ReactiveCache.getRule(ruleId.get());
if (!rule) return '';
const action = ReactiveCache.getAction(rule.actionId);
if (!action) return '';
return upperFirst(localizedDescription(action.description()));
},
});