Files
wekan/server/publications/team.js
T
Lauri Ojansivu ed2649f702 A board admin may add only the organizations and teams they belong to.
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.
2026-10-14 15:04:41 +03:00

47 lines
1.6 KiB
JavaScript

import { ReactiveCache } from '/imports/reactiveCache';
import { safeSelector } from '/server/lib/selectorGuard';
Meteor.publish('team', async function(query, limit, skip = 0) {
check(query, Match.OneOf(Object, null));
check(limit, Number);
check(skip, Match.OneOf(Number, null, undefined));
const user = await ReactiveCache.getCurrentUser();
let ret = [];
// GHSA-phm4-4v26-j2vq: the check above validates the TYPE of the selector and
// nothing else, and a selector is executable data - `$where` makes the database
// run the caller's JavaScript per document scanned. Refuse one that carries an
// execution operator, with the same "match nothing" the card window uses.
const safeQuery = safeSelector(query, 'team');
if (user && user.isAdmin) {
ret = await ReactiveCache.getTeams(safeQuery,
{
limit,
skip: skip || 0,
sort: { createdAt: -1 },
fields: {
teamDisplayName: 1,
teamDesc: 1,
teamShortName: 1,
teamWebsite: 1,
teams: 1,
createdAt: 1,
teamIsActive: 1,
teamSharedTemplates: 1,
teamPropagateMembersToBoards: 1,
teamSyncMembersFromAuth: 1,
}
},
true,
);
} else if (user) {
// #5141: anybody else gets their OWN teams' names, so a board admin can
// add them to a board (and only them: setBoardTeams checks).
const ownIds = (user.teams || []).map(t => t && t.teamId).filter(Boolean);
ret = await ReactiveCache.getTeams({ _id: { $in: ownIds } }, { fields: { teamDisplayName: 1, teamShortName: 1 } }, true);
}
return ret;
});