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)
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)
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)
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)
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)
def test_update_comment_text(comment_factory): comment = comment_factory() comments.update_comment_text(comment, "text") assert comment.text == "text"
def test_update_comment_text_with_emptry_string(comment_factory): comment = comment_factory() with pytest.raises(comments.EmptyCommentTextError): comments.update_comment_text(comment, None)
def test_update_comment_text(comment_factory): comment = comment_factory() comments.update_comment_text(comment, 'text') assert comment.text == 'text'
def test_update_comment_text_with_emptry_string(comment_factory): comment = comment_factory() with pytest.raises(comments.EmptyCommentTextError): comments.update_comment_text(comment, None)