bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/publishers.js

71 lines
2.1 KiB
JavaScript
Raw Normal View History

import Users from '/imports/api/users';
import { Meteor } from 'meteor/meteor';
import Logger from '/imports/startup/server/logger';
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
2023-11-30 22:20:12 +08:00
import { publicationSafeGuard } from '/imports/api/common/server/helpers';
2017-03-11 02:33:46 +08:00
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
async function users() {
const tokenValidation = await AuthTokenValidation
.findOneAsync({ 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: '' });
}
if (!this.userId) {
return Users.find({ meetingId: '' });
}
const { meetingId, userId } = tokenValidation;
Logger.debug(`Publishing Users for ${meetingId} ${userId}`);
2017-02-07 23:29:27 +08:00
const selector = {
$or: [
{ meetingId },
],
intId: { $exists: true },
2022-01-07 05:07:22 +08:00
left: false,
};
const User = await Users.findOneAsync({ userId, meetingId }, { fields: { role: 1 } });
if (!!User && User.role === ROLE_MODERATOR) {
selector.$or.push({
'breakoutProps.isBreakoutUser': true,
'breakoutProps.parentId': meetingId,
});
// Monitor this publication and stop it when user is not a moderator anymore
const comparisonFunc = async () => {
const user = await Users.findOneAsync({ userId, meetingId },
{ fields: { role: 1, userId: 1 } });
const condition = user.role === ROLE_MODERATOR;
if (!condition) {
Logger.info(`conditions aren't filled anymore in publication ${this._name}:
user.role === ROLE_MODERATOR :${condition}, user.role: ${user.role} ROLE_MODERATOR: ${ROLE_MODERATOR}`);
}
return condition;
};
publicationSafeGuard(comparisonFunc, this);
}
const options = {
fields: {
authToken: false,
},
};
2020-11-24 23:13:09 +08:00
Logger.debug('Publishing Users', { meetingId, userId });
return Users.find(selector, options);
}
2017-06-06 03:12:06 +08:00
function publish(...args) {
const boundUsers = users.bind(this);
return boundUsers(...args);
2017-06-06 03:12:06 +08:00
}
Meteor.publish('users', publish);