From 7d302302d0ca55128f7fee40be17b78a8728e608 Mon Sep 17 00:00:00 2001 From: Philipp Rothmann Date: Wed, 2 Nov 2022 13:55:12 +0100 Subject: [PATCH] mock admin role --- backend/areas/apps/models_lit.py | 4 ++-- backend/areas/auth/lit_auth.py | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/backend/areas/apps/models_lit.py b/backend/areas/apps/models_lit.py index 1132970..63ee487 100644 --- a/backend/areas/apps/models_lit.py +++ b/backend/areas/apps/models_lit.py @@ -1,7 +1,7 @@ """Everything to do with Apps""" from database import db -from .models import App +from .models import App, AppRole class LITApp(App): """ @@ -29,4 +29,4 @@ class LITApp(App): "installed": "", "ready": "", "message": "", - } + } \ No newline at end of file diff --git a/backend/areas/auth/lit_auth.py b/backend/areas/auth/lit_auth.py index f804690..018b507 100644 --- a/backend/areas/auth/lit_auth.py +++ b/backend/areas/auth/lit_auth.py @@ -30,17 +30,21 @@ def hydra_callback(): token = HydraOauth.get_token(state, code) user_info = HydraOauth.get_user_info() - access_token = create_access_token( - identity=token, expires_delta=timedelta(days=365), - #additional_claims={"user_id": identity["id"]} - ) + identity=token, expires_delta=timedelta(days=365)) + isAdmin = "admin" in user_info["groups"] + app_roles = [ + { + "name": "dashboard", + "role_id": 1 if isAdmin else 2 + }, + ] + print(app_roles) # apps = App.query.all() - # app_roles = [] # for app in apps: # 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() # app_roles.append( # { @@ -48,7 +52,6 @@ def hydra_callback(): # "role_id": tmp_app_role.role_id if tmp_app_role else None, # } # ) - return jsonify( { "accessToken": access_token, @@ -57,7 +60,7 @@ def hydra_callback(): "email": user_info["email"], "name": user_info["name"], "preferredUsername": user_info["preferred_username"], - # "app_roles": app_roles, - }, + "app_roles": app_roles + } } )