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 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)
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 {}
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)
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)
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)
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 {}
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, 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 get_comment(ctx, params): auth.verify_privilege(ctx.user, 'comments:view') comment = comments.get_comment_by_id(params['comment_id']) return _serialize(ctx, comment)
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)
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)
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)