2017-08-03 09:24:38 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 10:00:28 +08:00
|
|
|
import WhiteboardMultiUser from '/imports/api/whiteboard-multi-user/';
|
2020-08-18 01:03:23 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-08-03 09:24:38 +08:00
|
|
|
|
2018-04-10 07:18:49 +08:00
|
|
|
export default function modifyWhiteboardAccess(meetingId, whiteboardId, multiUser) {
|
2017-08-03 09:24:38 +08:00
|
|
|
check(meetingId, String);
|
2018-04-10 07:18:49 +08:00
|
|
|
check(whiteboardId, String);
|
|
|
|
check(multiUser, Boolean);
|
2017-08-03 09:24:38 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2018-04-10 07:18:49 +08:00
|
|
|
whiteboardId,
|
2017-08-03 09:24:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
2018-04-10 07:18:49 +08:00
|
|
|
meetingId,
|
|
|
|
whiteboardId,
|
|
|
|
multiUser,
|
2017-08-03 09:24:38 +08:00
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
2021-02-21 08:04:36 +08:00
|
|
|
if (!multiUser) {
|
|
|
|
const usersSelector = { meetingId };
|
|
|
|
|
|
|
|
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}`);
|
|
|
|
});
|
2017-08-03 09:24:38 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
const { insertedId } = WhiteboardMultiUser.upsert(selector, modifier);
|
2017-08-03 09:24:38 +08:00
|
|
|
if (insertedId) {
|
2020-11-23 21:13:46 +08:00
|
|
|
Logger.info(`Added multiUser flag=${multiUser} meetingId=${meetingId} whiteboardId=${whiteboardId}`);
|
|
|
|
} else {
|
|
|
|
Logger.info(`Upserted multiUser flag=${multiUser} meetingId=${meetingId} whiteboardId=${whiteboardId}`);
|
2017-08-03 09:24:38 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Error while adding an entry to Multi-User collection: ${err}`);
|
|
|
|
}
|
2017-08-03 09:24:38 +08:00
|
|
|
}
|