Exemple #1
0
    def get_all(self,
                story_id=None,
                marker=None,
                limit=None,
                sort_field='id',
                sort_dir='asc'):
        """Retrieve all comments posted under specified story.

        Example::

          curl https://my.example.org/api/v1/stories/11/comments

        :param story_id: Filter comments by story ID.
        :param marker: The resource id where the page should begin.
        :param limit: The number of comments to retrieve.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).
        """
        current_user = request.current_user_id

        # Boundary check on limit.
        if limit is not None:
            limit = max(0, limit)

        # Resolve the marker record.
        marker_event = None
        if marker:
            event_query = \
                events_api.events_get_all(comment_id=marker,
                                          event_type=event_types.USER_COMMENT,
                                          current_user=current_user)
            if len(event_query) > 0:
                marker_event = event_query[0]

        events_count = events_api.events_get_count(
            story_id=story_id,
            event_type=event_types.USER_COMMENT,
            current_user=current_user)

        events = events_api.events_get_all(story_id=story_id,
                                           marker=marker_event,
                                           limit=limit,
                                           event_type=event_types.USER_COMMENT,
                                           sort_field=sort_field,
                                           sort_dir=sort_dir,
                                           current_user=current_user)

        comments = [
            comments_api.comment_get(event.comment_id) for event in events
        ]

        # Apply the query response headers.
        if limit:
            response.headers['X-Limit'] = str(limit)
        response.headers['X-Total'] = str(events_count)
        if marker_event:
            response.headers['X-Marker'] = str(marker)

        return [wmodels.Comment.from_db_model(comment) for comment in comments]
Exemple #2
0
    def resolve_event_values(event):
        if event.comment_id:
            comment = comments_api.comment_get(event.comment_id)
            event.comment = Comment.from_db_model(comment)

        event = TimeLineEvent._resolve_info(event)

        return event
    def resolve_event_values(event):
        if event.comment_id:
            comment = comments_api.comment_get(event.comment_id)
            event.comment = Comment.from_db_model(comment)

        event = TimeLineEvent._resolve_info(event)

        return event
Exemple #4
0
    def put(self, story_id, comment_id, comment_body):
        """Update an existing comment.

        :param story_id: A placeholder.
        :param comment_id: The id of a Comment to be updated.
        :param comment_body: An updated Comment.
        """

        comments_api.comment_get(comment_id)
        comment_author_id = events_api.events_get_all(
            comment_id=comment_id)[0].author_id
        if request.current_user_id != comment_author_id:
            abort(403, _("You are not allowed to update this comment."))

        updated_comment = comments_api.comment_update(
            comment_id, comment_body.as_dict(omit_unset=True))

        return wmodels.Comment.from_db_model(updated_comment)
Exemple #5
0
    def put(self, story_id, comment_id, comment_body):
        """Update an existing comment.

        :param story_id: A placeholder.
        :param comment_id: The id of a Comment to be updated.
        :param comment_body: An updated Comment.
        """

        comments_api.comment_get(comment_id)
        comment_author_id = events_api.events_get_all(
            comment_id=comment_id)[0].author_id
        if request.current_user_id != comment_author_id:
            abort(403, _("You are not allowed to update this comment."))

        updated_comment = comments_api.comment_update(comment_id,
                                                      comment_body.as_dict(
                                                          omit_unset=True
                                                      ))

        return wmodels.Comment.from_db_model(updated_comment)
    def get_all(self, story_id=None, marker=None, limit=None, sort_field='id',
                sort_dir='asc'):
        """Retrieve all comments posted under specified story.

        Example::

          curl https://my.example.org/api/v1/stories/11/comments

        :param story_id: Filter comments by story ID.
        :param marker: The resource id where the page should begin.
        :param limit: The number of comments to retrieve.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).
        """
        current_user = request.current_user_id

        # Boundary check on limit.
        if limit is not None:
            limit = max(0, limit)

        # Resolve the marker record.
        marker_event = None
        if marker:
            event_query = \
                events_api.events_get_all(comment_id=marker,
                                          event_type=event_types.USER_COMMENT,
                                          current_user=current_user)
            if len(event_query) > 0:
                marker_event = event_query[0]

        events_count = events_api.events_get_count(
            story_id=story_id,
            event_type=event_types.USER_COMMENT,
            current_user=current_user)

        events = events_api.events_get_all(story_id=story_id,
                                           marker=marker_event,
                                           limit=limit,
                                           event_type=event_types.USER_COMMENT,
                                           sort_field=sort_field,
                                           sort_dir=sort_dir,
                                           current_user=current_user)

        comments = [comments_api.comment_get(event.comment_id)
                    for event in events]

        # Apply the query response headers.
        if limit:
            response.headers['X-Limit'] = str(limit)
        response.headers['X-Total'] = str(events_count)
        if marker_event:
            response.headers['X-Marker'] = str(marker)

        return [wmodels.Comment.from_db_model(comment) for comment in comments]
