Files
wekan/models/lib/propagateMembers.js
T
Lauri Ojansivu 5234d09d15 Org/Team: the 'Propagate Members To Boards' flag now actually propagates.
#4737/#5850: the per-org/team orgPropagateMembersToBoards / teamPropagateMembersToBoards flag was stored and shown in the Admin Panel, but the propagateOrgTeamMembersToBoards method that acts on it had NO caller anywhere — dead code, so turning the flag on did nothing. The propagation logic is refactored into exported propagateGroupMembersToBoards(kind, groupId) / propagateAllFlaggedGroupsToBoards() (the Meteor method now delegates to the latter), and the flag setters setTeamPropagateMembersToBoards / setOrgPropagateMembersToBoards now run the propagation for that group when the flag is turned ON. Still strictly add-only (existing board members are never removed/modified) and template boards are skipped; the add-only member computation is extracted to a pure, unit-tested models/lib/propagateMembers.js.

Tests: tests/propagateMembers.test.cjs (9 checks) covers membersToAddToBoard (add-only, de-dup, already-member, invalid inputs) and source guards that both flag-setters propagate on enable, the method delegates to the shared impl, and it stays add-only + board-type-only.

Thanks to xet7 !
2026-07-22 12:15:56 +03:00

40 lines
1.4 KiB
JavaScript

'use strict';
// Pure decision logic for the per-org/team "Propagate Members To Boards" flag
// (#4737 / #5850). Extracted from server/propagateOrgTeamMembers.js so the
// add-only membership computation is unit-testable without Meteor.
//
// The propagation is strictly ADD-ONLY: a user who is a member of a flagged
// org/team is added as a normal (active, non-admin) board member of every
// regular board that lists that org/team, and existing board members are never
// removed or modified.
// Given a board's current `members` array and the org/team member userIds,
// return the NEW member entries to append (for the users not already members).
// Returns [] when there is nothing to add. Does not mutate the inputs.
function membersToAddToBoard(existingMembers, memberUserIds) {
const existing = new Set(
(Array.isArray(existingMembers) ? existingMembers : [])
.map(m => m && m.userId)
.filter(Boolean),
);
const seen = new Set();
const toAdd = [];
for (const userId of Array.isArray(memberUserIds) ? memberUserIds : []) {
if (!userId || typeof userId !== 'string') continue;
if (existing.has(userId) || seen.has(userId)) continue;
seen.add(userId);
toAdd.push({
userId,
isAdmin: false,
isActive: true,
isNoComments: false,
isCommentOnly: false,
isWorker: false,
});
}
return toAdd;
}
module.exports = { membersToAddToBoard };