Files
wekan/models/lib/generateDefaultRuleTitle.js
T
Lauri Ojansivu 52972b3e4c Add Admin Panel setting to restrict board creation to admins only.
Admin Panel -> Settings -> Visibility gets a new checkbox beside "Public
boards": "Only admins can create boards"
(tableVisibilityMode-boardCreationAdminOnly, off by default). It follows
the exact TableVisibilityModeSettings pattern its sibling
tableVisibilityMode-allowPrivateOnly already uses: a collection doc seeded
in server/models/collectionBootstrap.js, a jade checkbox and reactive
helper in settingBody.jade/js, and a write in the section's own Save
handler.

The real enforcement is server-side: createBoardWithInitialSwimlanes
(server/models/boards.js) now rejects the call with a not-authorized error
when the setting is on and the caller is not isAdmin === true, before the
board is ever inserted. The client mirrors this only as a convenience - a
new client/lib/boardCreationAllowed.js helper hides the top-bar "+" (header
header.js/.jade) and the All Boards "Add board" tile (boardsList.js) for a
restricted non-admin, but nothing depends on that for security.

A full per-user allow/deny override was left out of this pass: it would
need is own schema field, a People/Admin Panel UI to flip it per account,
and server enforcement layered under the global toggle, which is a larger
change than this issue's "let an admin forbid board creation instance-wide"
core request. The global toggle covers that request cleanly on its own.

Added imports/i18n/data/en.i18n.json's board-creation-admin-only string and
a direct translation (no external translation API) in all other locale
files, in en.i18n.json's key order. tests/boardCreationAdminOnly.test.cjs
pins the default-off setting, the checkbox/handler wiring, the server-side
admin check (and that it runs before the insert), the shared client helper,
the i18n key placement, and - as a negative test - that no OTHER
Boards.insertAsync call site was silently added outside the two already
known and deliberately ungated ones (the per-user Templates container and
createBoardFromCard).

Thanks to belf88 and xet7 !

Closes #4475,
2026-09-10 19:45:52 +03:00

31 lines
1.1 KiB
JavaScript

// Pure, unit-testable helper: compose a sensible default title for a rule
// from its trigger and action human-readable descriptions (the same
// description strings already shown in the "View rule" details page — see
// Triggers.description()/Actions.description() in models/triggers.js and
// models/actions.js). No DOM, no Mongo, no Meteor globals — safe to call
// from a schema autoValue (client and server) or straight from a test.
//
// #4294: rules had no default title, and leaving the title field empty
// produced a silent no-op instead of a usable rule.
function lowerFirst(value) {
return value ? value.charAt(0).toLowerCase() + value.slice(1) : value;
}
function generateDefaultRuleTitle(triggerDesc, actionDesc) {
const trigger = (triggerDesc || '').trim();
const action = (actionDesc || '').trim();
if (trigger && action) {
return `When ${lowerFirst(trigger)}, then ${lowerFirst(action)}`;
}
if (trigger) {
return `When ${lowerFirst(trigger)}`;
}
if (action) {
return `Then ${lowerFirst(action)}`;
}
return 'Rule';
}
module.exports = { generateDefaultRuleTitle };
module.exports.default = generateDefaultRuleTitle;