bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/handlers/changeRole.js

28 lines
776 B
JavaScript
Raw Normal View History

2017-10-07 02:12:33 +08:00
import { check } from 'meteor/check';
2017-10-26 03:00:31 +08:00
import Users from '/imports/api/users';
2017-10-26 01:29:03 +08:00
import changeRole from '/imports/api/users/server/modifiers/changeRole';
2017-10-10 23:05:16 +08:00
export default function handleChangeRole(payload, meetingId) {
2017-10-26 03:00:31 +08:00
const USER_CONFIG = Meteor.settings.public.user;
const ROLE_MODERATOR = USER_CONFIG.role_moderator;
const ROLE_VIEWER = USER_CONFIG.role_viewer;
2017-10-10 23:05:16 +08:00
check(payload.body, Object);
2017-10-07 02:12:33 +08:00
check(meetingId, String);
2017-10-26 01:29:03 +08:00
const { userId, role, changedBy } = payload.body;
2017-10-26 03:00:31 +08:00
const selector = {
meetingId,
userId,
};
const user = Users.findOne(selector);
if (role === ROLE_VIEWER && user.role === ROLE_MODERATOR) {
changeRole(ROLE_MODERATOR, false, userId, meetingId, changedBy);
}
2017-10-26 01:29:03 +08:00
return changeRole(role, true, userId, meetingId, changedBy);
}