Files
wekan/models/lib/instanceFeatures.js
T
Lauri Ojansivu 326d9bbf61 Board View / Version Control, issue files and synced issue details.
Version Control shows the board as a GitHub or Gitea issue tracker in the
board's own theme: cards are issues (open, or closed when archived, in a
Closed or Done list, or closed upstream), the board's labels are labels,
labels with a due date and the importers' milestone: labels are
milestones, comments are the conversation and attachments are the files.
The issue list takes GitHub's search words (is:open, label:, milestone:,
author:, assignee:@me, no:label, sort:). New issue, Close and Reopen write
through the ordinary collections, so the History tab - the board's
history table - shows them and Restore undoes them. Import links open the
GitHub, GitLab, Gitea and Forgejo importers, and each synced list has a
Sync now button.

The GitHub, GitLab, Gitea and Forgejo importers bring each issue's files:
user-attachments and user-images links, GitLab uploads, and Gitea and
Forgejo assets, downloaded through the import's SSRF guard and stored as
card attachments in Admin Panel / Attachments / Default Storage.

List sync has a new option, Comments, labels, state and files, off by
default: comments come from one paged repository-wide list (GitHub,
Gitea) or each issue's notes (GitLab), keyed by the tracker's ids, so a
second run writes only what changed, and nothing written in WeKan is
changed. Gitea issues are fetched without pull requests, and a rate
limited answer is waited out once or ends the run with the time to retry.

A public board's Show on / Default on Public Board settings are for the
public: visitors and non-members get them, read-only, and the board's own
members get the private side, so any view - Version Control, Email, Chat
and the rest - can be the read-only public view.

The card menu has a QR code of the card's link, drawn in the browser by
WeKan's own encoder, which the tests check module for module against
qrcode-svg.

The new strings are translated in every locale.

Thanks to xet7 !

Fixes #2015.
2026-10-14 12:09:34 +03:00

162 lines
7.7 KiB
JavaScript

'use strict';
// #6736: Admin Panel / Settings / Visibility / Features - which optional
// features this WeKan offers, instance-wide.
//
// Pure CommonJS, no Meteor: the Admin Panel page, the server method that saves
// it, the client places that hide a disabled feature, and the tests/*.test.cjs
// guards all load this ONE catalog and these decisions.
//
// What a disabled feature means:
// * it is HIDDEN from the interface - its menu entries are not drawn, not
// greyed out - and a user who had it open is moved to what remains;
// * its data is untouched: enabling it again shows everything as it was;
// * it never changes permissions: availability is not access, so enabling
// a feature grants nobody a board, a card or an edit right.
// Swimlanes and Lists are the core of a board and are never in the catalog.
//
// Stored on the Settings document:
// featureStates: { '<key>': true|false } - explicit decisions
// featureApprovalRequired: Boolean - keep NEW features off until enabled
// featureKnownKeys: [key] - the catalog when the policy was turned
// on, or when the page was last saved
// featurePreviewAdmins: Boolean - site admins see disabled features
// and on a user: featurePreview: true - a pilot user who sees them too.
// Each entry is a group of related views, so an administrator decides about
// "the Scrum views", not about 35 menu lines. `views` are keys of
// models/lib/boardViewSettings.js BOARD_VIEWS; tests/instanceFeatures.test.cjs
// fails when a view is unknown or in two groups.
const FEATURES = [
{ key: 'views-table', labelKey: 'feature-views-table', descKey: 'feature-views-table-desc',
views: ['board-view-table'] },
{ key: 'views-calendar', labelKey: 'feature-views-calendar', descKey: 'feature-views-calendar-desc',
views: ['board-view-cal', 'board-view-calendar-mode', 'board-view-multiboard-cal'] },
{ key: 'views-time', labelKey: 'feature-views-time', descKey: 'feature-views-time-desc',
views: ['board-view-time', 'board-view-timeline'] },
{ key: 'views-overview', labelKey: 'feature-views-overview', descKey: 'feature-views-overview-desc',
views: ['board-view-stats', 'board-view-group-by-assignee', 'board-view-roadmap', 'board-view-dashboard',
'board-view-bigboard'] },
{ key: 'views-gantt', labelKey: 'feature-views-gantt', descKey: 'feature-views-gantt-desc',
views: ['board-view-gantt', 'board-view-gantt-frappe', 'board-view-gantt-dhtmlx'] },
{ key: 'views-scrum', labelKey: 'feature-views-scrum', descKey: 'feature-views-scrum-desc',
views: ['board-view-product-backlog', 'board-view-sprints', 'board-view-sprint-report', 'board-view-velocity'] },
{ key: 'views-flow-charts', labelKey: 'feature-views-flow-charts', descKey: 'feature-views-flow-charts-desc',
views: ['board-view-burndown', 'board-view-burnup', 'board-view-cumulative-flow', 'board-view-control-chart',
'board-view-cycle-time', 'board-view-flow-efficiency', 'board-view-lead-time',
'board-view-throughput-histogram', 'board-view-wip-run', 'board-view-pulse', 'board-view-aging-wip',
'board-view-blocker-analysis', 'board-view-monte-carlo', 'board-view-process-behavior',
'board-view-size-cycle-time'] },
{ key: 'views-map', labelKey: 'feature-views-map', descKey: 'feature-views-map-desc',
views: ['board-view-map'] },
{ key: 'views-email', labelKey: 'feature-views-email', descKey: 'feature-views-email-desc',
views: ['board-view-email'] },
{ key: 'views-chat', labelKey: 'feature-views-chat', descKey: 'feature-views-chat-desc',
views: ['board-view-chat'] },
{ key: 'views-version-control', labelKey: 'feature-views-version-control', descKey: 'feature-views-version-control-desc',
views: ['board-view-version-control'] },
];
const FEATURE_KEYS = FEATURES.map(feature => feature.key);
const FEATURE_OF_VIEW = new Map(FEATURES.flatMap(feature => feature.views.map(view => [view, feature.key])));
function isFeatureKey(key) {
return FEATURE_KEYS.includes(key);
}
function storedStates(setting) {
const states = setting && setting.featureStates;
return states && typeof states === 'object' && !Array.isArray(states) ? states : {};
}
function knownKeys(setting) {
return Array.isArray(setting && setting.featureKnownKeys) ? setting.featureKnownKeys : [];
}
// A feature nobody has decided about yet, that arrived after the approval
// policy was turned on. It waits for an administrator.
function isAwaitingApproval(setting, key) {
if (!isFeatureKey(key)) return false;
return !!(setting && setting.featureApprovalRequired === true) &&
typeof storedStates(setting)[key] !== 'boolean' && !knownKeys(setting).includes(key);
}
// On for everyone. An explicit decision wins; without one a feature is on,
// as it always was, unless it is new and the instance asked to approve first.
function isFeatureEnabled(setting, key) {
if (!isFeatureKey(key)) return true;
const state = storedStates(setting)[key];
if (typeof state === 'boolean') return state;
return !isAwaitingApproval(setting, key);
}
// Whether THIS user sees disabled features: site admins when the preview is
// on, and the pilot users an administrator named.
function canPreviewFeatures(setting, user) {
if (!user) return false;
if (user.featurePreview === true) return true;
return user.isAdmin === true && !!(setting && setting.featurePreviewAdmins === true);
}
function isFeatureAvailable(setting, user, key) {
return isFeatureEnabled(setting, key) || canPreviewFeatures(setting, user);
}
function isBoardViewAvailable(setting, user, view) {
const key = FEATURE_OF_VIEW.get(view);
return !key || isFeatureAvailable(setting, user, key);
}
// The rows of the Admin Panel page.
function featureRows(setting) {
return FEATURES.map(feature => ({
key: feature.key,
labelKey: feature.labelKey,
descKey: feature.descKey,
enabled: isFeatureEnabled(setting, feature.key),
awaitingApproval: isAwaitingApproval(setting, feature.key),
}));
}
// The page's Save, turned into one $set, or { error }. Every catalog feature
// gets an explicit decision, so what the administrator saw is what is stored.
// Turning the approval policy ON records the catalog as it is now: only
// features added by a LATER update wait for approval. Saving with the policy
// on records the current catalog too, because every feature on the page has
// just been decided.
function featureSettingsModifier(input) {
if (!input || typeof input !== 'object' || Array.isArray(input)) return { error: 'invalid' };
const { states, approvalRequired, previewAdmins } = input;
if (!states || typeof states !== 'object' || Array.isArray(states) ||
typeof approvalRequired !== 'boolean' || typeof previewAdmins !== 'boolean') return { error: 'invalid' };
const unknown = Object.keys(states).filter(key => !isFeatureKey(key));
if (unknown.length) return { error: 'unknown-feature', keys: unknown };
const featureStates = {};
for (const key of FEATURE_KEYS) {
if (typeof states[key] !== 'boolean') return { error: 'invalid' };
featureStates[key] = states[key];
}
return { $set: { featureStates, featureApprovalRequired: approvalRequired,
featurePreviewAdmins: previewAdmins, featureKnownKeys: FEATURE_KEYS.slice() } };
}
// "alice, bob\ncarol" -> ['alice', 'bob', 'carol'], unique, bounded.
function parsePilotUsernames(text) {
if (typeof text !== 'string') return [];
return [...new Set(text.split(/[\s,;]+/).map(name => name.trim()).filter(Boolean))].slice(0, 500);
}
module.exports = {
FEATURES,
FEATURE_KEYS,
isFeatureKey,
isAwaitingApproval,
isFeatureEnabled,
canPreviewFeatures,
isFeatureAvailable,
isBoardViewAvailable,
featureRows,
featureSettingsModifier,
parsePilotUsernames,
};