コード例 #1
0
ファイル: test_comments.py プロジェクト: rr-/szurubooru
def test_get_comment(comment_factory):
    comment = comment_factory()
    db.session.add(comment)
    db.session.flush()
    with pytest.raises(comments.CommentNotFoundError):
        comments.get_comment_by_id(comment.comment_id + 1)
    assert comments.get_comment_by_id(comment.comment_id) is comment
コード例 #2
0
ファイル: test_comments.py プロジェクト: stopsquarks/quarkman
def test_get_comment(comment_factory):
    comment = comment_factory()
    db.session.add(comment)
    db.session.flush()
    with pytest.raises(comments.CommentNotFoundError):
        comments.get_comment_by_id(comment.comment_id + 1)
    assert comments.get_comment_by_id(comment.comment_id) is comment
コード例 #3
0
def set_comment_score(ctx, params):
    auth.verify_privilege(ctx.user, 'comments:score')
    score = ctx.get_param_as_int('score', required=True)
    comment = comments.get_comment_by_id(params['comment_id'])
    scores.set_score(comment, ctx.user, score)
    ctx.session.commit()
    return _serialize(ctx, comment)
コード例 #4
0
ファイル: comment_api.py プロジェクト: hnamquoc/szurubooru
 def delete(self, ctx, comment_id):
     comment = comments.get_comment_by_id(comment_id)
     infix = 'self' if ctx.user.user_id == comment.user_id else 'any'
     auth.verify_privilege(ctx.user, 'comments:delete:%s' % infix)
     ctx.session.delete(comment)
     ctx.session.commit()
     return {}
コード例 #5
0
ファイル: comment_api.py プロジェクト: paul1409/fumobooru
def _get_comment(params: Dict[str, str]) -> model.Comment:
    try:
        comment_id = int(params['comment_id'])
    except TypeError:
        raise comments.InvalidCommentIdError('Invalid comment ID: %r.' %
                                             params['comment_id'])
    return comments.get_comment_by_id(comment_id)
コード例 #6
0
 def put(self, ctx, comment_id):
     auth.verify_privilege(ctx.user, 'comments:score')
     score = ctx.get_param_as_int('score', required=True)
     comment = comments.get_comment_by_id(comment_id)
     scores.set_score(comment, ctx.user, score)
     ctx.session.commit()
     return comments.serialize_comment_with_details(comment, ctx.user)
コード例 #7
0
ファイル: comment_api.py プロジェクト: rr-/szurubooru
def _get_comment(params: Dict[str, str]) -> model.Comment:
    try:
        comment_id = int(params['comment_id'])
    except TypeError:
        raise comments.InvalidCommentIdError(
            'Invalid comment ID: %r.' % params['comment_id'])
    return comments.get_comment_by_id(comment_id)
コード例 #8
0
 def delete(self, ctx, comment_id):
     comment = comments.get_comment_by_id(comment_id)
     infix = 'self' if ctx.user.user_id == comment.user_id else 'any'
     auth.verify_privilege(ctx.user, 'comments:delete:%s' % infix)
     ctx.session.delete(comment)
     ctx.session.commit()
     return {}
コード例 #9
0
ファイル: comment_api.py プロジェクト: hnamquoc/szurubooru
 def put(self, ctx, comment_id):
     auth.verify_privilege(ctx.user, 'comments:score')
     score = ctx.get_param_as_int('score', required=True)
     comment = comments.get_comment_by_id(comment_id)
     scores.set_score(comment, ctx.user, score)
     ctx.session.commit()
     return comments.serialize_comment_with_details(comment, ctx.user)
コード例 #10
0
def delete_comment(ctx, params):
    comment = comments.get_comment_by_id(params['comment_id'])
    versions.verify_version(comment, ctx)
    infix = 'own' if ctx.user.user_id == comment.user_id else 'any'
    auth.verify_privilege(ctx.user, 'comments:delete:%s' % infix)
    ctx.session.delete(comment)
    ctx.session.commit()
    return {}
コード例 #11
0
 def put(self, ctx, comment_id):
     comment = comments.get_comment_by_id(comment_id)
     infix = 'self' if ctx.user.user_id == comment.user_id else 'any'
     text = ctx.get_param_as_string('text', required=True)
     auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
     comment.last_edit_time = datetime.datetime.now()
     comments.update_comment_text(comment, text)
     ctx.session.commit()
     return comments.serialize_comment_with_details(comment, ctx.user)
コード例 #12
0
ファイル: comment_api.py プロジェクト: hnamquoc/szurubooru
 def put(self, ctx, comment_id):
     comment = comments.get_comment_by_id(comment_id)
     infix = 'self' if ctx.user.user_id == comment.user_id else 'any'
     text = ctx.get_param_as_string('text', required=True)
     auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
     comment.last_edit_time = datetime.datetime.now()
     comments.update_comment_text(comment, text)
     ctx.session.commit()
     return comments.serialize_comment_with_details(comment, ctx.user)
コード例 #13
0
def update_comment(ctx, params):
    comment = comments.get_comment_by_id(params['comment_id'])
    versions.verify_version(comment, ctx)
    versions.bump_version(comment)
    infix = 'own' if ctx.user.user_id == comment.user_id else 'any'
    text = ctx.get_param_as_string('text', required=True)
    auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
    comments.update_comment_text(comment, text)
    comment.last_edit_time = datetime.datetime.utcnow()
    ctx.session.commit()
    return _serialize(ctx, comment)
コード例 #14
0
def get_comment(ctx, params):
    auth.verify_privilege(ctx.user, 'comments:view')
    comment = comments.get_comment_by_id(params['comment_id'])
    return _serialize(ctx, comment)
コード例 #15
0
 def delete(self, ctx, comment_id):
     auth.verify_privilege(ctx.user, 'comments:score')
     comment = comments.get_comment_by_id(comment_id)
     scores.delete_score(comment, ctx.user)
     ctx.session.commit()
     return comments.serialize_comment_with_details(comment, ctx.user)
コード例 #16
0
 def get(self, ctx, comment_id):
     auth.verify_privilege(ctx.user, 'comments:view')
     comment = comments.get_comment_by_id(comment_id)
     return comments.serialize_comment_with_details(comment, ctx.user)
コード例 #17
0
ファイル: comment_api.py プロジェクト: hnamquoc/szurubooru
 def delete(self, ctx, comment_id):
     auth.verify_privilege(ctx.user, 'comments:score')
     comment = comments.get_comment_by_id(comment_id)
     scores.delete_score(comment, ctx.user)
     ctx.session.commit()
     return comments.serialize_comment_with_details(comment, ctx.user)
コード例 #18
0
ファイル: comment_api.py プロジェクト: hnamquoc/szurubooru
 def get(self, ctx, comment_id):
     auth.verify_privilege(ctx.user, 'comments:view')
     comment = comments.get_comment_by_id(comment_id)
     return comments.serialize_comment_with_details(comment, ctx.user)
コード例 #19
0
def delete_comment_score(ctx, params):
    auth.verify_privilege(ctx.user, 'comments:score')
    comment = comments.get_comment_by_id(params['comment_id'])
    scores.delete_score(comment, ctx.user)
    ctx.session.commit()
    return _serialize(ctx, comment)