bigbluebutton-Github/bigbluebutton-html5/imports/startup/server/userPermissions.js

172 lines
4.4 KiB
JavaScript
Raw Normal View History

import Users from '/imports/api/2.0/users';
2017-06-19 19:57:32 +08:00
import Meetings from '/imports/api/1.1/meetings';
2016-05-05 02:29:43 +08:00
import { logger } from '/imports/startup/server/logger';
2016-04-29 05:10:43 +08:00
const presenter = {
2016-01-13 04:15:16 +08:00
switchSlide: true,
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// poll
2016-01-13 04:15:16 +08:00
subscribePoll: true,
subscribeAnswers: true,
2017-02-22 21:42:42 +08:00
2016-01-13 04:15:16 +08:00
};
2016-01-15 13:46:41 +08:00
// holds the values for whether the moderator user is allowed to perform an action (true)
// or false if not allowed. Some actions have dynamic values depending on the current lock settings
const moderator = {
2016-01-15 13:46:41 +08:00
// audio listen only
2016-01-13 04:15:16 +08:00
joinListenOnly: true,
leaveListenOnly: true,
2016-01-15 13:46:41 +08:00
// join audio with mic cannot be controlled on the server side as it is
// a client side only functionality
// raising/lowering hand
2016-01-13 04:15:16 +08:00
raiseOwnHand: true,
lowerOwnHand: true,
2016-01-15 13:46:41 +08:00
// muting
2016-01-13 04:15:16 +08:00
muteSelf: true,
unmuteSelf: true,
2017-02-02 03:14:32 +08:00
muteOther: true,
unmuteOther: true,
2016-01-15 13:46:41 +08:00
2016-01-13 04:15:16 +08:00
logoutSelf: true,
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// subscribing
2016-01-13 04:15:16 +08:00
subscribeUsers: true,
subscribeChat: true,
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// chat
2016-01-13 04:15:16 +08:00
chatPublic: true,
chatPrivate: true,
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// poll
2016-01-13 04:15:16 +08:00
subscribePoll: true,
subscribeAnswers: false,
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// emojis
2016-01-13 04:15:16 +08:00
setEmojiStatus: true,
clearEmojiStatus: true,
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// user control
2016-01-13 04:15:16 +08:00
kickUser: true,
setPresenter: true,
2017-06-03 03:25:02 +08:00
// captions
subscribeCaptions: true,
2016-01-13 04:15:16 +08:00
};
2016-01-15 13:46:41 +08:00
// holds the values for whether the viewer user is allowed to perform an action (true)
// or false if not allowed. Some actions have dynamic values depending on the current lock settings
const viewer = function (meetingId, userId) {
2016-06-28 02:24:37 +08:00
let meeting;
let user;
2016-01-13 04:15:16 +08:00
return {
2016-01-15 13:46:41 +08:00
// listen only
2016-01-13 04:15:16 +08:00
joinListenOnly: true,
leaveListenOnly: true,
2016-01-15 13:46:41 +08:00
// join audio with mic cannot be controlled on the server side as it is
// a client side only functionality
// raising/lowering hand
2016-01-13 04:15:16 +08:00
raiseOwnHand: true,
lowerOwnHand: true,
2016-01-15 13:46:41 +08:00
// muting
2016-01-13 04:15:16 +08:00
muteSelf: true,
2016-06-28 02:24:37 +08:00
unmuteSelf:
2017-02-02 03:27:25 +08:00
!((meeting = Meetings.findOne({ meetingId })) != null &&
2016-06-28 02:24:37 +08:00
meeting.roomLockSettings.disableMic) ||
2017-02-02 03:27:25 +08:00
!((user = Users.findOne({ meetingId, userId })) != null &&
2016-06-28 02:24:37 +08:00
user.user.locked),
2016-01-15 13:46:41 +08:00
2016-01-13 04:15:16 +08:00
logoutSelf: true,
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// subscribing
2016-01-13 04:15:16 +08:00
subscribeUsers: true,
subscribeChat: true,
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// chat
2017-02-02 03:27:25 +08:00
chatPublic: !((meeting = Meetings.findOne({ meetingId })) != null &&
2016-06-28 02:24:37 +08:00
meeting.roomLockSettings.disablePublicChat) ||
2017-02-02 03:27:25 +08:00
!((user = Users.findOne({ meetingId, userId })) != null &&
2016-06-28 02:24:37 +08:00
user.user.locked) ||
(user != null && user.user.presenter),
2017-02-02 03:27:25 +08:00
chatPrivate: !((meeting = Meetings.findOne({ meetingId })) != null &&
2016-06-28 02:24:37 +08:00
meeting.roomLockSettings.disablePrivateChat) ||
2017-02-02 03:27:25 +08:00
!((user = Users.findOne({ meetingId, userId })) != null &&
2016-06-28 02:24:37 +08:00
user.user.locked) ||
(user != null && user.user.presenter),
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// poll
2016-01-13 04:15:16 +08:00
subscribePoll: true,
subscribeAnswers: false,
2016-01-15 13:46:41 +08:00
2017-06-03 03:25:02 +08:00
// emojis
2016-01-13 04:15:16 +08:00
setEmojiStatus: true,
clearEmojiStatus: true,
2017-06-03 03:25:02 +08:00
// captions
subscribeCaptions: true,
2016-01-13 04:15:16 +08:00
};
};
2016-01-15 13:46:41 +08:00
// carries out the decision making for actions affecting users. For the list of
// actions and the default value - see 'viewer' and 'moderator' in the beginning of the file
2016-05-17 02:12:27 +08:00
export function isAllowedTo(action, credentials) {
const meetingId = credentials.meetingId;
const userId = credentials.requesterUserId;
const authToken = credentials.requesterToken;
const user = Users.findOne({
2017-02-02 03:27:25 +08:00
meetingId,
userId,
2016-01-30 09:33:40 +08:00
});
2017-02-02 03:27:25 +08:00
2017-05-17 23:54:48 +08:00
const allowedToInitiateRequest = user &&
2017-05-12 03:15:12 +08:00
user.authToken === authToken &&
user.validated &&
user.clientType === 'HTML5' &&
2017-05-12 03:15:12 +08:00
user.user &&
user.user.connection_status === 'online';
2017-05-19 22:25:24 +08:00
const listOfSafeActions = ['logoutSelf'];
2017-05-12 03:15:12 +08:00
const requestIsSafe = listOfSafeActions.includes(action);
if (requestIsSafe) {
logger.info(`permissions: requestIsSafe for ${action} by userId=${userId} allowed`);
return true;
}
if (allowedToInitiateRequest) {
let result = false;
// check role specific actions
if (user.user.role === 'MODERATOR') {
logger.debug('user permissions moderator case');
result = result || moderator[action];
} else if (user.user.role === 'VIEWER') {
logger.debug('user permissions viewer case');
result = result || viewer(meetingId, userId)[action];
}
// check presenter actions
if (user.user.presenter) {
logger.debug('user permissions presenter case');
result = result || presenter[action];
2016-01-13 04:15:16 +08:00
}
2016-02-02 02:38:15 +08:00
logger.debug(`attempt from userId=${userId} to perform:${action}, allowed=${result}`);
return result;
2016-01-13 04:15:16 +08:00
}
2017-06-03 03:25:02 +08:00
logger.error(`FAILED due to permissions:${action} ${JSON.stringify(credentials)}`);
return false;
}