mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Which group kinds - Organizations, Teams, email Domains - Admin Panel / People / Shared templates allows came from the browser's localStorage, so it differed per browser and was empty for every user but the admin who ticked it. It is Settings.sharedTemplatesScopes now, published to every client, and an admin's earlier ticks are carried over once. The All Boards / Templates targets were empty for everyone anyway: getMyShareableGroups did not await ReactiveCache.getUser, so it read orgs, teams and emails from a Promise. Thanks to xet7 !
68 lines
2.2 KiB
JavaScript
68 lines
2.2 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import Org from '/models/org';
|
|
import Team from '/models/team';
|
|
|
|
// #5850: drag-to-share drop targets. The org/team publications are admin-only,
|
|
// so a non-admin member cannot read the per-org/team `orgSharedTemplates` /
|
|
// `teamSharedTemplates` flag client-side. This method returns just the user's
|
|
// own orgs/teams that have the flag set (plus their email domains, which have
|
|
// no per-record flag), so boardsList.js can gate the drop targets on it.
|
|
Meteor.methods({
|
|
async getMyShareableGroups() {
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('not-logged-in');
|
|
}
|
|
|
|
// Awaited: on the server ReactiveCache.getUser returns a Promise, and the
|
|
// Promise has no orgs, teams or emails - every list came back empty.
|
|
const user = await ReactiveCache.getUser(this.userId);
|
|
const result = { orgs: [], teams: [], domains: [] };
|
|
if (!user) {
|
|
return result;
|
|
}
|
|
|
|
const orgIds = (user.orgs || []).map(o => o.orgId).filter(Boolean);
|
|
const teamIds = (user.teams || []).map(t => t.teamId).filter(Boolean);
|
|
|
|
if (orgIds.length) {
|
|
const orgs = await Org.find(
|
|
{ _id: { $in: orgIds }, orgSharedTemplates: true },
|
|
{ fields: { orgDisplayName: 1 } },
|
|
).fetchAsync();
|
|
result.orgs = orgs.map(o => ({
|
|
type: 'org',
|
|
id: o._id,
|
|
name: o.orgDisplayName,
|
|
}));
|
|
}
|
|
|
|
if (teamIds.length) {
|
|
const teams = await Team.find(
|
|
{ _id: { $in: teamIds }, teamSharedTemplates: true },
|
|
{ fields: { teamDisplayName: 1 } },
|
|
).fetchAsync();
|
|
result.teams = teams.map(t => ({
|
|
type: 'team',
|
|
id: t._id,
|
|
name: t.teamDisplayName,
|
|
}));
|
|
}
|
|
|
|
// Domains have no per-record flag; include the user's email domains.
|
|
const domains = [];
|
|
(user.emails || []).forEach((email) => {
|
|
const addr = (email && email.address) || '';
|
|
const at = addr.lastIndexOf('@');
|
|
if (at !== -1) {
|
|
const domain = addr.slice(at + 1).toLowerCase().trim();
|
|
if (domain && !domains.includes(domain)) {
|
|
domains.push(domain);
|
|
}
|
|
}
|
|
});
|
|
result.domains = domains.map(d => ({ type: 'domain', id: d, name: d }));
|
|
|
|
return result;
|
|
},
|
|
});
|