The Open Source kanban (built with Meteor). Keep variable/table/field names camelCase. For translations, only add Pull Request changes to wekan/i18n/en.i18n.json , other translations are done at https://transifex.com/wekan/wekan only.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
wekan/server/lib/removeMember.js

33 lines
1.5 KiB

/**
* Pure, dependency-free helper for removing a board member entry by userId.
*
* This module intentionally has NO Meteor / collection imports so it can be
* imported directly by unit tests (mocha + chai) without a running app, while
* still being the single source of truth used by models/boards.js when a member
* must be hard-removed from board.members.
*
* #5330 "Remove a non-existent (removed user) from a board member is not
* working": after a user account is deleted the user still appears in some
* boards' member lists, and removing them did nothing because the removal flow
* looked the user up and bailed out when the Users document no longer existed.
*
* The member entry on a board references the user only by userId, so removal
* must work purely on that id, regardless of whether the Users document still
* exists.
*/
/**
* Return a new members array with the entry matching userId removed.
*
* Works whether or not the referenced user still exists, since matching is by
* the stored userId only. If no entry matches, the (copied) array is returned
* unchanged (no-op).
*
* @param {Array<{userId:string}>} members - board.members
* @param {string} userId - userId of the member entry to remove
* @returns {Array<{userId:string}>} members without the matching entry
*/
export function pullMemberById(members, userId) {
const list = Array.isArray(members) ? members : [];
return list.filter(member => !(member && member.userId === userId));
}