Ejemplo n.º 1
0
    def get(self, post_id, jwt_payload=None):
        """Get info on a specific post.

        Args:
            post_id: UUID of the post to lookup.
        """
        if not validate_uuid(post_id):
            return Fail("invalid post ID").to_json(), 400
        LOGGER.debug({"Requested Post": post_id})
        post = Post.get_post(post_id)
        if post is not None:
            return Success({"post": post.to_json()}).to_json(), 200
        return Fail(f"post with ID {post_id} not found").to_json(), 404
Ejemplo n.º 2
0
    def delete(self, reply_id):
        """Delete a specific reply from the database.

        Args:
            reply_id: UUID of the reply to delete.
        """
        if not validate_uuid(reply_id):
            return Fail("invalid reply ID").to_json(), 400
        reply = Reply.get_reply(reply_id)
        if reply is not None:
            reply.delete()
            return Success(None).to_json(), 204
        return Fail(f"Reply ID {reply_id} does not exist").to_json(), 404
Ejemplo n.º 3
0
    def get(self, reply_id, jwt_payload=None):
        """Get info on a specific reply.

        Args:
            reply_id: UUID of the post to lookup.
        """
        if not validate_uuid(reply_id):
            return Fail("invalid reply ID").to_json(), 400
        LOGGER.debug({"Requested reply": reply_id})
        reply = Reply.get_reply(reply_id)
        if reply is not None:
            return Success({"reply": reply.to_json()}).to_json(), 200
        return Fail(f"post with ID {reply_id} not found").to_json(), 404
Ejemplo n.º 4
0
    def delete(self, post_id):
        """Delete a specific post from the database.

        Args:
            post_id: UUID of the post to delete.
        """
        if not validate_uuid(post_id):
            return Fail("invalid post ID").to_json(), 400
        post = Post.get_post(post_id)
        if post is not None:
            post.delete()
            return Success(None).to_json(), 204
        return Fail(f"Post ID {post_id} does not exist").to_json(), 404
Ejemplo n.º 5
0
    def put(self, reply_id):
        """Update info for a specific reply.

        Args:
            reply_id: UUID of the reply to update.
        """
        if not validate_uuid(reply_id):
            return Fail("invalid reply ID").to_json(), 400

        reply = Reply.get_reply(reply_id)
        if reply is not None:
            args = put_parser.parse_args(strict=True)
            reply.body = args.body
            reply.edited = True
            reply.save()
            return Success(f"reply with ID {reply_id} updated").to_json(), 200
        return Fail(f"reply with ID {reply_id} not found").to_json(), 404
Ejemplo n.º 6
0
    def put(self, post_id):
        """Update info for a specific post.

        Args:
            post_id: UUID of the post to update.
        """
        if not validate_uuid(post_id):
            return Fail("invalid post ID").to_json(), 400

        post = Post.get_post(post_id)
        if post is not None:
            args = put_parser.parse_args(strict=True)
            post.body = args.body
            post.edited = True
            post.save()
            return Success(f"post with ID {post_id} updated").to_json(), 200
        return Fail(f"post with ID {post_id} not found").to_json(), 404
Ejemplo n.º 7
0
    def delete(self, reply_id, jwt_payload=None):
        """Delete a specific reply from the database.

        Args:
            reply_id: UUID of the reply to delete.
        """
        if not validate_uuid(reply_id):
            return Fail("invalid reply ID").to_json(), 400
        reply = Reply.get_reply(reply_id)
        if reply is None:
            return Fail(f"Reply ID {reply_id} does not exist").to_json(), 404
        if not (jwt_payload.is_admin or jwt_payload.is_mod
                or jwt_payload.username == reply.author):
            return Fail(
                "You do not have permission to delete replies").to_json(), 403
        else:
            if reply is not None:
                reply.delete()
                return Success(None).to_json(), 204
Ejemplo n.º 8
0
    def put(self, reply_id, jwt_payload=None):
        """Update info for a specific reply.

        Args:
            reply_id: UUID of the reply to update.
        """
        if not validate_uuid(reply_id):
            return Fail("invalid reply ID").to_json(), 400
        reply = Reply.get_reply(reply_id)
        if reply is None:
            return Fail(f"reply with ID {reply_id} not found").to_json(), 404
        if jwt_payload.username != reply.author:
            return Fail(
                "Replies can only be updated by their creators").to_json(), 403

        if reply is not None:
            args = put_parser.parse_args(strict=True)
            reply.body = args.body
            reply.edited = True
            reply.save()
            return Success(f"reply with ID {reply_id} updated").to_json(), 200
Ejemplo n.º 9
0
    def delete(self, post_id, jwt_payload=None):
        """Delete a specific post from the database.
        Only available to admin, mod, and author
        Args:
            post_id: UUID of the post to delete.
        """
        post = Post.get_post(post_id)
        if post is None:
            return Fail(f"Post ID {post_id} does not exist").to_json(), 404
        if jwt_payload.username != post.author or not (jwt_payload.is_mod or
                                                       jwt_payload.is_admin):
            return (
                Fail("Permission denied, you can not delete other's posts").
                to_json(),
                403,
            )
        else:
            if not validate_uuid(post_id):
                return Fail("invalid post ID").to_json(), 400

            if post is not None:
                post.delete()
                return Success(None).to_json(), 204