示例#1
0
 def flagAbuse(self, user, voteable):
     if voteable.type == 'thread':
         url = _url_for_flag_abuse_thread(voteable.id)
     elif voteable.type == 'comment':
         url = _url_for_flag_comment(voteable.id)
     else:
         raise utils.CommentClientRequestError(
             "Can only flag/unflag threads or comments")
     params = {'user_id': user.id}
     response = utils.perform_request('put',
                                      url,
                                      params,
                                      metric_action='thread.abuse.flagged',
                                      metric_tags=self._metric_tags)
     voteable._update_from_response(response)
示例#2
0
 def active_threads(self, query_params={}):
     if not self.course_id:
         raise utils.CommentClientRequestError("Must provide course_id when retrieving active threads for the user")
     url = _url_for_user_active_threads(self.id)
     params = {'course_id': text_type(self.course_id)}
     params.update(query_params)
     response = utils.perform_request(
         'get',
         url,
         params,
         metric_action='user.active_threads',
         metric_tags=self._metric_tags,
         paged_results=True,
     )
     return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1)
示例#3
0
 def unvote(self, voteable):
     if voteable.type == 'thread':
         url = _url_for_vote_thread(voteable.id)
     elif voteable.type == 'comment':
         url = _url_for_vote_comment(voteable.id)
     else:
         raise utils.CommentClientRequestError("Can only vote / unvote for threads or comments")
     params = {'user_id': self.id}
     response = utils.perform_request(
         'delete',
         url,
         params,
         metric_action='user.unvote',
         metric_tags=self._metric_tags + ['target.type:{}'.format(voteable.type)],
     )
     voteable._update_from_response(response)
示例#4
0
    def unFlagAbuse(self, user, voteable, removeAll):
        if voteable.type == 'thread':
            url = _url_for_unflag_abuse_thread(voteable.id)
        elif voteable.type == 'comment':
            url = _url_for_unflag_comment(voteable.id)
        else:
            raise utils.CommentClientRequestError(
                "Can only flag/unflag for threads or comments")
        params = {'user_id': user.id}
        #if you're an admin, when you unflag, remove ALL flags
        if removeAll:
            params['all'] = True

        response = utils.perform_request(
            'put',
            url,
            params,
            metric_tags=self._metric_tags,
            metric_action='thread.abuse.unflagged')
        voteable._update_from_response(response)
示例#5
0
 def subscribed_threads(self, query_params={}):
     if not self.course_id:
         raise utils.CommentClientRequestError(
             "Must provide course_id when retrieving subscribed threads for the user"
         )
     url = _url_for_user_subscribed_threads(self.id)
     params = {'course_id': text_type(self.course_id)}
     params.update(query_params)
     response = utils.perform_request(
         'get',
         url,
         params,
         metric_action='user.subscribed_threads',
         metric_tags=self._metric_tags,
         paged_results=True)
     return utils.CommentClientPaginatedResult(
         collection=response.get('collection', []),
         page=response.get('page', 1),
         num_pages=response.get('num_pages', 1),
         thread_count=response.get('thread_count', 0))