mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
setBoardOrgs and setBoardTeams refused nothing but non-admins: a board admin could link any organization or team of the instance to a board, and with it give every one of its members the board. Now an organization or team that is new to the board must be one the board admin belongs to; a site administrator may add any. Links already on the board stay - somebody else may have added them - and removing or switching one off is always allowed. The pickers offer only the admin's own groups, and the org and team publications, which gave non-admins nothing (so the pickers were empty for them), now give a signed-in user their own groups' names. models/lib/boardGroupLinks.js decides; tests/boardGroupLinks.test.cjs covers own groups, existing links, removals, site admins, a foreign group refused and not offered, and that both methods check before writing. Thanks to chrisi51 and xet7 ! Fixes #5141.
27 lines
1.2 KiB
JavaScript
27 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
// #5141: a board admin may add to a board only the organizations and teams
|
|
// they belong to themselves; a site administrator may add any. What is
|
|
// already on the board stays (it may have been added by someone else), and
|
|
// removing or switching off a link is always allowed.
|
|
// Pure: tests/boardGroupLinks.test.cjs.
|
|
|
|
// The ids `next` adds to `previous` that this user may not add.
|
|
function forbiddenNewGroupIds({ previous = [], next = [], key, ownIds = [], isSiteAdmin = false }) {
|
|
if (isSiteAdmin) return [];
|
|
const before = new Set((Array.isArray(previous) ? previous : []).map(g => g && g[key]).filter(Boolean));
|
|
const own = new Set(Array.isArray(ownIds) ? ownIds : []);
|
|
return [...new Set((Array.isArray(next) ? next : []).map(g => g && g[key]).filter(Boolean))]
|
|
.filter(id => !before.has(id) && !own.has(id));
|
|
}
|
|
|
|
// What the add pickers offer: the user's own groups, or all for a site admin.
|
|
function offeredGroups(groups, ownIds, isSiteAdmin) {
|
|
const list = Array.isArray(groups) ? groups : [];
|
|
if (isSiteAdmin) return list;
|
|
const own = new Set(Array.isArray(ownIds) ? ownIds : []);
|
|
return list.filter(g => g && own.has(g._id));
|
|
}
|
|
|
|
module.exports = { forbiddenNewGroupIds, offeredGroups };
|