Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 6
0
def test_update_comment_text(comment_factory):
    comment = comment_factory()
    comments.update_comment_text(comment, "text")
    assert comment.text == "text"
Ejemplo n.º 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)
Ejemplo n.º 8
0
def test_update_comment_text(comment_factory):
    comment = comment_factory()
    comments.update_comment_text(comment, 'text')
    assert comment.text == 'text'
Ejemplo n.º 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)