2016-10-28 01:47:40 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Breakouts from '/imports/api/breakouts';
|
2019-03-08 04:23:42 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-10-12 05:25:18 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-09-02 00:31:11 +08:00
|
|
|
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
|
2021-09-07 04:51:42 +08:00
|
|
|
import { publicationSafeGuard } from '/imports/api/common/server/helpers';
|
2016-10-28 01:47:40 +08:00
|
|
|
|
2019-06-29 04:52:19 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
|
2023-02-24 03:42:21 +08:00
|
|
|
async function breakouts() {
|
|
|
|
const tokenValidation = await AuthTokenValidation
|
|
|
|
.findOneAsync({ connectionId: this.connection.id });
|
2020-09-02 00:31:11 +08:00
|
|
|
|
|
|
|
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
|
|
|
|
Logger.warn(`Publishing Breakouts was requested by unauth connection ${this.connection.id}`);
|
2020-02-07 04:47:28 +08:00
|
|
|
return Breakouts.find({ meetingId: '' });
|
|
|
|
}
|
2020-09-02 00:31:11 +08:00
|
|
|
const { meetingId, userId } = tokenValidation;
|
2020-02-07 04:47:28 +08:00
|
|
|
|
2023-02-24 03:42:21 +08:00
|
|
|
const User = await Users.findOneAsync({ userId, meetingId }, { fields: { role: 1 } });
|
2020-11-24 23:13:09 +08:00
|
|
|
Logger.debug('Publishing Breakouts', { meetingId, userId });
|
2018-12-18 19:04:23 +08:00
|
|
|
|
2022-08-31 03:21:12 +08:00
|
|
|
const fields = {
|
|
|
|
fields: {
|
|
|
|
[`url_${userId}`]: 1,
|
|
|
|
breakoutId: 1,
|
|
|
|
externalId: 1,
|
|
|
|
freeJoin: 1,
|
|
|
|
isDefaultName: 1,
|
|
|
|
joinedUsers: 1,
|
|
|
|
name: 1,
|
|
|
|
parentMeetingId: 1,
|
|
|
|
sequence: 1,
|
|
|
|
shortName: 1,
|
|
|
|
timeRemaining: 1,
|
2022-10-19 19:36:25 +08:00
|
|
|
captureNotes: 1,
|
2022-11-23 04:07:43 +08:00
|
|
|
captureSlides: 1,
|
2022-08-31 03:21:12 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-05-21 05:07:36 +08:00
|
|
|
if (!!User && User.role === ROLE_MODERATOR) {
|
|
|
|
const presenterSelector = {
|
|
|
|
$or: [
|
|
|
|
{ parentMeetingId: meetingId },
|
|
|
|
{ breakoutId: meetingId },
|
|
|
|
],
|
|
|
|
};
|
2021-09-07 04:51:42 +08:00
|
|
|
// Monitor this publication and stop it when user is not a moderator anymore
|
2023-02-24 03:42:21 +08:00
|
|
|
const comparisonFunc = async () => {
|
|
|
|
const user = await Users.findOneAsync({ userId, meetingId }, { fields: { role: 1, userId: 1 } });
|
2021-09-07 04:51:42 +08:00
|
|
|
const condition = user.role === ROLE_MODERATOR;
|
2020-05-21 05:07:36 +08:00
|
|
|
|
2021-09-07 04:51:42 +08:00
|
|
|
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);
|
2022-08-31 03:21:12 +08:00
|
|
|
return Breakouts.find(presenterSelector, fields);
|
2018-11-22 00:27:01 +08:00
|
|
|
}
|
2017-10-12 05:25:18 +08:00
|
|
|
|
2018-06-07 05:24:09 +08:00
|
|
|
const selector = {
|
2018-07-07 01:07:08 +08:00
|
|
|
$or: [
|
|
|
|
{
|
|
|
|
parentMeetingId: meetingId,
|
|
|
|
freeJoin: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
parentMeetingId: meetingId,
|
2021-10-01 21:44:01 +08:00
|
|
|
[`url_${userId}`]: { $exists: true },
|
2018-07-07 01:07:08 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
breakoutId: meetingId,
|
|
|
|
},
|
2018-06-07 06:18:27 +08:00
|
|
|
],
|
2018-06-07 05:24:09 +08:00
|
|
|
};
|
|
|
|
|
2021-07-30 21:11:44 +08:00
|
|
|
return Breakouts.find(selector, fields);
|
2017-06-06 03:12:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundBreakouts = breakouts.bind(this);
|
2018-11-06 03:30:37 +08:00
|
|
|
return boundBreakouts(...args);
|
2017-06-06 03:12:06 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 03:07:02 +08:00
|
|
|
Meteor.publish('breakouts', publish);
|