#29-add-admin-role #2

Merged
philipp merged 10 commits from #29-add-admin-role into fork 2022-11-08 16:36:18 +01:00
2 changed files with 14 additions and 11 deletions
Showing only changes of commit 7d302302d0 - Show all commits

View file

@ -1,7 +1,7 @@
"""Everything to do with Apps""" """Everything to do with Apps"""
from database import db from database import db
from .models import App from .models import App, AppRole
class LITApp(App): class LITApp(App):
""" """
@ -29,4 +29,4 @@ class LITApp(App):
"installed": "", "installed": "",
"ready": "", "ready": "",
"message": "", "message": "",
} }

View file

@ -30,17 +30,21 @@ def hydra_callback():
token = HydraOauth.get_token(state, code) token = HydraOauth.get_token(state, code)
user_info = HydraOauth.get_user_info() user_info = HydraOauth.get_user_info()
access_token = create_access_token( access_token = create_access_token(
identity=token, expires_delta=timedelta(days=365), identity=token, expires_delta=timedelta(days=365))
#additional_claims={"user_id": identity["id"]}
)
isAdmin = "admin" in user_info["groups"]
app_roles = [
{
"name": "dashboard",
"role_id": 1 if isAdmin else 2
},
]
print(app_roles)
# apps = App.query.all() # apps = App.query.all()
# app_roles = []
# for app in apps: # for app in apps:
# tmp_app_role = AppRole.query.filter_by( # tmp_app_role = AppRole.query.filter_by(
# user_id=identity["id"], app_id=app.id # user_id=user_info["sub"], app_id=app.id
# ).first() # ).first()
# app_roles.append( # app_roles.append(
# { # {
@ -48,7 +52,6 @@ def hydra_callback():
# "role_id": tmp_app_role.role_id if tmp_app_role else None, # "role_id": tmp_app_role.role_id if tmp_app_role else None,
# } # }
# ) # )
return jsonify( return jsonify(
{ {
"accessToken": access_token, "accessToken": access_token,
@ -57,7 +60,7 @@ def hydra_callback():
"email": user_info["email"], "email": user_info["email"],
"name": user_info["name"], "name": user_info["name"],
"preferredUsername": user_info["preferred_username"], "preferredUsername": user_info["preferred_username"],
# "app_roles": app_roles, "app_roles": app_roles
}, }
} }
) )