2017-09-22 22:24:24 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2017-09-22 22:24:24 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-09-22 22:24:24 +08:00
|
|
|
|
|
|
|
export default function changeRole(credentials, userId, role) {
|
2018-01-08 08:24:05 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
2017-09-22 22:24:24 +08:00
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'ChangeUserRoleCmdMsg';
|
|
|
|
|
|
|
|
const { meetingId, requesterUserId } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(userId, String);
|
|
|
|
check(role, String);
|
|
|
|
|
|
|
|
const User = Users.findOne({
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!User) {
|
2018-01-08 08:25:56 +08:00
|
|
|
throw new Meteor.Error('user-not-found', `You need a valid user to be able to set '${role}'`);
|
2017-09-22 22:24:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
userId,
|
|
|
|
role,
|
|
|
|
changedBy: requesterUserId,
|
|
|
|
};
|
|
|
|
|
|
|
|
Logger.verbose(`User '${userId}' setted as '${role} role by '${requesterUserId}' from meeting '${meetingId}'`);
|
|
|
|
|
2017-10-06 21:31:56 +08:00
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
2017-09-22 22:24:24 +08:00
|
|
|
}
|