mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Extract the pure, security- and correctness-critical logic of the recent features into Meteor-free models/lib/* modules (so production and tests share one implementation) and add plain-Node tests with positive AND negative cases, wired into test:unit:node: - models/lib/mongoSelectorSafety.js hasWhere() — the windowed card publication refuses a client selector carrying $where (server-side JS). Tests: safe selectors pass; $where at top level / in $and / deep in arrays / in $elemMatch is rejected. (was inline in server/publications/cardsWindow.js) - models/lib/cardsLoading.js resolveCardsLoadingMode / parseCardsLoadingEnv / windowCountId — CARDS_LOADING maps to 'lazy' only for exactly "lazy" (garbage never enables the experimental mode); a falsy swimlane id collapses to one count-doc id (listBody uses undefined, listHeader uses ''). (used by server/cards-loading.js, server/models/settings.js, client/lib/lazyCards.js) - models/lib/base64Chunk.js encodeAligned/encodeFinal — streaming an attachment into the JSON export as base64 in any chunk sizes reconstructs exactly the whole-file base64; aligned pieces never carry padding. (used by Exporter.buildStream) - models/lib/backupPaths.js filesRootFrom/scheduleText — WRITABLE_PATH -> files root (no double /files suffix, Windows-safe) and the synced-cron schedule text (daily/weekly/monthly + defaults, unknown frequency falls back to daily). (used by server/methods/backup.js) 41 new assertions across 4 files, all passing; whole test:unit:node suite green.
32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
// Pure, Meteor-free helpers for the CARDS_LOADING / lazy card-loading feature.
|
|
// Unit-tested in tests/cardsLoading.test.cjs. Used by server/cards-loading.js,
|
|
// server/models/settings.js (env seeding) and client/lib/lazyCards.js.
|
|
|
|
// Effective card-loading mode from any input (env var, setting): 'lazy' only for
|
|
// exactly "lazy" (case-insensitive), otherwise 'all'. Never throws.
|
|
function resolveCardsLoadingMode(value) {
|
|
return String(value == null ? '' : value).trim().toLowerCase() === 'lazy'
|
|
? 'lazy'
|
|
: 'all';
|
|
}
|
|
|
|
// Parse the CARDS_LOADING env var for the "env is authoritative only when
|
|
// explicitly set" case: returns 'all' or 'lazy' when set to one of those,
|
|
// otherwise undefined (leave the stored setting alone).
|
|
function parseCardsLoadingEnv(value) {
|
|
const v = String(value == null ? '' : value).trim().toLowerCase();
|
|
return v === 'all' || v === 'lazy' ? v : undefined;
|
|
}
|
|
|
|
// Stable id for one (list, swimlane) window's reactive count doc. A falsy
|
|
// swimlaneId (undefined, null, '') MUST collapse to the same id, because the
|
|
// list body subscribes with `undefined` (list view) while the list header reads
|
|
// with '' — both must reference the same count.
|
|
function windowCountId(listId, swimlaneId) {
|
|
return `${listId}::${swimlaneId || ''}`;
|
|
}
|
|
|
|
module.exports = { resolveCardsLoadingMode, parseCardsLoadingEnv, windowCountId };
|