Ejemplo n.º 1
0
    def accept_comment(self, comment_id, moderator=False):
        """Accept a comment that is pending moderation.

        This raises :class:`~sphinxcontrib.websupport.errors.UserNotAuthorizedError`
        if moderator is False.

        :param comment_id: The id of the comment that was accepted.
        :param moderator: Whether the user making the request is a moderator.
        """
        if not moderator:
            raise errors.UserNotAuthorizedError()
        self.storage.accept_comment(comment_id)
Ejemplo n.º 2
0
    def add_comment(self,
                    text,
                    node_id='',
                    parent_id='',
                    displayed=True,
                    username=None,
                    time=None,
                    proposal=None,
                    moderator=False):
        """Add a comment to a node or another comment. Returns the comment
        in the same format as :meth:`get_comments`. If the comment is being
        attached to a node, pass in the node's id (as a string) with the
        node keyword argument::

            comment = support.add_comment(text, node_id=node_id)

        If the comment is the child of another comment, provide the parent's
        id (as a string) with the parent keyword argument::

            comment = support.add_comment(text, parent_id=parent_id)

        If you would like to store a username with the comment, pass
        in the optional `username` keyword argument::

            comment = support.add_comment(text, node=node_id,
                                          username=username)

        :param parent_id: the prefixed id of the comment's parent.
        :param text: the text of the comment.
        :param displayed: for moderation purposes
        :param username: the username of the user making the comment.
        :param time: the time the comment was created, defaults to now.
        """
        if username is None:
            if self.allow_anonymous_comments:
                username = '******'
            else:
                raise errors.UserNotAuthorizedError()
        parsed = self._parse_comment_text(text)
        comment = self.storage.add_comment(parsed, displayed, username, time,
                                           proposal, node_id, parent_id,
                                           moderator)
        comment['original_text'] = text
        if not displayed and self.moderation_callback:
            self.moderation_callback(comment)
        return comment