Files
wekan/models/lib/boardInvites.js
T
Lauri Ojansivu 9ddbc777dd Startup schema upgrade, self-healing attachments, migration speed; fix
#5695 #4897 #4654 #5174 #4825 #5659 #4730 #4419 #4158 #4560 #4036
#1959 #1971.

- Startup schema upgrade (server/lib/schemaUpgradeSteps.js): on start,
  check that data from EVERY old WeKan version is migrated to the newest
  structure and migrate only what is missing - all platforms, MongoDB and
  FerretDB. Version-gated (marker stores WeKan version + datetime of the
  last re-check; one findOne per boot until a new release), non-blocking,
  live dashboard at /schema-upgrade-status showing the product name, fast
  on big databases (distinct() set-joins, updateMany batches). Steps:
  archived-flag backfill, swimlane structure + visibility rescue
  (#1959 #1971: cards under deleted/archived/foreign swimlanes reassigned
  to a visible swimlane; card-insert hook validates supplied swimlaneIds),
  merge-per-swimlane-lists (v7.98/v8.0x list copies merged back into
  shared lists: no duplicate columns in Lists view, everything visible in
  Swimlanes view, cards keep their swimlane), embedded checklist items,
  customFields boardIds, allows* backfills, members isActive, permission
  lowercase, filesystem path healing.
- Migration speed (5-hour reports): insertMany batches in the text phase,
  preloaded target-record maps in the file phases.
- Snap attachment-repair + FILES_ONLY importer mode (see prior commit
  wiring) extended with CFS FileSystem-store coverage
  (ATTACHMENTS_STORE_PATH era), missing-binary reporting, and
  migrate-gridfs-to-fs.mjs bucket fixes.
- OAuth2/OIDC: OAUTH2_LOGIN_STYLE=redirect honored (#5695); concurrent
  logins no longer contaminate each other's user data (#4897); account
  merge no longer wipes avatars/templates (#4560).
- LDAP: background sync fixed (#4654), password login rejected after LDAP
  migration (#4419), LDAP_ENCRYPTION=true actually encrypts (#4158),
  group filter accepts multiple groups and admits admin-sync groups
  (#4036).
- All Boards tiles: per-list card counts + member avatars restored
  non-reactively (#5174 #4825). Uniform default list widths (#5659).
  Declined invitations no longer resurrect membership (#4730).
- Tests with negative cases for every fix (tests/*.test.cjs; suite green
  except the pre-existing environment-only htmljs failure).

Closes #5600: OAUTH2_CA_CERT already works - the fetch migration
(49a272d6c) applies the CA to all OIDC calls via https.Agent.
Closes #3828: board members seeing all board cards is by design (no
per-card visibility model), and organizations/teams now exist.

Thanks to mueschel, ArturRuta, gerardo-junior, fabianrbz, Miuler,
butteredCat-2021, Griiimm, preciousamorc, farwayer, LeoLu-eng, hnb1,
rangersdo and xet7.
2026-07-17 03:07:59 +03:00

76 lines
3.2 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.
function planQuitBoard({ isMember, isInvited }) {
if (!isMember && !isInvited) {
return {
ok: false,
removeMember: false,
pullInvite: false,
error: 'error-board-notAMember',
};
}
return {
ok: true,
removeMember: !!isMember,
pullInvite: !!isInvited,
};
}
// 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 = {
isInvitedToBoard,
planQuitBoard,
planAcceptInvite,
};