bigbluebutton-Github/bigbluebutton-html5/imports/api/polls/server/publishers.js

36 lines
969 B
JavaScript
Raw Normal View History

2016-10-21 21:21:09 +08:00
import { Meteor } from 'meteor/meteor';
import { isAllowedTo } from '/imports/startup/server/userPermissions';
import Polls from '/imports/api/polls';
import { check } from 'meteor/check';
import { logger } from '/imports/startup/server/logger';
2017-03-14 06:33:06 +08:00
Meteor.publish('polls', function(credentials) {
2016-10-21 21:21:09 +08:00
//checking if it is allowed to see Poll Collection in general
if (!isAllowedTo('subscribePoll', credentials)) {
2017-03-14 06:33:06 +08:00
this.error(new Meteor.Error(402, "The user was not authorized to subscribe for 'polls'"));
2016-10-21 21:21:09 +08:00
}
const { meetingId, requesterUserId, requesterToken } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
const selector = {
meetingId: meetingId,
users: requesterUserId,
};
2016-11-25 03:22:04 +08:00
let options = {};
if (!isAllowedTo('subscribeAnswers', credentials)) {
options = {
2016-10-21 21:21:09 +08:00
fields: {
'poll.answers.num_votes': 0,
},
};
2016-10-21 21:21:09 +08:00
}
return Polls.find(selector, options);
2016-10-21 21:21:09 +08:00
});