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

44 lines
1.0 KiB
JavaScript
Raw Normal View History

import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
2017-10-26 01:29:03 +08:00
export default function changeRole(role, status, userId, meetingId, changedBy) {
2017-10-26 03:00:31 +08:00
const USER_CONFIG = Meteor.settings.public.user;
const ROLE_PRESENTER = USER_CONFIG.role_presenter;
const selector = {
meetingId,
userId,
};
2017-10-26 01:29:03 +08:00
const action = status ? '$push' : '$pop';
const user = Users.findOne(selector);
const modifier = {
$set: {
2017-10-26 03:00:31 +08:00
role: (role === ROLE_PRESENTER ? user.role : role),
2017-10-26 01:29:03 +08:00
[role.toLowerCase()]: status,
2017-10-07 01:52:14 +08:00
},
2017-10-26 01:29:03 +08:00
[action]: {
roles: (role.toLowerCase()),
},
};
const cb = (err, numChanged) => {
2017-10-26 01:29:03 +08:00
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 ? ` changedBy=${changedBy}` : ''}`);
}
2017-10-07 01:56:56 +08:00
return null;
};
return Users.update(selector, modifier, cb);
}