mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 01:49:41 -05:00
An unticked feature hid its menus and nothing else: the Table, Chat, Email, Version Control and Scrum views' methods and publications still answered, setBoardView still stored a hidden view, and a client could still turn on a list policy, a commitment point, a WIP limit per person or a split list. models/lib/featureServerGates.js lists, for every catalog feature, its server paths, its write gates, or why it is display only. requireFeature / featureAllowed (server/lib/assistGate.js) refuse with feature-disabled and record the attempt in Admin Panel / Problems as Disabled setting; the Scrum methods are wrapped in one place, except the ones the card details, Board Settings and data recovery use too; Boards / Lists deny rules refuse turning a flow policy on; setCardFlow refuses Done here while split lists is off; setBoardView refuses a hidden view. Board Settings / Scrum settings follows the Scrum views tick, as it opens in the Sprints view. tests/featureServerGates.test.cjs fails when a catalog feature is undecided, or when a method or publication of a feature file does not ask the gate. Thanks to xet7 !
87 lines
4.0 KiB
JavaScript
87 lines
4.0 KiB
JavaScript
/* eslint-env mocha */
|
|
// Admin Panel / Settings / Features: with a feature unticked, the server paths
|
|
// of that feature refuse the call (models/lib/featureServerGates.js), and
|
|
// with it ticked they answer as before.
|
|
import assert from 'node:assert/strict';
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { DDP } from 'meteor/ddp';
|
|
import { Random } from 'meteor/random';
|
|
import Settings from '/models/settings';
|
|
|
|
describe('Admin Panel features are refused on the server while off', function () {
|
|
this.timeout(30000);
|
|
let setting;
|
|
let savedStates;
|
|
const userId = Random.id();
|
|
const adminId = Random.id();
|
|
|
|
const call = (uid, name, ...args) => {
|
|
const context = { userId: uid, isSimulation: false, connection: null, setUserId() {}, unblock() {} };
|
|
return DDP._CurrentMethodInvocation.withValue(context, () =>
|
|
Meteor.server.method_handlers[name].apply(context, args));
|
|
};
|
|
const turn = (key, on) => Settings.updateAsync(setting._id, { $set: { [`featureStates.${key}`]: on } });
|
|
|
|
before(async function () {
|
|
setting = await Settings.findOneAsync({});
|
|
if (!setting) this.skip();
|
|
savedStates = setting.featureStates;
|
|
await Meteor.users.rawCollection().insertMany([
|
|
{ _id: userId, username: `gate-${userId}`, profile: {} },
|
|
// A site admin, without the preview: an off feature is off for them too.
|
|
{ _id: adminId, username: `gate-admin-${adminId}`, isAdmin: true, profile: {} },
|
|
]);
|
|
});
|
|
after(async function () {
|
|
if (setting) {
|
|
await Settings.updateAsync(setting._id, savedStates === undefined
|
|
? { $unset: { featureStates: '' } } : { $set: { featureStates: savedStates } });
|
|
}
|
|
await Meteor.users.removeAsync({ _id: { $in: [userId, adminId] } });
|
|
});
|
|
|
|
const refused = async promise => assert.rejects(promise, err => err && err.error === 'feature-disabled');
|
|
const notRefusedForTheFeature = async promise => {
|
|
try { await promise; } catch (err) { assert.notEqual(err && err.error, 'feature-disabled'); }
|
|
};
|
|
|
|
it('refuses the Table view, Chat view and Scrum view methods while their features are off', async function () {
|
|
await turn('views-table', false);
|
|
await turn('views-chat', false);
|
|
await turn('views-scrum', false);
|
|
await refused(call(userId, 'tableViewAddCard', { boardId: 'b', listId: 'l', swimlaneId: 's', title: 'x' }));
|
|
await refused(call(userId, 'chatViewChannels'));
|
|
await refused(call(adminId, 'chatViewChannels'));
|
|
await refused(call(userId, 'scrum.startSprint', 'b', 's', 0));
|
|
});
|
|
|
|
it('keeps the Scrum methods the card details and recovery use (negative)', async function () {
|
|
await turn('views-scrum', false);
|
|
await notRefusedForTheFeature(call(userId, 'scrum.getBoardData', 'no-such-board'));
|
|
});
|
|
|
|
it('refuses choosing a board view whose feature is off, and allows Swimlanes', async function () {
|
|
await turn('views-table', false);
|
|
await refused(call(userId, 'setBoardView', 'board-view-table', null));
|
|
const before = await Meteor.users.findOneAsync(userId);
|
|
assert.notEqual(before.profile && before.profile.boardView, 'board-view-table');
|
|
await notRefusedForTheFeature(call(userId, 'setBoardView', 'board-view-swimlanes', null));
|
|
});
|
|
|
|
it('answers as before while the features are on (negative)', async function () {
|
|
await turn('views-table', true);
|
|
await turn('views-chat', true);
|
|
await turn('views-scrum', true);
|
|
await notRefusedForTheFeature(call(userId, 'tableViewAddCard', { boardId: 'b', listId: 'l', swimlaneId: 's', title: 'x' }));
|
|
await notRefusedForTheFeature(call(userId, 'chatViewChannels'));
|
|
await notRefusedForTheFeature(call(userId, 'scrum.startSprint', 'b', 's', 0));
|
|
await notRefusedForTheFeature(call(userId, 'setBoardView', 'board-view-table', null));
|
|
});
|
|
|
|
it('leaves a logged-out call to the method\'s own login check (negative)', async function () {
|
|
await turn('views-table', false);
|
|
await assert.rejects(call(null, 'tableViewAddCard', { boardId: 'b', listId: 'l', swimlaneId: 's', title: 'x' }),
|
|
err => err && err.error === 'not-authorized');
|
|
});
|
|
});
|