2019-02-27 01:08:15 +08:00
|
|
|
import GuestUsers from '/imports/api/guest-users/';
|
2021-07-31 03:31:04 +08:00
|
|
|
import Users from '/imports/api/users';
|
2019-02-27 01:08:15 +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';
|
2019-02-27 01:08:15 +08:00
|
|
|
|
2021-07-31 03:31:04 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
|
2021-08-04 23:34:52 +08:00
|
|
|
function guestUsers(role) {
|
2020-09-02 00:31:11 +08:00
|
|
|
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
|
|
|
|
|
|
|
|
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
|
2021-07-31 03:31:04 +08:00
|
|
|
Logger.warn(`Publishing GuestUser was requested by unauth connection ${this.connection.id}`);
|
2020-02-07 04:47:28 +08:00
|
|
|
return GuestUsers.find({ meetingId: '' });
|
|
|
|
}
|
2019-02-27 01:08:15 +08:00
|
|
|
|
2020-09-02 00:31:11 +08:00
|
|
|
const { meetingId, userId } = tokenValidation;
|
2019-02-27 01:08:15 +08:00
|
|
|
|
2021-07-31 03:31:04 +08:00
|
|
|
const User = Users.findOne({ userId, meetingId }, { fields: { role: 1 } });
|
|
|
|
if (!User || User.role !== ROLE_MODERATOR) {
|
|
|
|
Logger.warn(
|
2021-08-04 23:34:52 +08:00
|
|
|
'Publishing GuestUser was requested by non-moderator connection',
|
2021-07-31 03:31:04 +08:00
|
|
|
{ meetingId, userId, connectionId: this.connection.id },
|
|
|
|
);
|
|
|
|
return GuestUsers.find({ meetingId: '' });
|
|
|
|
}
|
|
|
|
|
2020-09-02 00:31:11 +08:00
|
|
|
Logger.debug(`Publishing GuestUsers for ${meetingId} ${userId}`);
|
2019-02-27 01:08:15 +08:00
|
|
|
|
|
|
|
return GuestUsers.find({ meetingId });
|
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundSlides = guestUsers.bind(this);
|
|
|
|
return boundSlides(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('guestUser', publish);
|