mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
A board a member reaches through one of their teams or organizations, or their e-mail domain, could not be left: without a member entry quitBoard refused it, and with one the board stayed in All Boards through the team. Now leaving such a board puts it in the member's own hidden list (profile.hiddenBoards): All Boards leaves it out, in the paged sorted views and the drag-ordered one, and Member Settings / Hidden boards brings it back with Restore. The team or organization membership is not touched, and access stays the board's own. An All Boards tile of a board the member is not on gets an eye-slash "leave" button; a member who also has the board through a team is both removed and hidden. A board reached only by membership leaves as before. models/lib/boardInvites.js decides (planQuitBoard's hide, reachesBoardOtherwise, hiddenBoardsAfter); tests/hiddenBoards.test.cjs covers team, organization and domain reach, an inactive link, the bound, that the team is not touched and the All Boards filters. tests/boardInvites.test.cjs expects the plan's hide: false where nothing else reaches the board. The new strings are English placeholders until the next translation pass. Thanks to LaureHades and xet7 ! Fixes #4265.
105 lines
4.8 KiB
JavaScript
105 lines
4.8 KiB
JavaScript
'use strict';
|
|
|
|
// Pure decision helpers for board invitation accept / decline (quit) flows.
|
|
// Extracted so the logic is unit-testable in plain Node without Meteor
|
|
// (mirrors models/lib/boardSortReorder.js).
|
|
//
|
|
// #4730 ("Bugs in adding and removing users"):
|
|
//
|
|
// Case 2 of the issue — "User A declines the invitation but still sees board 1
|
|
// in the personal overview" — was caused by the decline handler on the All
|
|
// Boards page (client/components/boards/boardsList.js), which calls
|
|
// `quitBoard` (deactivates the member entry) and then `acceptInvite` to clear
|
|
// the invitation. The old server-side `acceptInvite` unconditionally set
|
|
// `members.$.isActive = true`, immediately RE-ACTIVATING the membership that
|
|
// `quitBoard` had just deactivated — so the declined board stayed in the
|
|
// user's personal overview as an active membership.
|
|
//
|
|
// The same unconditional re-activation also let any user with a deactivated
|
|
// member entry (i.e. someone an admin had removed from the board) re-add
|
|
// themselves simply by calling `Meteor.call('acceptInvite', boardId)` — the
|
|
// "adding and removing user A again doesn't fix it" half of Case 1.
|
|
//
|
|
// Fix: activating a membership through acceptInvite is only legitimate while
|
|
// the user actually holds an invitation (profile.invitedBoards contains the
|
|
// board id). Declining is made robust by having quitBoard clear the pending
|
|
// invitation itself, so the follow-up acceptInvite call finds no invitation
|
|
// and becomes a no-op. quitBoard also succeeds (instead of throwing
|
|
// error-board-notAMember) for a user who holds a stale invitation without a
|
|
// member entry — e.g. after an admin removed them — so a stuck invited board
|
|
// can always be removed from the personal overview.
|
|
|
|
// Whether the given user profile holds a pending invitation to boardId.
|
|
function isInvitedToBoard(profile, boardId) {
|
|
if (!boardId) return false;
|
|
const invitedBoards = (profile && profile.invitedBoards) || [];
|
|
return Array.isArray(invitedBoards) && invitedBoards.includes(boardId);
|
|
}
|
|
|
|
// Decide what `quitBoard` (leave board / decline invitation) must do.
|
|
// - A member quits: deactivate the member entry, and clear any pending
|
|
// invitation so a later acceptInvite cannot resurrect the membership.
|
|
// - A non-member with a pending (stale) invitation: just clear the invitation
|
|
// and report success, so the board disappears from the personal overview.
|
|
// - Neither member nor invited: nothing to quit — error.
|
|
//
|
|
// #4265: a board the user also reaches some other way - one of their teams or
|
|
// organizations, or their e-mail domain - would still be in All Boards after
|
|
// the member entry went, and a user who reaches it ONLY that way has no member
|
|
// entry to leave. Leaving such a board HIDES it: it goes into the user's own
|
|
// hidden list (profile.hiddenBoards), from which Member Settings restores it,
|
|
// and the team or organization membership is not touched.
|
|
function planQuitBoard({ isMember, isInvited, reachableOtherwise = false }) {
|
|
if (!isMember && !isInvited && reachableOtherwise) {
|
|
return { ok: true, removeMember: false, pullInvite: false, hide: true };
|
|
}
|
|
if (!isMember && !isInvited) {
|
|
return {
|
|
ok: false,
|
|
removeMember: false,
|
|
pullInvite: false,
|
|
error: 'error-board-notAMember',
|
|
};
|
|
}
|
|
return {
|
|
ok: true,
|
|
removeMember: !!isMember,
|
|
pullInvite: !!isInvited,
|
|
hide: !!reachableOtherwise,
|
|
};
|
|
}
|
|
|
|
// Whether the user reaches the board through a team, an organization or an
|
|
// e-mail domain (the same ways models/lib/boardVisibilitySelectors.js lists).
|
|
function reachesBoardOtherwise(board, { teamIds = [], orgIds = [], emailDomains = [] } = {}) {
|
|
if (!board) return false;
|
|
const active = (list, key, ids) => (Array.isArray(list) ? list : [])
|
|
.some(entry => entry && entry.isActive !== false && ids.includes(entry[key]));
|
|
return active(board.teams, 'teamId', teamIds) || active(board.orgs, 'orgId', orgIds)
|
|
|| (Array.isArray(board.domains) ? board.domains : []).some(d => d && emailDomains.includes(d.domain));
|
|
}
|
|
|
|
// The hidden list after hiding or restoring a board: once each, bounded.
|
|
function hiddenBoardsAfter(current, boardId, hide) {
|
|
const list = (Array.isArray(current) ? current : []).filter(id => typeof id === 'string' && id !== boardId);
|
|
return hide ? [...list, boardId].slice(-1000) : list;
|
|
}
|
|
|
|
// Decide what `acceptInvite` must do. Only a user actually holding an
|
|
// invitation may (re)activate their member entry; for anyone else the call is
|
|
// a no-op (#4730: this is what used to re-activate declined/removed members).
|
|
function planAcceptInvite({ isInvited }) {
|
|
if (!isInvited) {
|
|
return { ok: false, pullInvite: false, activateMember: false };
|
|
}
|
|
return { ok: true, pullInvite: true, activateMember: true };
|
|
}
|
|
|
|
module.exports = {
|
|
reachesBoardOtherwise,
|
|
hiddenBoardsAfter,
|
|
isInvitedToBoard,
|
|
planQuitBoard,
|
|
planAcceptInvite,
|
|
};
|