mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Ticking "Propagate Members To Boards" for a team in Admin Panel > People > Teams
stored the flag and added nobody. The members only appeared later, when the LDAP
sync cron ran the propagation by its other, correct route.
`setTeamPropagateMembersToBoards(team, value)` receives `team` as the SELECTOR the
client sent - `{ _id: … }`, the same value it hands to `Team.updateAsync` on the
line above - and passed it whole:
await propagateGroupMembersToBoards('team', team);
`propagateGroupMembersToBoards(kind, groupId)` puts that straight into the member
lookup, so it ran
Meteor.users.find({ 'teams.teamId': { _id: 'abc' } })
comparing a string field against an object. It matched nobody, the function
returned early with "0 boards updated, 0 members added", and nothing threw. The
checkbox went green and did nothing.
The org column beside it was identical - `setOrgPropagateMembersToBoards` passed
`org` the same way - and is fixed with it, though the report was about teams.
Both call sites pass the id now, and `propagateGroupMembersToBoards` normalises
whatever it is given at the one point every caller goes through: a plain id, or a
document/selector carrying one. Anything it cannot turn into an id is REFUSED AND
LOGGED rather than quietly treated as a group with no members, because a silent
"0 members added" is exactly how this survived a release. A missing group stays
quiet - propagateAllFlaggedGroupsToBoards may legitimately have nothing to pass.
The select-all checkbox in the column header is the same promise to the admin, and
it did not propagate at all, not even wrongly: setAllTeamsFeature /
setAllOrgsFeature set the flag on every row and stopped. They now propagate when
that field is the one being turned ON, and only for their own kind, so ticking the
team column does not act on the org column beside it.
propagateAllFlaggedGroupsToBoards takes an optional kind for this; the default is
unchanged, so the LDAP cron and the propagateOrgTeamMembersToBoards method still
do both.
The two wiring tests in tests/propagateMembers.test.cjs REQUIRED the buggy calls -
they asserted `propagateGroupMembersToBoards('team', team)` verbatim, pinning that
a call happened without asking whether its argument was right, and so held the bug
in place. They require the id now and fail if the whole selector comes back, and
the normaliser is exercised for real: every shape a caller might hold an id in
resolves to it, a selector with no id resolves to null AND warns, and an absent
group is quiet.
Thanks to ChristianMa97 and xet7 !
Fixes #6559,
422 lines
14 KiB
JavaScript
422 lines
14 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { WebApp } from 'meteor/webapp';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import Org from '/models/org';
|
|
import { ensureIndex } from '/server/lib/mongoStartup';
|
|
import { Authentication } from '/server/authentication';
|
|
import { sendJsonResult } from '/server/apiMiddleware';
|
|
// Multitenancy option D: per-tenant Global Admin rules (shared with the client and
|
|
// the publications) - docs/Design/Multitenancy/Multitenancy.md.
|
|
import * as tenantAdmin from '/models/lib/tenantAdmin';
|
|
|
|
// #5850: reliable admin check from a method's this.userId. Meteor.user()/
|
|
// getCurrentUser() can return null inside an async method after an await
|
|
// (the DDP invocation context is not always preserved), so we look the caller
|
|
// up directly by id.
|
|
async function callerIsAdmin(userId) {
|
|
if (!userId) return false;
|
|
const u = await ReactiveCache.getUser({ _id: userId }, { fields: { isAdmin: 1 } });
|
|
return !!(u && u.isAdmin);
|
|
}
|
|
|
|
Meteor.methods({
|
|
async setCreateOrg(
|
|
orgDisplayName,
|
|
orgDesc,
|
|
orgShortName,
|
|
orgAutoAddUsersWithDomainName,
|
|
orgWebsite,
|
|
orgIsActive,
|
|
) {
|
|
if ((await ReactiveCache.getCurrentUser())?.isAdmin) {
|
|
check(orgDisplayName, String);
|
|
check(orgDesc, String);
|
|
check(orgShortName, String);
|
|
check(orgAutoAddUsersWithDomainName, String);
|
|
check(orgWebsite, String);
|
|
check(orgIsActive, Boolean);
|
|
|
|
const nOrgNames = (await ReactiveCache.getOrgs({ orgShortName })).length;
|
|
if (nOrgNames > 0) {
|
|
throw new Meteor.Error('orgname-already-taken');
|
|
}
|
|
|
|
await Org.insertAsync({
|
|
orgDisplayName,
|
|
orgDesc,
|
|
orgShortName,
|
|
orgAutoAddUsersWithDomainName,
|
|
orgWebsite,
|
|
orgIsActive,
|
|
});
|
|
}
|
|
},
|
|
|
|
async setCreateOrgFromOidc(
|
|
orgDisplayName,
|
|
orgDesc,
|
|
orgShortName,
|
|
orgAutoAddUsersWithDomainName,
|
|
orgWebsite,
|
|
orgIsActive,
|
|
) {
|
|
// SECURITY (GHSA-cv95-8h7c-2ffq): This *FromOidc method is an internal
|
|
// helper invoked only server-side during the OIDC login flow (via
|
|
// Meteor.callAsync from packages/wekan-oidc/loginHandler.js). It performs
|
|
// a privileged org write with no per-user authorization, so it must never
|
|
// be callable directly by a client over DDP — otherwise any authenticated
|
|
// user could create/modify organizations, bypassing the admin-only check
|
|
// on setCreateOrg/setOrgAllFields. A server-side method call has
|
|
// this.connection === null; a direct client call has a non-null
|
|
// connection. Reject the latter.
|
|
if (this.connection !== null) {
|
|
throw new Meteor.Error('not-authorized');
|
|
}
|
|
check(orgDisplayName, String);
|
|
check(orgDesc, String);
|
|
check(orgShortName, String);
|
|
check(orgAutoAddUsersWithDomainName, String);
|
|
check(orgWebsite, String);
|
|
check(orgIsActive, Boolean);
|
|
|
|
const nOrgNames = (await ReactiveCache.getOrgs({ orgShortName })).length;
|
|
if (nOrgNames > 0) {
|
|
throw new Meteor.Error('orgname-already-taken');
|
|
}
|
|
|
|
await Org.insertAsync({
|
|
orgDisplayName,
|
|
orgDesc,
|
|
orgShortName,
|
|
orgAutoAddUsersWithDomainName,
|
|
orgWebsite,
|
|
orgIsActive,
|
|
});
|
|
},
|
|
|
|
async setOrgDisplayName(org, orgDisplayName) {
|
|
if ((await ReactiveCache.getCurrentUser())?.isAdmin) {
|
|
check(org, Object);
|
|
check(orgDisplayName, String);
|
|
await Org.updateAsync(org, {
|
|
$set: { orgDisplayName },
|
|
});
|
|
await Meteor.callAsync('setUsersOrgsOrgDisplayName', org._id, orgDisplayName);
|
|
}
|
|
},
|
|
|
|
async setOrgDesc(org, orgDesc) {
|
|
if ((await ReactiveCache.getCurrentUser())?.isAdmin) {
|
|
check(org, Object);
|
|
check(orgDesc, String);
|
|
await Org.updateAsync(org, {
|
|
$set: { orgDesc },
|
|
});
|
|
}
|
|
},
|
|
|
|
async setOrgShortName(org, orgShortName) {
|
|
if ((await ReactiveCache.getCurrentUser())?.isAdmin) {
|
|
check(org, Object);
|
|
check(orgShortName, String);
|
|
await Org.updateAsync(org, {
|
|
$set: { orgShortName },
|
|
});
|
|
}
|
|
},
|
|
|
|
async setAutoAddUsersWithDomainName(org, orgAutoAddUsersWithDomainName) {
|
|
if ((await ReactiveCache.getCurrentUser())?.isAdmin) {
|
|
check(org, Object);
|
|
check(orgAutoAddUsersWithDomainName, String);
|
|
await Org.updateAsync(org, {
|
|
$set: { orgAutoAddUsersWithDomainName },
|
|
});
|
|
}
|
|
},
|
|
|
|
async setOrgIsActive(org, orgIsActive) {
|
|
if ((await ReactiveCache.getCurrentUser())?.isAdmin) {
|
|
check(org, Object);
|
|
check(orgIsActive, Boolean);
|
|
await Org.updateAsync(org, {
|
|
$set: { orgIsActive },
|
|
});
|
|
}
|
|
},
|
|
|
|
// #4737/#5850: per-org feature toggles shown as columns in Admin Panel >
|
|
// People > Organizations. All default off. NOTE: arguments are check()ed
|
|
// unconditionally (audit-argument-checks), and admin is verified via the
|
|
// method's this.userId (Meteor.user()/getCurrentUser() can lose the DDP
|
|
// invocation context across awaits in async methods and return null).
|
|
async setOrgSharedTemplates(org, value) {
|
|
check(org, Object);
|
|
check(value, Boolean);
|
|
if (await callerIsAdmin(this.userId)) {
|
|
await Org.updateAsync(org, { $set: { orgSharedTemplates: value } });
|
|
}
|
|
},
|
|
|
|
async setOrgPropagateMembersToBoards(org, value) {
|
|
check(org, Object);
|
|
check(value, Boolean);
|
|
if (await callerIsAdmin(this.userId)) {
|
|
await Org.updateAsync(org, { $set: { orgPropagateMembersToBoards: value } });
|
|
// #4737/#5850: actually ACT on the flag. Turning it on adds this org's
|
|
// members to the boards that list the org (add-only). Previously the flag
|
|
// was stored but nothing ever propagated (the method had no caller).
|
|
//
|
|
// #6559: `org` is the SELECTOR the client sent - `{ _id: … }`, the same
|
|
// value handed to updateAsync above - not an id. Passing it whole made the
|
|
// member lookup compare `orgs.orgId` against an object, which matches
|
|
// nobody, so the checkbox stored the flag and silently added no one. The
|
|
// report was about the team column; the org column beside it was identical.
|
|
if (value === true) {
|
|
const { propagateGroupMembersToBoards } = require('/server/propagateOrgTeamMembers');
|
|
await propagateGroupMembersToBoards('org', org._id);
|
|
}
|
|
}
|
|
},
|
|
|
|
async setOrgSyncMembersFromAuth(org, value) {
|
|
check(org, Object);
|
|
check(value, Boolean);
|
|
if (await callerIsAdmin(this.userId)) {
|
|
await Org.updateAsync(org, { $set: { orgSyncMembersFromAuth: value } });
|
|
}
|
|
},
|
|
|
|
// Bulk select-all / unselect-all for one of the org feature columns.
|
|
async setAllOrgsFeature(field, value) {
|
|
check(field, String);
|
|
check(value, Boolean);
|
|
if (await callerIsAdmin(this.userId)) {
|
|
const allowed = [
|
|
'orgSharedTemplates',
|
|
'orgPropagateMembersToBoards',
|
|
'orgSyncMembersFromAuth',
|
|
];
|
|
if (!allowed.includes(field)) {
|
|
throw new Meteor.Error('invalid-field');
|
|
}
|
|
await Org.updateAsync({}, { $set: { [field]: value } }, { multi: true });
|
|
// #6559: the select-all header checkbox is the same promise as the per-row
|
|
// one - tick it and the members should be on the boards - and it did not
|
|
// propagate at all, not even wrongly. Orgs only: ticking the org column
|
|
// must not act on the team column beside it.
|
|
if (field === 'orgPropagateMembersToBoards' && value === true) {
|
|
const { propagateAllFlaggedGroupsToBoards } = require('/server/propagateOrgTeamMembers');
|
|
await propagateAllFlaggedGroupsToBoards('org');
|
|
}
|
|
}
|
|
},
|
|
|
|
async setOrgAllFieldsFromOidc(
|
|
org,
|
|
orgDisplayName,
|
|
orgDesc,
|
|
orgShortName,
|
|
orgAutoAddUsersWithDomainName,
|
|
orgWebsite,
|
|
orgIsActive,
|
|
) {
|
|
// SECURITY (GHSA-cv95-8h7c-2ffq): Internal OIDC-login-only helper (called
|
|
// server-side from packages/wekan-oidc/loginHandler.js). Performs a
|
|
// privileged org update of an arbitrary _id with no per-user
|
|
// authorization, so reject direct client/DDP calls (this.connection
|
|
// non-null) to keep the admin-only restriction of setOrgAllFields intact.
|
|
if (this.connection !== null) {
|
|
throw new Meteor.Error('not-authorized');
|
|
}
|
|
check(org, Object);
|
|
check(orgDisplayName, String);
|
|
check(orgDesc, String);
|
|
check(orgShortName, String);
|
|
check(orgAutoAddUsersWithDomainName, String);
|
|
check(orgWebsite, String);
|
|
check(orgIsActive, Boolean);
|
|
await Org.updateAsync(org, {
|
|
$set: {
|
|
orgDisplayName,
|
|
orgDesc,
|
|
orgShortName,
|
|
orgAutoAddUsersWithDomainName,
|
|
orgWebsite,
|
|
orgIsActive,
|
|
},
|
|
});
|
|
await Meteor.callAsync('setUsersOrgsOrgDisplayName', org._id, orgDisplayName);
|
|
},
|
|
|
|
async setOrgAllFields(
|
|
org,
|
|
orgDisplayName,
|
|
orgDesc,
|
|
orgShortName,
|
|
orgAutoAddUsersWithDomainName,
|
|
orgWebsite,
|
|
orgIsActive,
|
|
) {
|
|
if ((await ReactiveCache.getCurrentUser())?.isAdmin) {
|
|
check(org, Object);
|
|
check(orgDisplayName, String);
|
|
check(orgDesc, String);
|
|
check(orgShortName, String);
|
|
check(orgAutoAddUsersWithDomainName, String);
|
|
check(orgWebsite, String);
|
|
check(orgIsActive, Boolean);
|
|
await Org.updateAsync(org, {
|
|
$set: {
|
|
orgDisplayName,
|
|
orgDesc,
|
|
orgShortName,
|
|
orgAutoAddUsersWithDomainName,
|
|
orgWebsite,
|
|
orgIsActive,
|
|
},
|
|
});
|
|
await Meteor.callAsync('setUsersOrgsOrgDisplayName', org._id, orgDisplayName);
|
|
}
|
|
},
|
|
|
|
async getOrgsCollectionCount(query = {}) {
|
|
check(query, Match.OneOf(Object, null, undefined));
|
|
// Multitenancy option D (D.7): scoped exactly like the `org` publication, so a
|
|
// per-tenant Global Admin's pager counts the orgs they can actually see.
|
|
const user = await ReactiveCache.getUser(
|
|
{ _id: this.userId }, { fields: { isAdmin: 1, orgs: 1 } });
|
|
if (!tenantAdmin.canOpenAdminPanel(user)) {
|
|
throw new Meteor.Error('not-authorized');
|
|
}
|
|
const cursor = await ReactiveCache.getOrgs(
|
|
tenantAdmin.orgScopeSelector(user, query || {}), {}, true);
|
|
return typeof cursor.countAsync === 'function' ? await cursor.countAsync() : cursor.count();
|
|
},
|
|
});
|
|
|
|
Meteor.startup(async () => {
|
|
await ensureIndex(Org, { orgDisplayName: 1 });
|
|
});
|
|
|
|
// #4737/#5850: per-org feature toggles exposed over the GlobalAdmin REST API.
|
|
const ORG_FEATURE_FIELDS = [
|
|
'orgSharedTemplates',
|
|
'orgPropagateMembersToBoards',
|
|
'orgSyncMembersFromAuth',
|
|
];
|
|
|
|
/**
|
|
* @operation get_admin_orgs
|
|
* @tag Organizations
|
|
*
|
|
* @summary List organizations with their feature toggles (GlobalAdmin)
|
|
*
|
|
* @description Only the global admin can call this. Returns every organization
|
|
* with its identifying fields and the per-org feature toggles shown as columns
|
|
* in Admin Panel > People > Organizations.
|
|
*
|
|
* @return_type [{_id: string, orgDisplayName: string, orgShortName: string, orgSharedTemplates: boolean, orgPropagateMembersToBoards: boolean, orgSyncMembersFromAuth: boolean}]
|
|
*/
|
|
WebApp.handlers.get('/api/admin/orgs', async function(req, res) {
|
|
try {
|
|
await Authentication.checkUserId(req.userId);
|
|
const orgs = await Org.find(
|
|
{},
|
|
{
|
|
fields: {
|
|
orgDisplayName: 1,
|
|
orgShortName: 1,
|
|
orgSharedTemplates: 1,
|
|
orgPropagateMembersToBoards: 1,
|
|
orgSyncMembersFromAuth: 1,
|
|
},
|
|
},
|
|
).fetchAsync();
|
|
const data = orgs.map(org => ({
|
|
_id: org._id,
|
|
orgDisplayName: org.orgDisplayName,
|
|
orgShortName: org.orgShortName,
|
|
orgSharedTemplates: !!org.orgSharedTemplates,
|
|
orgPropagateMembersToBoards: !!org.orgPropagateMembersToBoards,
|
|
orgSyncMembersFromAuth: !!org.orgSyncMembersFromAuth,
|
|
}));
|
|
sendJsonResult(res, { code: 200, data });
|
|
} catch (error) {
|
|
sendJsonResult(res, { code: 200, data: error });
|
|
}
|
|
});
|
|
|
|
/**
|
|
* @operation update_admin_org_features
|
|
* @tag Organizations
|
|
*
|
|
* @summary Set feature toggles on one organization (GlobalAdmin)
|
|
*
|
|
* @description Only the global admin can call this. The request body may
|
|
* contain any of `orgSharedTemplates`, `orgPropagateMembersToBoards` and
|
|
* `orgSyncMembersFromAuth` (booleans); only those whitelisted fields are
|
|
* `$set` on the organization. Returns the updated organization.
|
|
*
|
|
* @param {string} orgId the ID of the organization
|
|
* @param {Object} features the feature toggles to set
|
|
* @return_type Object
|
|
*/
|
|
WebApp.handlers.put('/api/admin/orgs/:orgId/features', async function(req, res) {
|
|
try {
|
|
await Authentication.checkUserId(req.userId);
|
|
const orgId = req.params.orgId;
|
|
const body = req.body || {};
|
|
const $set = {};
|
|
ORG_FEATURE_FIELDS.forEach(field => {
|
|
if (body[field] !== undefined) {
|
|
$set[field] = !!body[field];
|
|
}
|
|
});
|
|
if (Object.keys($set).length > 0) {
|
|
await Org.updateAsync(orgId, { $set });
|
|
}
|
|
const updated = await Org.findOneAsync(orgId);
|
|
sendJsonResult(res, { code: 200, data: updated });
|
|
} catch (error) {
|
|
sendJsonResult(res, { code: 200, data: error });
|
|
}
|
|
});
|
|
|
|
/**
|
|
* @operation update_all_admin_org_features
|
|
* @tag Organizations
|
|
*
|
|
* @summary Set one feature toggle on all organizations (GlobalAdmin)
|
|
*
|
|
* @description Only the global admin can call this. The request body is
|
|
* `{ field, value }` where `field` is one of `orgSharedTemplates`,
|
|
* `orgPropagateMembersToBoards` or `orgSyncMembersFromAuth` and `value` is a
|
|
* boolean. The field is `$set` on ALL organizations. Returns the number of
|
|
* organizations updated.
|
|
*
|
|
* @param {string} field the feature field to set
|
|
* @param {boolean} value the value to set
|
|
* @return_type {updated: number}
|
|
*/
|
|
WebApp.handlers.put('/api/admin/orgs/features', async function(req, res) {
|
|
try {
|
|
await Authentication.checkUserId(req.userId);
|
|
const body = req.body || {};
|
|
const field = body.field;
|
|
if (!ORG_FEATURE_FIELDS.includes(field)) {
|
|
sendJsonResult(res, { code: 200, data: { error: 'invalid-field' } });
|
|
return;
|
|
}
|
|
const value = !!body.value;
|
|
const updated = await Org.updateAsync(
|
|
{},
|
|
{ $set: { [field]: value } },
|
|
{ multi: true },
|
|
);
|
|
sendJsonResult(res, { code: 200, data: { updated } });
|
|
} catch (error) {
|
|
sendJsonResult(res, { code: 200, data: error });
|
|
}
|
|
});
|