Files
wekan/server/models/collectionBootstrap.js
T
Lauri Ojansivu 7595727917 Boards every signed-in user may edit, per-list permissions, board keys and shared labels.
A board can let every signed-in user edit it, when Admin Panel / Settings /
Visibility allows it: a non-member then comments, edits and moves cards like
a Normal member, and their first edit makes them one. Board-wide settings
stay members-only.

Lists can allow or refuse editing and commenting per role (list menu, board
admins): built-in roles, custom roles and, on an open board, everyone signed
in. The server applies it to card, checklist, attachment and comment writes
and to moves into the list; the REST API honours a list's refusal on every
per-list card route. A direct client write of the setting is refused and
shown in Admin Panel / Problems.

Every board has a key, unique in the instance, suggested from its title and
set for existing boards at startup; card numbers show as KEY-7 and searching
for KEY-7 finds the card.

Shared labels in Admin Panel / Labels, for every board or an organization's
or team's boards; a board uses them beside its own, and a rename or colour
change reaches every board that uses it.

New strings translated in all languages. Low confidence: chr, tlh, wal, ay,
ace, nah, gn, iu, zgh, rup, wo, se, ff, tig, vo, bm, kl, bua, nap, mai, to,
ks, qu, bo, fj, haw, om, ss, ts, ve-PP, lld, scn.

Thanks to Meeques, justinr1234, tiFabGrinch, ejlkemper and xet7 !

Fixes #4575,
Fixes #4527,
Fixes #2449,
Fixes #2450,
Fixes #2761,
Fixes #4698.
2026-10-14 09:28:45 +03:00

169 lines
6.1 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 },
);
// The two ways the app actually READS reactions - the card publication by
// `cardId: { $in: [...all the board's cards] }`, the board publication by
// `boardId` - had no index: a reported MongoDB log (.tools/crash) had 3,397
// full collection scans of this one collection, up to 1.6 s each on slow
// storage, the bulk of that server's "Slow query" lines.
await ensureIndex(CardCommentReactions, { cardId: 1 });
await ensureIndex(CardCommentReactions, { boardId: 1 });
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 } },
);
// #4575: off by default - no board can let every signed-in user edit it
// until a site admin allows that.
await TableVisibilityModeSettings.upsertAsync(
{ _id: 'tableVisibilityMode-allowInstanceEditing' },
{ $setOnInsert: { booleanValue: false, sort: 2 } },
);
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 });
});