From 97d4f0845daaa7d95eedee113e848baeda367684 Mon Sep 17 00:00:00 2001 From: Davor Date: Wed, 18 May 2022 20:58:00 +0200 Subject: [PATCH] fix issue with WordPress login - resolving role name --- areas/roles/role_service.py | 9 +++++++++ web/login/login.py | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/areas/roles/role_service.py b/areas/roles/role_service.py index 3eb3207..4b44793 100644 --- a/areas/roles/role_service.py +++ b/areas/roles/role_service.py @@ -6,3 +6,12 @@ class RoleService: def get_roles(): roles = Role.query.all() return [{"id": r.id, "name": r.name} for r in roles] + + @staticmethod + def get_role_by_id(role_id): + if role_id is None: + role = Role() + role.name = 'user' + return role + + return Role.query.filter_by(id=role_id).first() diff --git a/web/login/login.py b/web/login/login.py index d0c01d2..258df32 100644 --- a/web/login/login.py +++ b/web/login/login.py @@ -18,6 +18,7 @@ from helpers import KratosUser from config import * from web import web from areas.apps import AppRole, App +from areas.roles import RoleService # This is a circular import and should be solved differently @@ -261,7 +262,9 @@ def consent(): .filter(AppRole.user_id == user.uuid) ) for role_obj in role_objects: - roles.append(role_obj.role.name) + role_name = RoleService.get_role_by_id(role_obj.role_id).name + if (role_name is not None): + roles.append(role_name) current_app.logger.info(f"Using '{roles}' when applying consent for {kratos_id}")