2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-02-06 23:56:09 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-09-02 00:31:11 +08:00
|
|
|
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2021-03-17 00:15:41 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-03-11 02:33:46 +08:00
|
|
|
|
2019-06-29 04:52:19 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
|
2020-02-14 03:19:29 +08:00
|
|
|
function currentUser() {
|
2020-02-07 04:47:28 +08:00
|
|
|
if (!this.userId) {
|
2021-10-05 04:01:20 +08:00
|
|
|
Mongo.Collection._publishCursor(Users.find({ meetingId: '' }), this, 'current-user');
|
|
|
|
return this.ready();
|
2020-02-07 04:47:28 +08:00
|
|
|
}
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2017-02-06 23:56:09 +08:00
|
|
|
|
2020-02-14 03:19:29 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId: requesterUserId,
|
2021-03-17 00:15:41 +08:00
|
|
|
intId: { $exists: true },
|
2017-03-11 02:33:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
fields: {
|
|
|
|
user: false,
|
2020-02-07 04:47:28 +08:00
|
|
|
authToken: false, // Not asking for authToken from client side but also not exposing it
|
2017-03-11 02:33:46 +08:00
|
|
|
},
|
|
|
|
};
|
2021-10-05 04:01:20 +08:00
|
|
|
Mongo.Collection._publishCursor(Users.find(selector, options), this, 'current-user');
|
|
|
|
return this.ready();
|
2020-02-14 03:19:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publishCurrentUser(...args) {
|
|
|
|
const boundUsers = currentUser.bind(this);
|
|
|
|
return boundUsers(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('current-user', publishCurrentUser);
|
2017-03-11 02:33:46 +08:00
|
|
|
|
2021-10-05 04:01:20 +08:00
|
|
|
function users() {
|
2020-09-02 00:31:11 +08:00
|
|
|
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
|
|
|
|
|
|
|
|
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
|
|
|
|
Logger.warn(`Publishing Users was requested by unauth connection ${this.connection.id}`);
|
|
|
|
return Users.find({ meetingId: '' });
|
|
|
|
}
|
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
if (!this.userId) {
|
|
|
|
return Users.find({ meetingId: '' });
|
|
|
|
}
|
2020-09-02 00:31:11 +08:00
|
|
|
const { meetingId, userId } = tokenValidation;
|
|
|
|
|
|
|
|
Logger.debug(`Publishing Users for ${meetingId} ${userId}`);
|
2017-02-07 23:29:27 +08:00
|
|
|
|
2017-02-06 23:56:09 +08:00
|
|
|
const selector = {
|
2019-02-08 00:42:47 +08:00
|
|
|
$or: [
|
|
|
|
{ meetingId },
|
|
|
|
],
|
2021-03-17 00:15:41 +08:00
|
|
|
intId: { $exists: true },
|
2017-02-06 23:56:09 +08:00
|
|
|
};
|
|
|
|
|
2020-09-02 00:31:11 +08:00
|
|
|
const User = Users.findOne({ userId, meetingId }, { fields: { role: 1 } });
|
2020-05-21 05:07:36 +08:00
|
|
|
if (!!User && User.role === ROLE_MODERATOR) {
|
|
|
|
selector.$or.push({
|
|
|
|
'breakoutProps.isBreakoutUser': true,
|
|
|
|
'breakoutProps.parentId': meetingId,
|
|
|
|
});
|
2019-02-08 03:40:27 +08:00
|
|
|
}
|
|
|
|
|
2017-02-06 23:56:09 +08:00
|
|
|
const options = {
|
|
|
|
fields: {
|
|
|
|
authToken: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-24 23:13:09 +08:00
|
|
|
Logger.debug('Publishing Users', { meetingId, userId });
|
2017-02-06 23:56:09 +08:00
|
|
|
|
|
|
|
return Users.find(selector, options);
|
2017-06-01 21:12:11 +08:00
|
|
|
}
|
2017-06-06 03:12:06 +08:00
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundUsers = users.bind(this);
|
2018-11-06 03:30:37 +08:00
|
|
|
return boundUsers(...args);
|
2017-06-06 03:12:06 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 03:07:02 +08:00
|
|
|
Meteor.publish('users', publish);
|