def put(self, post_id): user = get_user(username=get_jwt_identity()) post = get_obj(Post.query.filter_by(post_id=post_id)) topic = get_obj(Topic.query.filter_by(topic_id=post.topic_id)) check_permissions(user, [ EditPost(post, attributes=set(request.form)), ]) ret = generic_put(obj=post, schema=PostSchema(exclude=('user_id', 'topic_id')), data=request.form) return ret
def delete(self, post_id): user = get_user(username=get_jwt_identity()) post = get_obj(Post.query.filter_by(post_id=post_id)) topic = get_obj(Topic.query.filter_by(topic_id=post.topic_id)) check_permissions(user, [ DeletePost(post), ]) ret = generic_delete(obj=post, ) #updating number of posts by user user.n_posts = max(user.n_posts - 1, 0) user.save() return ret
def delete(self, subforum_id): user = get_user(username=get_jwt_identity()) subforum = get_obj(Subforum.query.filter_by(subforum_id=subforum_id)) check_permissions(user, [ DeleteSubforum(subforum), ]) ret = generic_delete(obj=subforum, ) return ret
def delete(self, avatar_id): user = get_user(username=get_jwt_identity()) avatar = get_obj(Avatar.query.filter_by(avatar_id=avatar_id), 'avatar does not exist') check_permissions(user, [ DeleteAvatar(avatar), ]) ret = generic_delete(obj=Avatar.query.get(avatar_id), ) return ret
def put(self, subforum_id): user = get_user(username=get_jwt_identity()) subforum = get_obj(Subforum.query.filter_by(subforum_id=subforum_id)) check_permissions(user, [ EditSubforum(subforum, attributes=set(request.form)), ]) ret = generic_put(obj=subforum, schema=SubforumSchema(), data=request.form) return ret
def get(self, topic_id): topic = get_obj( Topic.query.filter_by(topic_id=topic_id), 'topic does not exist') args = parse_get_coll_args(request) ret = generic_get_coll( full_query=Post.query.filter_by(topic_id=topic_id), schema=PostSchema(many=True), **args ) return ret
def put(self, avatar_id): user = get_user(username=get_jwt_identity()) avatar = get_obj(Avatar.query.filter_by(avatar_id=avatar_id), 'avatar does not exist') check_permissions(user, [ EditAvatar(avatar, attributes=set(request.form)), ]) ret = generic_put(obj=Avatar.query.get(avatar_id), schema=AvatarSchema(), data=request.form) return ret
def put(self, topic_id): user = get_user(username=get_jwt_identity()) topic = get_obj( Topic.query.filter_by(topic_id=topic_id), 'topic not found') check_permissions(user, [ EditTopic(topic, attributes=set(request.form)), ]) ret = generic_put( obj=topic, schema=TopicSchema(), data=request.form ) return ret
def delete(self, topic_id): user = get_user(username=get_jwt_identity()) topic = get_obj(Topic.query.filter_by(topic_id=topic_id)) check_permissions(user, [ DeleteTopic(topic), ]) ret = generic_delete( obj=topic, ) #updating number of topics by user user.n_topics = max(user.n_topics - 1, 0) user.save() return ret
def post(self, subforum_id): subforum = get_obj(Subforum.query.filter_by(subforum_id=subforum_id), 'subforum does not exist') user = get_user(username=get_jwt_identity()) check_permissions(user, [ CreateTopicInSubforum(subforum), ]) check_post_time_interval(user, Topic) #validating/updating data data = request.form.to_dict() data['user_id'] = user.user_id data['subforum_id'] = subforum.subforum_id schema = TopicSchema() errors = schema.validate(data) if errors: return mk_errors(400, fmt_validation_error_messages(errors)) ret = generic_post( schema=schema, data=data, ) #updating number of topics by user user.n_topics += 1 user.save() return ret
def post(self, topic_id): topic = get_obj( Topic.query.filter_by(topic_id=topic_id), 'topic does not exist') user = get_user(username=get_jwt_identity()) check_permissions(user, [ CreatePostInTopic(topic), ]) check_post_time_interval(user, Post) #validating/updating data data = request.form.to_dict() data['user_id'] = user.user_id data['topic_id'] = topic.topic_id schema = PostSchema() errors = schema.validate(data) if errors: return mk_errors(400, fmt_validation_error_messages(errors)) ret = generic_post( schema=schema, data=data, ) #updating number of posts by user user.n_posts += 1 user.save() return ret