mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
#3022 (decided 2026-10-14): a site admin builds named roles in Admin Panel / People / Roles from the capability matrix - sees all cards, comments, edits, moves cards, invites - and a board admin gives one to a member in the same popup as the built-in roles. Board admin stays built-in. Every permission check asks boardRoleCapabilities, which answers a custom role from the role; the member's built-in flags carry the strongest built-in role that grants nothing more (fallbackRoleFor, checked for every combination), so code reading a flag never grants more, and a deleted role leaves exactly that. Where a role is asked by name (hasWorker, isCommentOnly, ...) a custom role reads as the built-in role that does what it does; commenting is asked as a capability everywhere. Invites, REST whole-board reads, imports (a foreign custom role is dropped) and member mapping (all eight flags now, not four) follow it. The six new strings are translated in all 234 locales. #4178 (decided 2026-10-14): a team or organization that gives board memberships takes them away again when the user leaves it - only those: each records where it came from (grantedBy), a direct membership is never touched, a board admin is kept, and a board admin's own add or removal is final. Teams through user edits, LDAP, OIDC and the board sidebar; organizations where they propagate members. Also: the Roles Status table gets a Move cards column; the comment form, reactions and chat ask the comment capability (a No comments member was offered reactions the server refused). Tests: customBoardRoles and groupBoardMembership node suites, and the runtime suites (9 passing) against a real database. Thanks to xet7 and mfnalex ! Fixes #3022, Fixes #4178.
112 lines
5.0 KiB
JavaScript
112 lines
5.0 KiB
JavaScript
// Pure decision helper for mapping an imported VIRTUAL (placeholder) board member to a
|
|
// real user, from the board sidebar member-avatar popup.
|
|
//
|
|
// Security model — mapping can NEVER be used to gain privileges:
|
|
// - Only a board admin (or a site admin) may map.
|
|
// - The source must be an imported placeholder member of this board.
|
|
// - The target must be a real (non-imported) user.
|
|
// - When the target is ALREADY an active member, their entry and role are left
|
|
// EXACTLY as they were: mapping only removes the placeholder.
|
|
// - When the target is NOT a member yet (#6519 — after a Trello/CSV import the real
|
|
// people usually have no membership at all, so the old "must already be an active
|
|
// board member" rule left the picker showing nobody but the admin), the target is
|
|
// added with the PLACEHOLDER's OWN role — the role the import gave that person —
|
|
// never a higher one. Adding a board member with a chosen role is something the
|
|
// board admin doing the mapping can already do through the normal add-member flow,
|
|
// so this grants no capability that caller did not have; it just does it in one
|
|
// step and with the imported role rather than an arbitrary one. The caller-side
|
|
// invite policy (Admin Panel roles allowed to invite, same-org/team restriction,
|
|
// deactivated accounts) is enforced by the server before this plan is applied — see
|
|
// server/importedUserReconciliation.js.
|
|
//
|
|
// Returns { ok:true, newMembers, placeholderId, targetId, addedMember } or
|
|
// { ok:false, error } with a stable error key. `addedMember` tells the caller whether
|
|
// the plan CREATES/reactivates a membership, so it can run the invite-policy checks only
|
|
// then. Pure and dependency-free so it is unit-tested without a database.
|
|
|
|
function planBoardMemberMapping({
|
|
members,
|
|
placeholderId,
|
|
targetId,
|
|
callerId,
|
|
placeholderIsImported,
|
|
targetIsImported,
|
|
callerIsSiteAdmin = false,
|
|
} = {}) {
|
|
const list = Array.isArray(members) ? members : [];
|
|
const find = id => list.find(m => m && m.userId === id);
|
|
|
|
if (!placeholderId || !targetId || placeholderId === targetId) {
|
|
return { ok: false, error: 'bad-map' };
|
|
}
|
|
|
|
// Authorization: board admin of THIS board, or a site admin.
|
|
const caller = find(callerId);
|
|
const callerIsBoardAdmin = !!(caller && caller.isActive !== false && caller.isAdmin);
|
|
if (!callerIsSiteAdmin && !callerIsBoardAdmin) {
|
|
return { ok: false, error: 'not-authorized' };
|
|
}
|
|
|
|
// Source must be an imported placeholder that is a member of this board.
|
|
if (!placeholderIsImported) {
|
|
return { ok: false, error: 'not-a-placeholder' };
|
|
}
|
|
const placeholderMember = find(placeholderId);
|
|
if (!placeholderMember) {
|
|
return { ok: false, error: 'placeholder-not-member' };
|
|
}
|
|
|
|
// Target must be a REAL (non-imported) user. Mapping one placeholder onto another
|
|
// would just move the problem and could chain into an unintended identity.
|
|
if (targetIsImported) {
|
|
return { ok: false, error: 'target-not-real' };
|
|
}
|
|
|
|
const targetMember = find(targetId);
|
|
const targetIsActiveMember = !!(targetMember && targetMember.isActive !== false);
|
|
|
|
// Drop the placeholder entry in every case.
|
|
const withoutPlaceholder = list.filter(m => m && m.userId !== placeholderId);
|
|
|
|
if (targetIsActiveMember) {
|
|
// Existing active member: nothing about them changes, not even a flag.
|
|
return {
|
|
ok: true,
|
|
newMembers: withoutPlaceholder,
|
|
placeholderId,
|
|
targetId,
|
|
addedMember: false,
|
|
};
|
|
}
|
|
|
|
// Not a member yet (or an inactive membership): give them the PLACEHOLDER's role.
|
|
// Copying the placeholder's flags is what makes this a "this virtual member IS this
|
|
// person" operation rather than a role grant — and it can only ever equal the role the
|
|
// import already recorded, never exceed it.
|
|
// ALL eight role flags and the custom role (#3022) come from the placeholder:
|
|
// copying four used to turn a read-only or assigned-only placeholder into a
|
|
// normal member, and let a stale flag of the target's old membership stand.
|
|
const { customRoleId: staleCustomRole, ...targetRest } = targetMember || {};
|
|
const entry = {
|
|
...targetRest,
|
|
userId: targetId,
|
|
isActive: true,
|
|
isAdmin: placeholderMember.isAdmin === true,
|
|
isNoComments: placeholderMember.isNoComments === true,
|
|
isCommentOnly: placeholderMember.isCommentOnly === true,
|
|
isWorker: placeholderMember.isWorker === true,
|
|
isNormalAssignedOnly: placeholderMember.isNormalAssignedOnly === true,
|
|
isCommentAssignedOnly: placeholderMember.isCommentAssignedOnly === true,
|
|
isReadOnly: placeholderMember.isReadOnly === true,
|
|
isReadAssignedOnly: placeholderMember.isReadAssignedOnly === true,
|
|
...(placeholderMember.customRoleId ? { customRoleId: placeholderMember.customRoleId } : {}),
|
|
};
|
|
const newMembers = targetMember
|
|
? withoutPlaceholder.map(m => (m.userId === targetId ? entry : m))
|
|
: withoutPlaceholder.concat([entry]);
|
|
|
|
return { ok: true, newMembers, placeholderId, targetId, addedMember: true };
|
|
}
|
|
|
|
module.exports = { planBoardMemberMapping };
|