mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -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 !
63 lines
2.9 KiB
JavaScript
63 lines
2.9 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { check, Match } from 'meteor/check';
|
|
import Boards from '/models/boards';
|
|
import Cards from '/models/cards';
|
|
import Lists from '/models/lists';
|
|
import { canEditCardOrLinkedCard } from '/server/lib/linkedCardPermission';
|
|
|
|
const { flowModifier, expediteOverLimit } = require('/models/lib/cardFlow');
|
|
const { isAssignedOnlyMember } = require('/models/lib/boardCardScope');
|
|
|
|
// The card's Kanban and Scrum flow fields (models/lib/cardFlow.js): blocked
|
|
// and why, class of service, MoSCoW, WSJF. The same permission as every other
|
|
// card edit (canEditCardOrLinkedCard, on the source of a linked card); an
|
|
// assigned-only member changes only a card assigned to them; Expedite keeps
|
|
// its WIP limit of one open card per board. Who blocked a card and when is
|
|
// the server's, never the client's.
|
|
export async function setCardFlowFor(userId, cardId, patch) {
|
|
check(cardId, String);
|
|
check(patch, Match.ObjectIncluding({}));
|
|
if (!userId) throw new Meteor.Error('not-authorized');
|
|
let card = await Cards.findOneAsync(cardId);
|
|
if (!card) throw new Meteor.Error('not-found');
|
|
if (card.type === 'cardType-linkedCard' && card.linkedId) {
|
|
card = await Cards.findOneAsync(card.linkedId);
|
|
if (!card) throw new Meteor.Error('not-found');
|
|
}
|
|
const board = await Boards.findOneAsync(card.boardId);
|
|
if (!board || !(await canEditCardOrLinkedCard(userId, card, board))) throw new Meteor.Error('not-authorized');
|
|
if (isAssignedOnlyMember(board, userId) && !(card.assignees || []).includes(userId)
|
|
&& !(card.members || []).includes(userId)) {
|
|
throw new Meteor.Error('not-authorized');
|
|
}
|
|
let modifier;
|
|
try {
|
|
modifier = flowModifier(patch, { userId, now: new Date(), listId: card.listId });
|
|
} catch (e) {
|
|
throw new Meteor.Error(e.code || 'invalid-flow-patch');
|
|
}
|
|
// Done here only in a list split into Doing and Done, and only while
|
|
// Admin Panel / Settings / Features offers split lists: the minicard draws no
|
|
// Done here toggle otherwise (models/lib/featureServerGates.js).
|
|
if (patch.splitDone === true) {
|
|
await require('/server/lib/assistGate').requireFeature(userId, 'split-lists', 'ddp:setCardFlow-splitDone');
|
|
const list = await Lists.findOneAsync(card.listId, { fields: { split: 1 } });
|
|
if (!list || list.split !== true) throw new Meteor.Error('not-a-split-list');
|
|
}
|
|
if (patch.classOfService === 'expedite' && card.flow?.classOfService !== 'expedite') {
|
|
const others = await Cards.find(
|
|
{ boardId: card.boardId, archived: { $ne: true }, 'flow.classOfService': 'expedite' },
|
|
{ fields: { _id: 1, archived: 1, dueComplete: 1, flow: 1 } },
|
|
).fetchAsync();
|
|
if (expediteOverLimit(card._id, others)) throw new Meteor.Error('expedite-limit');
|
|
}
|
|
await Cards.updateAsync({ _id: card._id }, modifier);
|
|
return true;
|
|
}
|
|
|
|
Meteor.methods({
|
|
async setCardFlow(cardId, patch) {
|
|
return await setCardFlowFor(this.userId, cardId, patch);
|
|
},
|
|
});
|