def update_user(current_user, email):

    if not current_user.admin:
        return ResponseGenerator.not_authorized()

    user = User.query.filter_by(email=email).first()
    data = request.get_json()

    if not user:
        return ResponseGenerator.not_found()

    if data['admin'] == "True":
        admin = True
    else:
        admin = False

    user.name = data['name']
    user.password = data['password']
    user.email = data['email']
    user.admin = admin
    update_user = User(name=user.name,
                       email=user.email,
                       password=user.password,
                       admin=user.admin)

    User.update(update_user)

    return ResponseGenerator.generate_response(
        f"{update_user.name} has been successfully updated", 200)
def delete_user(current_user, email):

    if not current_user.admin:
        return ResponseGenerator.not_authorized()

    user = User.query.filter_by(email=email).first()

    if not user:
        return ResponseGenerator.not_found()

    User.delete(user)

    return ResponseGenerator.generate_response(
        f"{user.name} deleted successfully from DB.", 200)
def get_one_user(current_user, email):
    if not current_user.admin:
        return ResponseGenerator.not_authorized()

    user = User.query.filter_by(email=email).first()

    if not user:
        return ResponseGenerator.not_found()

    user_data = {}
    user_data['id'] = user.id
    user_data['name'] = user.name
    user_data['email'] = user.email
    user_data['admin'] = user.admin

    return ResponseGenerator.generate_response(user_data, 200)
def get_all_users(current_user):
    if not current_user.admin:
        return ResponseGenerator.not_authorized()

    users = User.query.all()
    output = []

    for user in users:
        user_data = {}
        user_data['id'] = user.id
        user_data['name'] = user.name
        user_data['email'] = user.email
        user_data['admin'] = user.admin
        output.append(user_data)

    return ResponseGenerator.generate_response(output, 200)