Exemple #7
0
    def delete(self, story_id, comment_id):
        """Update an existing comment.

        :param story_id: A placeholder.
        :param comment_id: The id of a Comment to be updated.
        """

        comment = comments_api.comment_get(comment_id)

        if request.current_user_id != comment.author_id:
            abort(403, _("You are not allowed to delete this comment."))

        comments_api.comment_delete(comment_id)
Exemple #8
0
    def delete(self, story_id, comment_id):
        """Update an existing comment.

        :param story_id: A placeholder.
        :param comment_id: The id of a Comment to be updated.
        """

        comment = comments_api.comment_get(comment_id)

        if request.current_user_id != comment.author_id:
            abort(403, _("You are not allowed to delete this comment."))

        comments_api.comment_delete(comment_id)
    def put(self, story_id, comment_id, comment_body):
        """Update an existing comment. This command is disabled by default.

        :param story_id: A placeholder.
        :param comment_id: The id of a Comment to be updated.
        :param comment_body: An updated Comment.
        """
        if not CONF.enable_editable_comments:
            abort(405, _("Editing of comments is disabled "
                         "by the server administrator."))

        comments_api.comment_get(comment_id)
        comment_author_id = events_api.events_get_all(
            comment_id=comment_id)[0].author_id
        if request.current_user_id != comment_author_id:
            abort(403, _("You are not allowed to update this comment."))

        updated_comment = comments_api.comment_update(comment_id,
                                                      comment_body.as_dict(
                                                          omit_unset=True
                                                      ))

        return wmodels.Comment.from_db_model(updated_comment)
Exemple #10
0
    def put(self, story_id, comment_id, comment_body):
        """Update an existing comment. This command is disabled by default.

        :param story_id: A placeholder.
        :param comment_id: The id of a Comment to be updated.
        :param comment_body: An updated Comment.
        """
        if not CONF.enable_editable_comments:
            abort(
                405,
                _("Editing of comments is disabled "
                  "by the server administrator."))

        comments_api.comment_get(comment_id)
        comment_author_id = events_api.events_get_all(
            comment_id=comment_id)[0].author_id
        if request.current_user_id != comment_author_id:
            abort(403, _("You are not allowed to update this comment."))

        updated_comment = comments_api.comment_update(
            comment_id, comment_body.as_dict(omit_unset=True))

        return wmodels.Comment.from_db_model(updated_comment)
Exemple #11
0
    def get_one(self, story_id, comment_id):
        """Retrieve details about one comment.

        :param story_id: An ID of the story. It stays in params as a
                         placeholder so that pecan knows where to match an
                         incoming value. It will stay unused, as far as
                         comments have their own unique ids.
        :param comment_id: An ID of the comment.
        """

        comment = comments_api.comment_get(comment_id)

        if comment:
            return wmodels.Comment.from_db_model(comment)
        else:
            raise exc.NotFound(_("Comment %s not found") % comment_id)
