bigbluebutton-Github/bigbluebutton-html5/imports/api/polls/server/publications.js
2016-06-15 14:04:25 -07:00

34 lines
1.2 KiB
JavaScript
Executable File

import { isAllowedTo } from '/imports/startup/server/userPermissions';
import Polls from '/imports/api/polls';
import { logger } from '/imports/startup/server/logger';
Meteor.publish('polls', function (credentials) {
const { meetingId, requesterUserId, requesterToken } = credentials;
//checking if it is allowed to see Poll Collection in general
if (isAllowedTo('subscribePoll', credentials)) {
//checking if it is allowed to see a number of votes (presenter only)
if (isAllowedTo('subscribeAnswers', credentials)) {
logger.info('publishing Poll for presenter: ' + meetingId + ' ' + requesterUserId + ' ' +
requesterToken);
return Polls.find({
meetingId: meetingId,
users: requesterUserId,
});
} else {
logger.info('publishing Poll for viewer: ' + meetingId + ' ' + requesterUserId + ' ' +
requesterToken);
return Polls.find({
meetingId: meetingId,
users: requesterUserId,
}, {
fields: {
'poll.answers.num_votes': 0,
},
});
}
} else {
this.error(new Meteor.Error(402, "The user was not authorized to subscribe for 'polls'"));
}
});