Files
wekan/server/publications/org.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

67 lines
2.5 KiB
JavaScript

import { ReactiveCache } from '/imports/reactiveCache';
import { safeSelector } from '/server/lib/selectorGuard';
// Multitenancy option D (D.7): the site admin sees every Organization, a per-tenant
// Global Admin sees the ones they administer. Same rule module as the people
// publication, so the two panes cannot disagree about who sees what.
import * as tenantAdmin from '/models/lib/tenantAdmin';
Meteor.publish('org', async function(query, limit, skip = 0) {
check(query, Match.OneOf(Object, null));
check(limit, Number);
check(skip, Match.OneOf(Number, null, undefined));
let ret = [];
const user = await ReactiveCache.getCurrentUser();
// 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, 'org');
if (tenantAdmin.canOpenAdminPanel(user)) {
ret = await ReactiveCache.getOrgs(tenantAdmin.orgScopeSelector(user, safeQuery),
{
limit,
skip: skip || 0,
sort: { createdAt: -1 },
fields: {
orgDisplayName: 1,
orgDesc: 1,
orgShortName: 1,
orgAutoAddUsersWithDomainName: 1,
orgWebsite: 1,
orgTeams: 1,
createdAt: 1,
orgIsActive: 1,
orgSharedTemplates: 1,
orgPropagateMembersToBoards: 1,
orgSyncMembersFromAuth: 1,
// Multitenancy option D: the hostnames this org is served on, and the
// branding that replaces the instance branding on them.
orgDomains: 1,
orgDomainsRequested: 1,
orgProductName: 1,
orgThemeColor: 1,
orgThemeCustomColors: 1,
orgCustomLoginLogoImageUrl: 1,
orgCustomLoginLogoLinkUrl: 1,
orgTextBelowCustomLoginLogo: 1,
orgCustomTopLeftCornerLogoImageUrl: 1,
orgCustomTopLeftCornerLogoLinkUrl: 1,
orgCustomHelpLinkUrl: 1,
orgLegalNotice: 1,
}
},
true,
);
} else if (user) {
// #5141: anybody else gets their OWN organizations' names, so a board
// admin can add them to a board (and only them: setBoardOrgs checks).
const ownIds = (user.orgs || []).map(o => o && o.orgId).filter(Boolean);
ret = await ReactiveCache.getOrgs({ _id: { $in: ownIds } }, { fields: { orgDisplayName: 1, orgShortName: 1 } }, true);
}
return ret;
});