wekan/server/publications/users.js
Harry Adel 71eb01e233 Update ReactiveCache call sites to use async/await for Meteor 3.0
Part 3 of ReactiveCache async migration:
- Add await before all ReactiveCache.getX() calls
- Make functions containing ReactiveCache calls async
- Convert forEach/map/filter loops with async callbacks to for...of
- Update model helpers, Meteor methods, JsonRoutes handlers
- Update collection hooks (.before/.after insert/update/remove)
- Update .allow() callbacks to async

Files updated across models/ and server/ directories:
- Model files: cards, boards, lists, swimlanes, activities, users,
  checklists, checklistItems, customFields, attachments, integrations,
  cardComments, settings files, creators, exporters, and more
- Server files: publications, methods, notifications, routes, migrations
2026-02-01 00:54:38 +02:00

180 lines
5.4 KiB
JavaScript

Meteor.publish('user-miniprofile', async function (usernames) {
check(usernames, Array);
// eslint-disable-next-line no-console
// console.log('usernames:', usernames);
const ret = await ReactiveCache.getUsers(
{
$or: [
{ username: { $in: usernames } },
{ importUsernames: { $in: usernames } },
],
},
{
fields: {
...Users.safeFields,
importUsernames: 1,
},
},
true,
);
return ret;
});
Meteor.publish('user-admin', function () {
const ret = Meteor.users.find(this.userId, {
fields: {
isAdmin: 1,
teams: 1,
orgs: 1,
authenticationMethod: 1,
},
});
return ret;
});
Meteor.publish('user-authenticationMethod', async function (match) {
check(match, String);
const ret = await ReactiveCache.getUsers(
{ $or: [{ _id: match }, { email: match }, { username: match }] },
{
fields: {
authenticationMethod: 1,
teams: 1,
orgs: 1,
},
},
true,
);
return ret;
});
// Secure user search publication for board sharing
Meteor.publish('user-search', async function (searchTerm) {
check(searchTerm, String);
// Only allow logged-in users to search for other users
if (!this.userId) {
return this.ready();
}
// Create a regex for case-insensitive search
const searchRegex = new RegExp(searchTerm, 'i');
// Search for users by username, fullname, or email
const ret = await ReactiveCache.getUsers(
{
$or: [
{ username: searchRegex },
{ 'profile.fullname': searchRegex },
{ 'emails.address': searchRegex }
]
},
{
fields: {
_id: 1,
username: 1,
'profile.fullname': 1,
'profile.avatarUrl': 1,
'profile.initials': 1,
'emails.address': 1,
'emails.verified': 1,
authenticationMethod: 1,
isAdmin: 1,
loginDisabled: 1,
teams: 1,
orgs: 1,
},
},
true,
);
return ret;
});
// update last connection date and last connection average time (in seconds) for a user
// function UpdateLastConnectionDateAndLastConnectionAverageTime(lstUsers) {
// let lastConnectionAverageTime;
// lstUsers.forEach((currentUser) => {
// lastConnectionAverageTime =
// currentUser.lastConnectionAverageTimeInSecs !== undefined
// ? currentUser.lastConnectionAverageTimeInSecs
// : 0;
// lastConnectionAverageTime =
// currentUser.lastConnectionDate !== undefined
// ? ((new Date().getTime() - currentUser.lastConnectionDate.getTime()) /
// 1000 +
// lastConnectionAverageTime) /
// 2
// : 0;
// Users.update(currentUser._id, {
// $set: {
// lastConnectionDate: new Date(),
// lastConnectionAverageTimeInSecs: parseInt(lastConnectionAverageTime),
// },
// });
// });
// }
if (Meteor.isServer) {
/* Got this error, so using this code only when metrics enabled with process.env... below
I20221023-09:15:09.599(3)? Exception in onConnection callback: TypeError: Cannot read property 'userId' of null
I20221023-09:15:09.601(3)? at server/publications/users.js:106:44
I20221023-09:15:09.601(3)? at Array.forEach (<anonymous>)
I20221023-09:15:09.601(3)? at server/publications/users.js:102:46
I20221023-09:15:09.601(3)? at runWithEnvironment (packages/meteor.js:1347:24)
I20221023-09:15:09.601(3)? at packages/meteor.js:1360:14
I20221023-09:15:09.601(3)? at packages/ddp-server/livedata_server.js:1614:9
I20221023-09:15:09.601(3)? at Hook.forEach (packages/callback-hook/hook.js:110:15)
I20221023-09:15:09.601(3)? at Hook.each (packages/callback-hook/hook.js:122:17)
I20221023-09:15:09.602(3)? at Server._handleConnect (packages/ddp-server/livedata_server.js:1612:27)
I20221023-09:15:09.602(3)? at packages/ddp-server/livedata_server.js:1496:18
*/
if (process.env.WEKAN_METRICS_ACCEPTED_IP_ADDRESS) {
/*
Meteor.onConnection(function (connection) {
// console.log(
// 'Meteor.server.stream_server.open_sockets',
// Meteor.server.stream_server.open_sockets,
// );
//console.log('connection.Id on connection...', connection.id);
// connection.onClose(() => {
// console.log('connection.Id on close...', connection.id);
// // Get all user that were connected to this socket
// // And update last connection date and last connection average time (in seconds) for each user
// let lstOfUserThatWasConnectedToThisSocket = ReactiveCache.getUsers({
// lastconnectedSocketId: connection.id,
// }, {}, true).fetch();
// if (
// lstOfUserThatWasConnectedToThisSocket !== undefined &&
// lstOfUserThatWasConnectedToThisSocket.length > 0
// ) {
// console.log({ lstOfUserThatWasConnectedToThisSocket });
// UpdateLastConnectionDateAndLastConnectionAverageTime(
// lstOfUserThatWasConnectedToThisSocket,
// );
// }
// });
// Meteor.server.stream_server.open_sockets.forEach((socket) =>
// console.log('meteor session', socket._meteorSession.userId),
// );
// update last connected user date (needed for one of the KPI)
Meteor.server.stream_server.open_sockets.forEach(
(socket) => {
if (socket?._meteorSession?.userId) {
Users.update(socket._meteorSession.userId, {
$set: {
lastConnectionDate: new Date(),
},
});
}
});
});
*/
}
}