mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
"User with Worker permission can't assignee card if it has been assigned to
someone else before." The card showed the reporter's name for a moment and then
showed the previous assignee again - an optimistic write the server threw away.
The previous assignee was a red herring: a Worker could not assign themselves at
all.
The board schema defines the role as "only allowed to move card, assign himself to
card and comment". Both of those are card UPDATES, and the capability table gives
Worker `write: false` - so the role defined by two specific writes was allowed
neither. The client had already built the UI for it: the assignee popup shows a
Worker exactly one name, their own. The server discarded what they clicked.
Widening `write` to true was never the fix - that hands a Worker every field of
every card, which is the opposite of what the role is. What was missing is the
field-level policy the "Known gaps" section of docs/Features/Members/Roles.md said
this needed, so that is what this is.
models/lib/workerCardWrite.js decides an update by WHAT IT WRITES:
MOVE $set of listId / swimlaneId / sort, plus the dateLastActivity and
modifiedAt written with them
SELF-ASSIGN $addToSet or $pull of `assignees` with EXACTLY the caller's own id
and refuses everything else BY DEFAULT. Not "deny a list of dangerous fields" -
allow only when every operator and every field in the modifier is one of the
above. A modifier it does not recognise ($unset, $rename, $inc, a raw replacement
document, an operator MongoDB adds next year) is not a move and not a
self-assignment, so it is refused. A qualifier on the assignee write ($each, $in)
is refused rather than unpicked: a policy that starts unpicking list shapes is a
policy with a hole in it.
Deliberately not included: boardId, because "move card" here means within the
board and a cross-board move is a different act with its own guard
(GHSA-gm7v-pc38-53jr); `members`, because the role says assignee; and assigning or
unassigning anybody else, because the role says himself.
server/permissions/cards.js reads the modifier now (Meteor passes it to the allow
rule and it was being ignored) and consults the policy only for a member who has
no write access AND is a Worker on that board. Write access is still the first
question, and the vote/poker canaries still fire before either.
`moveCard` becomes its own capability in models/lib/boardRoleCapabilities.js -
true for every role that can write, plus Worker - so the client's canMoveCard()
asks for the same thing the server enforces. That is one answer added rather than
eight changed.
docs/Features/Members/Roles.md gains the column, the paragraph that used to
explain why moving a card could NOT be its own column now explains why it is, and
the Worker entry moves from "Known gaps" to "Fixed". The gaps section is empty and
says so.
tests/workerCardWrite.test.cjs covers both halves of the role and, more
importantly, the refusals: somebody else's name, a move with a passenger field, a
title, a label, members, an $unset, an $inc, a $rename, a whole-document
replacement, $each/$in qualifiers, and junk of every shape - none of which may
become permission. tests/boardRoles.test.cjs gains the column and flips its
gap test: the ⚠ that marked this role had to go with the fix.
Verified by running both suites and the whole node suite (383 suites, 0 failed).
Not verified in a browser: this sandbox has none, so the client half is verified
from the code and the popup template that has always shown a Worker their own name.
Thanks to rptl and xet7 !
Fixes #3189.
120 lines
5.5 KiB
JavaScript
120 lines
5.5 KiB
JavaScript
'use strict';
|
|
|
|
// What each board role may do — the ONE table, in code.
|
|
//
|
|
// It used to be spelled out three times: once in the server allow helpers
|
|
// (server/lib/utils.js), once in the client's canModify* helpers
|
|
// (client/lib/utils.js), and once in prose in the docs. The three had drifted, and
|
|
// each place they disagreed was a role that did not do what its name says. So the
|
|
// matrix lives here, everything else reads it, and there is nowhere for a fourth
|
|
// opinion to appear.
|
|
//
|
|
// Read by: server/lib/utils.js (the authority), client/lib/utils.js (what the UI
|
|
// offers), Admin Panel / People / Roles (the Roles Status table), and
|
|
// docs/Features/Members/Roles.md through tests/boardRoles.test.cjs.
|
|
//
|
|
// Pure: no Meteor, no DOM, no database.
|
|
|
|
// The roles, in the order they are shown to a person: most power first.
|
|
const BOARD_ROLES = [
|
|
'board-admin',
|
|
'normal',
|
|
'normal-assigned-only',
|
|
'no-comments',
|
|
'comment-only',
|
|
'comment-assigned-only',
|
|
'worker',
|
|
'read-only',
|
|
'read-assigned-only',
|
|
];
|
|
|
|
// The member flag that names each role. 'normal' is the absence of all of them.
|
|
const ROLE_FLAGS = {
|
|
'board-admin': 'isAdmin',
|
|
'normal-assigned-only': 'isNormalAssignedOnly',
|
|
'no-comments': 'isNoComments',
|
|
'comment-only': 'isCommentOnly',
|
|
'comment-assigned-only': 'isCommentAssignedOnly',
|
|
'worker': 'isWorker',
|
|
'read-only': 'isReadOnly',
|
|
'read-assigned-only': 'isReadAssignedOnly',
|
|
};
|
|
|
|
// The capabilities, one column each.
|
|
//
|
|
// seesAllCards false = only the cards the member is assigned to. Enforced by
|
|
// the card publications, not by an allow rule.
|
|
// comment add a card comment or a comment reaction.
|
|
// write create and edit cards, lists, swimlanes, checklists — and MOVE
|
|
// a card, because a move is a card update and goes through the
|
|
// same rule.
|
|
// manageBoard the board's settings, its members and their roles.
|
|
// moveCard move a card between lists/swimlanes, and put your OWN name in
|
|
// or out of its assignees. It is a subset of `write` for every
|
|
// role that has `write` - and it is the whole of what a Worker
|
|
// may do to a card (#3189, models/lib/workerCardWrite.js).
|
|
const CAPABILITIES = ['seesAllCards', 'comment', 'write', 'manageBoard', 'moveCard'];
|
|
|
|
const ROLE_CAPABILITIES = {
|
|
'board-admin': { seesAllCards: true, comment: true, write: true, manageBoard: true, moveCard: true },
|
|
'normal': { seesAllCards: true, comment: true, write: true, manageBoard: false, moveCard: true },
|
|
'normal-assigned-only': { seesAllCards: false, comment: true, write: true, manageBoard: false, moveCard: true },
|
|
// "No comments" is the one that blocks COMMENTING. It used to block writing as
|
|
// well, which made it a second read-only role under a name that says otherwise.
|
|
'no-comments': { seesAllCards: true, comment: false, write: true, manageBoard: false, moveCard: true },
|
|
'comment-only': { seesAllCards: true, comment: true, write: false, manageBoard: false, moveCard: false },
|
|
// ...and this is "comment only" plus the assigned-cards restriction. It used to
|
|
// have full write access, because nothing outside the card publications read
|
|
// its flag — so it was really "normal, assigned only" under another name.
|
|
'comment-assigned-only': { seesAllCards: false, comment: true, write: false, manageBoard: false, moveCard: false },
|
|
// A Worker is meant to "move card, assign himself to card and comment" (the
|
|
// board schema's own words). `write` stays false - the role is not "can edit
|
|
// cards" - and the two writes it IS for are now their own capability, enforced
|
|
// field by field on the server by models/lib/workerCardWrite.js (#3189). That
|
|
// is the field-level policy this line used to say was missing.
|
|
'worker': { seesAllCards: true, comment: true, write: false, manageBoard: false, moveCard: true },
|
|
'read-only': { seesAllCards: true, comment: false, write: false, manageBoard: false, moveCard: false },
|
|
'read-assigned-only': { seesAllCards: false, comment: false, write: false, manageBoard: false, moveCard: false },
|
|
};
|
|
|
|
// The role of ONE member document. The order matters and matches
|
|
// Board.memberRole(): a member carries a single flag in practice
|
|
// (setMemberPermission writes all of them at once), but the REST API can set
|
|
// several, and then the strongest wins — `isAdmin` above all, which is why every
|
|
// other flag on an admin is ignored here just as it is in Board.hasCommentOnly()
|
|
// and the rest of the has*() helpers.
|
|
function memberRoleOf(member) {
|
|
if (!member || member.isActive !== true) return null;
|
|
if (member.isAdmin) return 'board-admin';
|
|
for (const role of BOARD_ROLES) {
|
|
const flag = ROLE_FLAGS[role];
|
|
if (flag && flag !== 'isAdmin' && member[flag]) return role;
|
|
}
|
|
return 'normal';
|
|
}
|
|
|
|
// May a member with this role do this? An unknown role or capability is `false`:
|
|
// a permission question with no answer is a no.
|
|
function roleCan(role, capability) {
|
|
const caps = ROLE_CAPABILITIES[role];
|
|
if (!caps) return false;
|
|
return caps[capability] === true;
|
|
}
|
|
|
|
// May THIS member of THIS board do it? `members` is board.members.
|
|
function memberCan(members, userId, capability) {
|
|
if (!userId || !Array.isArray(members)) return false;
|
|
const member = members.find(m => m && m.userId === userId && m.isActive === true);
|
|
return roleCan(memberRoleOf(member), capability);
|
|
}
|
|
|
|
module.exports = {
|
|
BOARD_ROLES,
|
|
ROLE_FLAGS,
|
|
CAPABILITIES,
|
|
ROLE_CAPABILITIES,
|
|
memberRoleOf,
|
|
roleCan,
|
|
memberCan,
|
|
};
|