Example #1
0
 def delete(self, user_id):
     user = get_user(username=get_jwt_identity())
     target_user = get_user(user_id=user_id)
     check_permissions(user, [
         DeleteUser(target_user),
     ])
     ret = generic_delete(obj=target_user, )
     return ret
Example #2
0
 def put(self, user_id):
     user = get_user(username=get_jwt_identity())
     target_user = get_user(user_id=user_id)
     #EditUser(target=target_user, attributes=set(request.form)).check(user)
     check_permissions(user, [
         EditUser(target_user, attributes=set(request.form)),
     ])
     ret = generic_put(obj=target_user,
                       schema=UserSchema(),
                       data=request.form)
     return ret
Example #3
0
 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
Example #4
0
 def get(self):
     user = get_user(username=get_jwt_identity())
     ret = generic_get(
         obj=user,
         schema=UserSchema(),
     )
     #user themselves are allowed to see their emails
     ret['data']['email'] = str(user.email)
     return ret
Example #5
0
 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
Example #6
0
 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
Example #7
0
 def post(self):
     user = get_user(username=get_jwt_identity())
     check_permissions(user, [
         CreateAvatar(),
     ])
     ret = generic_post(
         schema=AvatarSchema(),
         data=request.form,
     )
     return ret
Example #8
0
 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
Example #9
0
 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
Example #10
0
 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
Example #11
0
 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
Example #12
0
 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
Example #13
0
 def post(self):
     user = get_user(username=get_jwt_identity())
     check_permissions(user, [
         CreateSubforum(),
     ])
     data = request.form.to_dict()
     if not 'position' in data:
         subforum = Subforum.query.order_by(-Subforum.position).first()
         position = 1 if subforum is None else (subforum.position + 1)
         data['position'] = position
     ret = generic_post(
         schema=SubforumSchema(),
         data=data,
     )
     return ret
Example #14
0
 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
Example #15
0
 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