bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/handlers/changeRole.js
2017-10-25 12:00:31 -07:00

28 lines
776 B
JavaScript

import { check } from 'meteor/check';
import Users from '/imports/api/users';
import changeRole from '/imports/api/users/server/modifiers/changeRole';
export default function handleChangeRole(payload, meetingId) {
const USER_CONFIG = Meteor.settings.public.user;
const ROLE_MODERATOR = USER_CONFIG.role_moderator;
const ROLE_VIEWER = USER_CONFIG.role_viewer;
check(payload.body, Object);
check(meetingId, String);
const { userId, role, changedBy } = payload.body;
const selector = {
meetingId,
userId,
};
const user = Users.findOne(selector);
if (role === ROLE_VIEWER && user.role === ROLE_MODERATOR) {
changeRole(ROLE_MODERATOR, false, userId, meetingId, changedBy);
}
return changeRole(role, true, userId, meetingId, changedBy);
}