From b5537cd63257c6a5126516d8756ad5cd1ec0cc8f Mon Sep 17 00:00:00 2001 From: Youngjin Jo Date: Fri, 6 Sep 2024 22:45:26 +0900 Subject: [PATCH] feat: update get_workspace_groups api of UserProfile Signed-off-by: Youngjin Jo --- .../identity/model/user_profile/response.py | 1 - .../identity/service/user_profile_service.py | 38 +++++++++++++------ .../service/workspace_group_service.py | 4 +- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/spaceone/identity/model/user_profile/response.py b/src/spaceone/identity/model/user_profile/response.py index 67aa718..1d3f990 100644 --- a/src/spaceone/identity/model/user_profile/response.py +++ b/src/spaceone/identity/model/user_profile/response.py @@ -45,7 +45,6 @@ class MyWorkspacesResponse(BaseModel): class MyWorkspaceGroupResponse(BaseModel): workspace_group_id: Union[str, None] = None name: Union[str, None] = None - workspaces: Union[List[str], None] = None users: Union[List[dict], None] = None tags: Union[dict, None] = None role_binding_info: Union[RoleBindingResponse, None] = None diff --git a/src/spaceone/identity/service/user_profile_service.py b/src/spaceone/identity/service/user_profile_service.py index faead79..ff07fd9 100644 --- a/src/spaceone/identity/service/user_profile_service.py +++ b/src/spaceone/identity/service/user_profile_service.py @@ -2,7 +2,7 @@ import random import re import string -from typing import Union +from typing import Dict, List, Union from spaceone.core import config from spaceone.core.service import * @@ -16,19 +16,23 @@ from spaceone.identity.manager.mfa_manager.base import MFAManager from spaceone.identity.manager.role_binding_manager import RoleBindingManager from spaceone.identity.manager.role_manager import RoleManager -from spaceone.identity.manager.token_manager.local_token_manager import \ - LocalTokenManager +from spaceone.identity.manager.token_manager.local_token_manager import ( + LocalTokenManager, +) from spaceone.identity.manager.user_manager import UserManager -from spaceone.identity.manager.workspace_group_manager import \ - WorkspaceGroupManager +from spaceone.identity.manager.workspace_group_manager import WorkspaceGroupManager from spaceone.identity.manager.workspace_manager import WorkspaceManager from spaceone.identity.model.user.database import User from spaceone.identity.model.user.response import * from spaceone.identity.model.user_profile.request import * -from spaceone.identity.model.user_profile.request import \ - UserProfileGetWorkspaceGroupsRequest +from spaceone.identity.model.user_profile.request import ( + UserProfileGetWorkspaceGroupsRequest, +) from spaceone.identity.model.user_profile.response import ( - MyWorkspaceGroupsResponse, MyWorkspacesResponse) + MyWorkspaceGroupsResponse, + MyWorkspacesResponse, +) +from spaceone.identity.service.workspace_group_service import WorkspaceGroupService _LOGGER = logging.getLogger(__name__) @@ -425,6 +429,7 @@ def get_workspace_groups( domain_id=params.domain_id ) else: + # TODO: Need to check users__user_id is correct workspace_group_vos = self.workspace_group_mgr.filter_workspace_groups( users__user_id=params.user_id, domain_id=params.domain_id, @@ -443,9 +448,20 @@ def get_workspace_groups( ) role_bindings_info_map = {rb.workspace_group_id: rb.to_dict() for rb in rb_vos} - workspace_groups_info = [ - workspace_group_vo.to_dict() for workspace_group_vo in workspace_group_vos + workspace_group_user_ids = [ + user["user_id"] + for workspace_group in workspace_group_vos + for user in workspace_group["users"] ] + + workspace_group_svc = WorkspaceGroupService() + workspace_groups_info = [] + for workspace_group_vo in workspace_group_vos: + workspace_group_dict = workspace_group_svc.add_user_name_and_state_to_users( + workspace_group_user_ids, workspace_group_vo, params.domain_id + ) + workspace_groups_info.append(workspace_group_dict) + my_workspace_groups_info = self._get_my_workspace_groups_info( workspace_groups_info, role_bindings_info_map ) @@ -537,7 +553,7 @@ def _get_my_workspaces_info( @staticmethod def _get_my_workspace_groups_info( workspace_groups_info: list, role_bindings_info_map: dict = None - ) -> list: + ) -> List[Dict[str, str]]: my_workspace_groups_info = [] for workspace_group_info in workspace_groups_info: diff --git a/src/spaceone/identity/service/workspace_group_service.py b/src/spaceone/identity/service/workspace_group_service.py index 9f62220..d98b0ad 100644 --- a/src/spaceone/identity/service/workspace_group_service.py +++ b/src/spaceone/identity/service/workspace_group_service.py @@ -203,7 +203,7 @@ def add_users( params.dict(exclude_unset=True), workspace_group_vo ) - workspace_group_dict = self._add_user_name_and_state_to_users( + workspace_group_dict = self.add_user_name_and_state_to_users( workspace_group_user_ids, workspace_group_vo, domain_id ) @@ -488,7 +488,7 @@ def _add_users_to_workspace_group( return new_users_in_workspace_group - def _add_user_name_and_state_to_users( + def add_user_name_and_state_to_users( self, workspace_group_user_ids: List[str], workspace_group_vo: WorkspaceGroup,