Exemplo n.º 1
0
    def post(self, type, identifier):
        """
        ---
        description: Create new comment
        security:
            - bearerAuth: []
        tags:
            - comment
        requestBody:
            description: Comment content
            content:
              application/json:
                schema: CommentSchemaBase
        parameters:
            - in: path
              name: type
              schema:
                type: string
                enum: [file, config, blob, object]
              description: Type of target object
            - in: path
              name: identifier
              schema:
                type: string
              description: Commented object's id
        responses:
            200:
                description: Comment object after addition
                content:
                  application/json:
                    schema: CommentSchema
        """
        schema = CommentSchemaBase()
        obj = schema.loads(request.get_data(as_text=True))

        if obj.errors:
            return {"errors": obj.errors}, 400

        db_object = authenticated_access(Object, identifier)

        db_comment = Comment()
        db_comment.comment = obj.data["comment"]
        db_comment.user_id = g.auth_user.id
        db_comment.object_id = db_object.id

        db.session.add(db_comment)
        db.session.commit()

        logger.info('comment added', extra={'comment': db_comment.object_id})

        db.session.refresh(db_comment)
        schema = CommentSchema()
        return schema.dump(db_comment)
Exemplo n.º 2
0
    def post(self, type, identifier):
        schema = CommentSchemaBase()
        obj = schema.loads(request.get_data(as_text=True))

        if obj.errors:
            return {"errors": obj.errors}, 400

        db_object = authenticated_access(Object, identifier)

        db_comment = Comment()
        db_comment.comment = obj.data["comment"]
        db_comment.user_id = g.auth_user.id
        db_comment.object_id = db_object.id

        db.session.add(db_comment)
        db.session.commit()

        logger.info('comment added', extra={'comment': db_comment.object_id})

        db.session.refresh(db_comment)
        schema = CommentSchema()
        return schema.dump(db_comment)