Exemple #1
0
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
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
Exemple #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)
Exemple #4
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 {}
Exemple #5
0
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)
Exemple #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)
Exemple #7
0
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)
Exemple #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 {}
Exemple #9
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)
Exemple #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 {}
Exemple #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)
Exemple #12
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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #17
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)
Exemple #18
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)
Exemple #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)