Files
wekan/server/models/collectionBootstrap.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

156 lines
5.3 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import AccessibilitySettings from '/models/accessibilitySettings';
import AccountSettings from '/models/accountSettings';
import Announcements from '/models/announcements';
import CardCommentReactions from '/models/cardCommentReactions';
import InvitationCodes from '/models/invitationCodes';
import LockoutSettings from '/models/lockoutSettings';
import OrgUser from '/models/orgUser';
import PositionHistory from '/models/positionHistory';
import Presences from '/models/presences';
import Rules from '/models/rules';
import TableVisibilityModeSettings from '/models/tableVisibilityModeSettings';
import InviteToBoardRolesSettings, {
INVITE_TO_BOARD_ROLES_ID,
INVITE_TO_BOARD_ROLES_DEFAULT,
} from '/models/inviteToBoardRolesSettings';
import Triggers from '/models/triggers';
import UnsavedEditCollection from '/models/unsavedEdits';
import { ensureIndex } from '/server/lib/mongoStartup';
Meteor.startup(async () => {
await ensureIndex(AccessibilitySettings, { modifiedAt: -1 });
if (!(await AccessibilitySettings.findOneAsync({}))) {
await AccessibilitySettings.insertAsync({ enabled: false, sort: 0 });
}
await ensureIndex(AccountSettings, { modifiedAt: -1 });
await AccountSettings.upsertAsync(
{ _id: 'accounts-allowEmailChange' },
{ $setOnInsert: { booleanValue: false, sort: 0 } },
);
await AccountSettings.upsertAsync(
{ _id: 'accounts-allowUserNameChange' },
{ $setOnInsert: { booleanValue: false, sort: 1 } },
);
await AccountSettings.upsertAsync(
{ _id: 'accounts-allowUserDelete' },
{ $setOnInsert: { booleanValue: false, sort: 0 } },
);
await ensureIndex(Announcements, { modifiedAt: -1 });
if (!(await Announcements.findOneAsync({}))) {
await Announcements.insertAsync({ enabled: false, sort: 0 });
}
await ensureIndex(
CardCommentReactions,
{ cardCommentId: 1 },
{ unique: true },
);
await ensureIndex(InvitationCodes, { modifiedAt: -1 });
await ensureIndex(LockoutSettings, { modifiedAt: -1 });
await LockoutSettings.upsertAsync(
{ _id: 'known-failuresBeforeLockout' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_FAILURES_BEFORE
? parseInt(process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_FAILURES_BEFORE, 10) : 3,
category: 'known',
sort: 0,
},
},
);
await LockoutSettings.upsertAsync(
{ _id: 'known-lockoutPeriod' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_PERIOD
? parseInt(process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_PERIOD, 10) : 60,
category: 'known',
sort: 1,
},
},
);
await LockoutSettings.upsertAsync(
{ _id: 'known-failureWindow' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_FAILURE_WINDOW
? parseInt(process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_FAILURE_WINDOW, 10) : 15,
category: 'known',
sort: 2,
},
},
);
const typoVar = process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURES_BERORE;
const correctVar = process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURES_BEFORE;
await LockoutSettings.upsertAsync(
{ _id: 'unknown-failuresBeforeLockout' },
{
$setOnInsert: {
value: (correctVar || typoVar) ? parseInt(correctVar || typoVar, 10) : 3,
category: 'unknown',
sort: 0,
},
},
);
await LockoutSettings.upsertAsync(
{ _id: 'unknown-lockoutPeriod' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_LOCKOUT_PERIOD
? parseInt(process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_LOCKOUT_PERIOD, 10) : 60,
category: 'unknown',
sort: 1,
},
},
);
await LockoutSettings.upsertAsync(
{ _id: 'unknown-failureWindow' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURE_WINDOW
? parseInt(process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURE_WINDOW, 10) : 15,
category: 'unknown',
sort: 2,
},
},
);
await ensureIndex(OrgUser, { orgId: -1 });
await ensureIndex(OrgUser, { orgId: -1, userId: -1 });
await ensureIndex(Presences, { serverId: -1 });
await ensureIndex(PositionHistory, { boardId: 1, entityType: 1, entityId: 1 });
await ensureIndex(PositionHistory, { boardId: 1, entityType: 1 });
await ensureIndex(PositionHistory, { createdAt: -1 });
await ensureIndex(Rules, { modifiedAt: -1 });
await ensureIndex(TableVisibilityModeSettings, { modifiedAt: -1 });
await TableVisibilityModeSettings.upsertAsync(
{ _id: 'tableVisibilityMode-allowPrivateOnly' },
{ $setOnInsert: { booleanValue: false, sort: 0 } },
);
// #4475: off by default, so board creation stays unrestricted unless a
// site admin explicitly turns it on.
await TableVisibilityModeSettings.upsertAsync(
{ _id: 'tableVisibilityMode-boardCreationAdminOnly' },
{ $setOnInsert: { booleanValue: false, sort: 1 } },
);
await ensureIndex(InviteToBoardRolesSettings, { modifiedAt: -1 });
await InviteToBoardRolesSettings.upsertAsync(
{ _id: INVITE_TO_BOARD_ROLES_ID },
{ $setOnInsert: { allowedRoles: INVITE_TO_BOARD_ROLES_DEFAULT, sort: 0 } },
);
await ensureIndex(Triggers, { modifiedAt: -1 });
await ensureIndex(UnsavedEditCollection, { modifiedAt: -1 });
await ensureIndex(UnsavedEditCollection, { userId: 1 });
});