Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get_workspace_groups API of UserProfile #346

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/spaceone/identity/model/user_profile/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 27 additions & 11 deletions src/spaceone/identity/service/user_profile_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -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__)

Expand Down Expand Up @@ -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,
Expand All @@ -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
)
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/spaceone/identity/service/workspace_group_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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,
Expand Down
Loading