Example #1
0
def post_comment_delete(comment_id):
    comment = get_comment_by_comment_id(comment_id)
    if user_verifying() == comment.user_id or is_admin(user_verifying()):
        db_delete(comment)
        db_commit()
        return jsonify(comment)
    else:
        return jsonify("You're not allowed to do this action.")
Example #2
0
def user_delete_by_username(username):
    user = get_user_by_username(username)
    if user_verifying() == user.user_id or is_admin(user_verifying()):
        db_delete(user)
        db_commit()
        return jsonify(user)
    else:
        return jsonify("You're not allowed to do this action.")
Example #3
0
def post_delete(post_id):
    post = PostModel.query.filter(user_verifying() == PostModel.user_id
                                  and post_id == PostModel.post_id).first()
    if user_verifying() == post.user_id or is_admin(user_verifying()):
        db_delete(post)
        db_commit()
        return jsonify(post)
    else:
        return jsonify("You're not allowed to do this action.")
Example #4
0
def set_admin():
    if is_admin(user_verifying()):
        user_id = request.json["user_id"]
        role_id = request.json["role_id"]
        user = get_user_by_user_id(user_id)
        user.role_id = role_id
        db_commit()
    else:
        return jsonify("You're not allowed to do this")
Example #5
0
def posts_comment_update(post_id):
    post = get_one_comment(post_id)
    comment = get_spesific_comment(user_verifying(), post)
    if user_verifying() == comment.user_id or is_admin(user_verifying()):
        comment_text = request.json["comment_text"]
        comment.comment_text = comment_text
        db_commit()
        return jsonify(comment)
    else:
        return jsonify("You're not allowed to do this action.")
Example #6
0
def post_update(user_id, post_id):
    post = PostModel.query.filter(user_id == PostModel.user_id
                                  and post_id == PostModel.post_id).first()
    post_text = request.json["post_text"]
    if user_verifying() == post.user_id or is_admin(user_verifying()):
        post.post_text = post_text

        db_commit()
        return jsonify(post)

    else:
        return jsonify("You're not allowed to do this.")
Example #7
0
def user_update(username):
    user = get_user_by_username(username)
    if user.user_id == user_verifying() or is_admin(user_verifying()):
        username = request.json['username']
        password = request.json['password']
        email = request.json['email']
        user.email = email
        user.username = username
        user.password_hash = password

        db_commit()
        return jsonify(user)
    else:
        return jsonify("You're not allowed to do this action.")