Exemple #1
0
def route_roles_get():
    current_user = get_current_user()
    if not current_user:
        abort(400, "Could not authenticate user with provided token")
    elif not check_if_user_is_active(current_user):
        abort(400, "Inactive user")
    elif not (check_if_user_is_superuser(current_user)):
        abort(400, "The current user does not have enogh privileges")
    roles = ensure_enums_to_strs(RoleEnum)
    return {"roles": roles}
Exemple #2
0
def route_roles_get(current_user: UserInDB = Depends(get_current_user)):
    """
    Retrieve roles
    """
    if not check_if_user_is_active(current_user):
        raise HTTPException(status_code=400, detail="Inactive user")
    elif not (check_if_user_is_superuser(current_user)):
        raise HTTPException(
            status_code=400, detail="The current user does not have enogh privileges"
        )
    roles = ensure_enums_to_strs(RoleEnum)
    return {"roles": roles}
Exemple #3
0
def is_project_member(user: UserInApp):
    return RoleEnum.projectmember.value in utils.ensure_enums_to_strs(
        user['admin_roles'] or [])
Exemple #4
0
def is_superuser(user: UserInApp):
    return RoleEnum.superuser.value in utils.ensure_enums_to_strs(
        user['admin_roles'] or [])
Exemple #5
0
def check_if_user_is_superuser(user: UserInDB):
    return RoleEnum.superuser.value in ensure_enums_to_strs(user.admin_roles)
Exemple #6
0
def check_if_user_is_admin(user: UserStored):
    return RoleEnum.admin.value in ensure_enums_to_strs(user.admin_roles)