bigbluebutton-Github/bigbluebutton-html5/imports/api/whiteboard-multi-user/server/modifiers/modifyWhiteboardAccess.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import WhiteboardMultiUser from '/imports/api/whiteboard-multi-user/';
import Users from '/imports/api/users';
2018-04-10 07:18:49 +08:00
export default function modifyWhiteboardAccess(meetingId, whiteboardId, multiUser) {
check(meetingId, String);
2018-04-10 07:18:49 +08:00
check(whiteboardId, String);
check(multiUser, Boolean);
if (!multiUser) {
const usersSelector = { meetingId, presenter: { $ne: true } };
const mod = {
$set: {
whiteboardAccess: false,
},
};
Users.update(usersSelector, mod, { multi: true }, (err) => {
if (err) {
return Logger.error(`Error removing whiteboard access, User collection: ${err}`);
}
return Logger.info(`updated Users whiteboardAccess flag=${false} meetingId=${meetingId} whiteboardId=${whiteboardId}`);
});
}
const selector = {
meetingId,
2018-04-10 07:18:49 +08:00
whiteboardId,
};
const modifier = {
2018-04-10 07:18:49 +08:00
meetingId,
whiteboardId,
multiUser,
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Error while adding an entry to Multi-User collection: ${err}`);
}
const { insertedId } = numChanged;
if (insertedId) {
return Logger.info(`Added multiUser flag=${multiUser} meetingId=${meetingId} whiteboardId=${whiteboardId}`);
}
return Logger.info(`Upserted multiUser flag=${multiUser} meetingId=${meetingId} whiteboardId=${whiteboardId}`);
};
return WhiteboardMultiUser.upsert(selector, modifier, cb);
}