Files
wekan/server/methods/instanceFeatures.js
T
Lauri Ojansivu 03975e7d31 Admin Panel / Settings / Visibility / Features: choose which card fields every board shows.
Above the Features Save there is now one tick per field type of Board
Settings / Card - the same icons and names, all ticked by default. An
unticked field, for example Pomodoro, is not offered in any board's Board
Settings / Card and is not shown on any opened card or minicard, whatever
the board chose. Visibility only: no card data and no board setting is
written, so ticking it again shows every board as it was set. There is no
ordering here; the order stays each board's own.

The catalog and the decisions are models/lib/cardFieldVisibility.js. It is
stored as cardFieldStates on the settings document (missing means shown,
so existing installs are unchanged), published with the other Features
settings and saved by the site-admin-only saveInstanceFeatures method,
which refuses unknown field keys. The hiding happens at the client's one
board read (ReactiveCache.getBoard), which returns the board with the
hidden fields' flags reading false - the same object when nothing is
hidden - so every card and minicard template that reads a board flag agrees
without being edited; the per-card List title and the user's Labels text
override check the same mark. The server's reads, publications and the REST
API are unchanged. A whole-column tick in Board Settings / Card leaves the
hidden fields' board values alone.

Thanks to xet7 !
2026-10-08 08:54:04 +03:00

66 lines
3.0 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');
const { cardFieldStatesValue } = require('/models/lib/cardFieldVisibility');
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),
// The card fields every board shows (models/lib/cardFieldVisibility.js).
cardFields: Match.Optional(Object),
});
const { pilotUsernames, cardFields, ...decisions } = input;
const modifier = featureSettingsModifier(decisions);
if (modifier.error) throw new Meteor.Error('invalid-features', modifier.error);
if (cardFields !== undefined) {
const value = cardFieldStatesValue(cardFields);
if (value.error) throw new Meteor.Error('invalid-card-fields', value.error);
modifier.$set.cardFieldStates = value.cardFieldStates;
}
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 };
},
});