Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
0
def update_comment(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    comment = _get_comment(params)
    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')
    auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
    comments.update_comment_text(comment, text)
    comment.last_edit_time = datetime.utcnow()
    ctx.session.commit()
    return _serialize(ctx, comment)
Beispiel #4
0
def update_comment(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    comment = _get_comment(params)
    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')
    auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
    comments.update_comment_text(comment, text)
    comment.last_edit_time = datetime.utcnow()
    ctx.session.commit()
    return _serialize(ctx, comment)
Beispiel #5
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)
Beispiel #6
0
def test_update_comment_text(comment_factory):
    comment = comment_factory()
    comments.update_comment_text(comment, "text")
    assert comment.text == "text"
Beispiel #7
0
def test_update_comment_text_with_emptry_string(comment_factory):
    comment = comment_factory()
    with pytest.raises(comments.EmptyCommentTextError):
        comments.update_comment_text(comment, None)
Beispiel #8
0
def test_update_comment_text(comment_factory):
    comment = comment_factory()
    comments.update_comment_text(comment, 'text')
    assert comment.text == 'text'
Beispiel #9
0
def test_update_comment_text_with_emptry_string(comment_factory):
    comment = comment_factory()
    with pytest.raises(comments.EmptyCommentTextError):
        comments.update_comment_text(comment, None)