Exemple #12
0
    def get_one(self, story_id, comment_id):
        """Retrieve details about one comment.

        :param story_id: An ID of the story. It stays in params as a
                         placeholder so that pecan knows where to match an
                         incoming value. It will stay unused, as far as
                         comments have their own unique ids.
        :param comment_id: An ID of the comment.
        """

        comment = comments_api.comment_get(comment_id)

        if comment:
            return wmodels.Comment.from_db_model(comment)
        else:
            raise exc.NotFound(_("Comment %s not found") % comment_id)
    def get(self, story_id, comment_id):
        """Return any historical versions of this comment.

        :param story_id: The ID of the story.
        :param comment_id: The ID of the comment to inspect history of.
        """
        comment = comments_api.comment_get(comment_id)
        if comment is None:
            raise exc.NotFound(_("Comment %s not found") % comment_id)

        # Check that the user can actually see the relevant story
        story = stories_api.story_get_simple(
            comment.event[0].story_id, current_user=request.current_user_id)
        if story is None:
            raise exc.NotFound(_("Comment %s not found") % comment_id)

        return [wmodels.Comment.from_db_model(old_comment)
                for old_comment in comment.history]
def resolve_comments(event):
    event_info = {
        'comment_id': event.comment_id or None,
    }

    # Retrieve the content of the comment.
    comment = comments_api.comment_get(event.comment_id)
    event_info['comment_content'] = comment.content

    # Retrieve the story ID of the comment.
    timeline_events = timeline_api.events_get_all(comment_id=event.comment_id)
    if timeline_events:
        story = story_api.story_get(timeline_events[0].story_id)

        if story:
            event_info['story_id'] = story.id
            event_info['story_title'] = story.title

    return json.dumps(event_info)
Exemple #15
0
    def get(self, story_id, comment_id):
        """Return any historical versions of this comment.

        :param story_id: The ID of the story.
        :param comment_id: The ID of the comment to inspect history of.
        """
        comment = comments_api.comment_get(comment_id)
        if comment is None:
            raise exc.NotFound(_("Comment %s not found") % comment_id)

        # Check that the user can actually see the relevant story
        story = stories_api.story_get_simple(
            comment.event[0].story_id, current_user=request.current_user_id)
        if story is None:
            raise exc.NotFound(_("Comment %s not found") % comment_id)

        return [
            wmodels.Comment.from_db_model(old_comment)
            for old_comment in comment.history
        ]
Exemple #16
0
    def get_one(self, story_id, comment_id):
        """Retrieve details about one comment.

        Example::

          curl https://my.example.org/api/v1/stories/11/comments/6834

        :param story_id: An ID of the story. It stays in params as a
                         placeholder so that pecan knows where to match an
                         incoming value. It will stay unused, as far as
                         comments have their own unique ids.
        :param comment_id: An ID of the comment.
        """
        comment = comments_api.comment_get(comment_id)
        if comment is None:
            raise exc.NotFound(_("Comment %s not found") % comment_id)

        # Check that the user can actually see the relevant story
        story = stories_api.story_get_simple(
            comment.event[0].story_id, current_user=request.current_user_id)
        if story is None:
            raise exc.NotFound(_("Comment %s not found") % comment_id)

        return wmodels.Comment.from_db_model(comment)
    def get_one(self, story_id, comment_id):
        """Retrieve details about one comment.

        Example::

          curl https://my.example.org/api/v1/stories/11/comments/6834

        :param story_id: An ID of the story. It stays in params as a
                         placeholder so that pecan knows where to match an
                         incoming value. It will stay unused, as far as
                         comments have their own unique ids.
        :param comment_id: An ID of the comment.
        """
        comment = comments_api.comment_get(comment_id)
        if comment is None:
            raise exc.NotFound(_("Comment %s not found") % comment_id)

        # Check that the user can actually see the relevant story
        story = stories_api.story_get_simple(
            comment.event[0].story_id, current_user=request.current_user_id)
        if story is None:
            raise exc.NotFound(_("Comment %s not found") % comment_id)

        return wmodels.Comment.from_db_model(comment)