bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/modifiers/changeRole.js
2017-10-25 10:29:03 -07:00

41 lines
950 B
JavaScript

import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function changeRole(role, status, userId, meetingId, changedBy) {
const selector = {
meetingId,
userId,
};
const action = status ? '$push' : '$pop';
const user = Users.findOne(selector);
const modifier = {
$set: {
role: (role === 'PRESENTER' ? user.role : role),
[role.toLowerCase()]: status,
},
[action]: {
roles: (role.toLowerCase()),
},
};
const cb = (err, numChanged) => {
const actionVerb = (status) ? 'Changed' : 'Removed';
if (err) {
return Logger.error(`Changed user role: ${err}`);
}
if (numChanged) {
return Logger.info(`${actionVerb} user role=${role} id=${userId} meeting=${meetingId}` +
`${changedBy === undefined ? '' : ` changedBy=${changedBy}`}`);
}
return null;
};
return Users.update(selector, modifier, cb);
}