From 9225c895cce882807edb18921f78c32326294189 Mon Sep 17 00:00:00 2001 From: auslin-aot Date: Wed, 7 Aug 2024 16:21:51 +0530 Subject: [PATCH] FWF-3562: [BugFix] Fixed user list display other tenant roles --- .../services/factory/keycloak_group_service.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/forms-flow-api/src/formsflow_api/services/factory/keycloak_group_service.py b/forms-flow-api/src/formsflow_api/services/factory/keycloak_group_service.py index 9dad36a949..8cb0faa3f0 100644 --- a/forms-flow-api/src/formsflow_api/services/factory/keycloak_group_service.py +++ b/forms-flow-api/src/formsflow_api/services/factory/keycloak_group_service.py @@ -22,12 +22,21 @@ def __init__(self): self.client = KeycloakAdminAPIService() self.user_service = UserService() - def __populate_user_groups(self, user_list: List) -> List: + @user_context + def __populate_user_groups(self, user_list: List, **kwargs) -> List: """Collect groups for a user list and populate the role attribute.""" for user in user_list: - user["role"] = ( + user_groups = ( self.client.get_user_groups(user.get("id")) if user.get("id") else [] ) + if current_app.config.get("MULTI_TENANCY_ENABLED"): + logged_user: UserContext = kwargs["user"] + user_groups = [ + group + for group in user_groups + if group["name"].startswith(logged_user.tenant_key) + ] + user["role"] = user_groups return user_list def __populate_user_roles(self, user_list: List) -> List: