Files
wekan/server/methods/instanceFeatures.js
T
Lauri Ojansivu 18d57b2b8f Let administrators choose which optional features WeKan offers.
Admin Panel / Settings / Visibility has a new Features group. Each
optional group of board views (Table, Calendar, Time, Overview, Gantt,
Scrum, Flow charts, Map) can be turned off for the whole instance. A
disabled feature is removed from the Board View menu and from Board
Settings / Board View rather than greyed out, and a user who had it open
is moved to the board's default view. Its data and every permission stay
as they are.

Administrators can preview disabled features, and named pilot users see
them too. An opt-in policy keeps features added by later WeKan updates
disabled until an administrator enables them; the features present when
it is turned on stay as they were. Swimlanes and Lists are core and
cannot be disabled. The English texts are pending Transifex.

Thanks to nalilord and xet7 !

Fixes #6736.
2026-10-02 15:26:22 +03:00

58 lines
2.5 KiB
JavaScript

// #6736: Admin Panel / Settings / Visibility / Features. Site admin only.
// The decisions are models/lib/instanceFeatures.js; this stores them and the
// pilot users who preview disabled features (a flag on the user, published
// only to that user, so nobody learns who the pilots are).
import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import Settings from '/models/settings';
const { featureSettingsModifier, parsePilotUsernames } = require('/models/lib/instanceFeatures');
async function requireSiteAdmin() {
const user = await Meteor.userAsync();
if (user?.isAdmin !== true) throw new Meteor.Error('error-notAuthorized');
return user;
}
Meteor.methods({
// The usernames of the current pilot users, for the page's text box.
async getFeaturePilotUsernames() {
await requireSiteAdmin();
const users = await Meteor.users.find({ featurePreview: true },
{ fields: { username: 1 }, sort: { username: 1 }, limit: 500 }).fetchAsync();
return users.map(user => user.username).filter(Boolean);
},
// Saves every feature's decision, the two policies and the pilot users.
// Unknown usernames are returned rather than silently ignored.
async saveInstanceFeatures(input) {
await requireSiteAdmin();
check(input, {
states: Object,
approvalRequired: Boolean,
previewAdmins: Boolean,
pilotUsernames: Match.Optional(String),
});
const { pilotUsernames, ...decisions } = input;
const modifier = featureSettingsModifier(decisions);
if (modifier.error) throw new Meteor.Error('invalid-features', modifier.error);
const setting = await Settings.findOneAsync({});
if (!setting) throw new Meteor.Error('settings-not-found');
await Settings.updateAsync(setting._id, modifier);
let unknownUsernames = [];
if (typeof pilotUsernames === 'string') {
const names = parsePilotUsernames(pilotUsernames);
const pilots = names.length ? await Meteor.users.find({ username: { $in: names } },
{ fields: { _id: 1, username: 1 } }).fetchAsync() : [];
const ids = pilots.map(user => user._id);
unknownUsernames = names.filter(name => !pilots.some(user => user.username === name));
await Meteor.users.updateAsync({ featurePreview: true, _id: { $nin: ids } },
{ $unset: { featurePreview: '' } }, { multi: true });
if (ids.length) {
await Meteor.users.updateAsync({ _id: { $in: ids } }, { $set: { featurePreview: true } }, { multi: true });
}
}
return { saved: true, unknownUsernames };
},
});