mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Fixes the bugs the new Playwright specs (30/31/32/33) surfaced in the recently
added All Boards / Templates redesign and per-org/team/domain board sharing:
- server/imports.js: import the new server method modules (ldapGroupSync,
sharedTemplateTargets, propagateOrgTeamMembers). This app uses an explicit
server mainModule, so files not imported here are never loaded and their
Meteor methods are not registered ("method not found").
- server/ldapGroupSync.js (setUserOrgsTeamsFromLdap): call check() on ALL
arguments FIRST, before the admin guard. When the guard threw before the
checks ran, audit-argument-checks raised "Did not check() all arguments" as an
unhandled rejection, which SyncedCron's global unhandledRejection handler
turned into a full app crash. Also read the caller with an explicit
{_id}-selector + isAdmin projection.
- server/models/org.js, server/models/team.js: the per-org/team feature-toggle
methods (setOrg/Team SharedTemplates, PropagateMembersToBoards,
SyncMembersFromAuth, setAll*Feature) now check() arguments unconditionally and
authorize via a callerIsAdmin(this.userId) helper instead of
Meteor.user()/getCurrentUser(), which can return null inside an async method
after an await.
- server/publications/boards.js (publishComposite 'boards'): publish
template-container boards and domain-shared boards too (was hardcoded
type:'board'), so the Templates sub-view and domain-based sharing actually
show their boards.
- client/components/boards/boardsList.js: the /templates and /remaining routes
now apply the same membership filtering as the home route (previously only
'home' did, so those views were empty).
- tests/playwright/specs/33-board-domains.e2e.js: assert the domain-shared board
via the Remaining sub-view; the default All Boards view is Starred, which only
lists starred boards.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
91 lines
3.7 KiB
JavaScript
91 lines
3.7 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { check } from 'meteor/check';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import Org from '/models/org';
|
|
import Team from '/models/team';
|
|
|
|
// #4737: helper that syncs a user's LDAP groups into Wekan Organizations or
|
|
// Teams. It is called server-to-server from the wekan-ldap package via
|
|
// Meteor.callAsync (where `this.connection` is null), and may also be called by
|
|
// an admin (admins already manage orgs/teams in the Admin Panel). Any other
|
|
// client-originated call is rejected. It finds the Org/Team by display name,
|
|
// creates it (active) if missing, and adds it to the user's membership. The
|
|
// update is add-only: existing memberships — including ones assigned manually or
|
|
// from another source — are preserved, so enabling LDAP org/team sync never
|
|
// removes a user's other memberships.
|
|
Meteor.methods({
|
|
async setUserOrgsTeamsFromLdap(userId, groupNames, asOrganization) {
|
|
// Check ALL arguments first, unconditionally: audit-argument-checks throws
|
|
// "Did not check() all arguments" otherwise, and that rejection (when the
|
|
// admin guard below throws first) escapes as an unhandledRejection that
|
|
// SyncedCron's global handler turns into a full app crash.
|
|
check(userId, String);
|
|
check(groupNames, [String]);
|
|
check(asOrganization, Boolean);
|
|
// Allow server-to-server calls (connection === null, used by the LDAP sync)
|
|
// and admins; reject any other client-originated call.
|
|
if (this.connection !== null) {
|
|
const caller = this.userId
|
|
? await ReactiveCache.getUser({ _id: this.userId }, { fields: { isAdmin: 1 } })
|
|
: null;
|
|
if (!caller || caller.isAdmin !== true) {
|
|
throw new Meteor.Error('forbidden', 'Not authorized');
|
|
}
|
|
}
|
|
|
|
const user = await ReactiveCache.getUser(userId);
|
|
if (!user) {
|
|
return;
|
|
}
|
|
|
|
// De-duplicate and drop empties so a group is not processed twice.
|
|
const names = [...new Set(groupNames.map(n => (n || '').trim()).filter(Boolean))];
|
|
|
|
for (const name of names) {
|
|
if (asOrganization) {
|
|
let org = await Org.findOneAsync({ orgDisplayName: name });
|
|
if (!org) {
|
|
const orgId = await Org.insertAsync({
|
|
orgDisplayName: name,
|
|
orgShortName: name,
|
|
orgIsActive: true,
|
|
// #5850: the auth sync marks the orgs it manages.
|
|
orgSyncMembersFromAuth: true,
|
|
});
|
|
org = { _id: orgId };
|
|
} else if (org.orgSyncMembersFromAuth !== true) {
|
|
await Org.updateAsync({ _id: org._id }, { $set: { orgSyncMembersFromAuth: true } });
|
|
}
|
|
const alreadyMember = (user.orgs || []).some(o => o.orgId === org._id);
|
|
if (!alreadyMember) {
|
|
await Meteor.users.updateAsync(
|
|
{ _id: userId },
|
|
{ $push: { orgs: { orgId: org._id, orgDisplayName: name } } },
|
|
);
|
|
}
|
|
} else {
|
|
let team = await Team.findOneAsync({ teamDisplayName: name });
|
|
if (!team) {
|
|
const teamId = await Team.insertAsync({
|
|
teamDisplayName: name,
|
|
teamShortName: name,
|
|
teamIsActive: true,
|
|
// #5850: the auth sync marks the teams it manages.
|
|
teamSyncMembersFromAuth: true,
|
|
});
|
|
team = { _id: teamId };
|
|
} else if (team.teamSyncMembersFromAuth !== true) {
|
|
await Team.updateAsync({ _id: team._id }, { $set: { teamSyncMembersFromAuth: true } });
|
|
}
|
|
const alreadyMember = (user.teams || []).some(t => t.teamId === team._id);
|
|
if (!alreadyMember) {
|
|
await Meteor.users.updateAsync(
|
|
{ _id: userId },
|
|
{ $push: { teams: { teamId: team._id, teamDisplayName: name } } },
|
|
);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
});
|