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}
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}
def is_project_member(user: UserInApp): return RoleEnum.projectmember.value in utils.ensure_enums_to_strs( user['admin_roles'] or [])
def is_superuser(user: UserInApp): return RoleEnum.superuser.value in utils.ensure_enums_to_strs( user['admin_roles'] or [])
def check_if_user_is_superuser(user: UserInDB): return RoleEnum.superuser.value in ensure_enums_to_strs(user.admin_roles)
def check_if_user_is_admin(user: UserStored): return RoleEnum.admin.value in ensure_enums_to_strs(user.admin_roles)