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

Add WorkspaceGroup object type #374

Merged
merged 1 commit into from
Sep 30, 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
22 changes: 12 additions & 10 deletions src/spaceone/identity/service/user_profile_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +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)
from spaceone.identity.service.workspace_group_service import \
WorkspaceGroupService
MyWorkspaceGroupsResponse,
MyWorkspacesResponse,
)
from spaceone.identity.service.workspace_group_service import WorkspaceGroupService

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -463,7 +465,7 @@ def get_workspace_groups(

workspace_group_user_ids = []
for workspace_group_info in workspace_group_infos:
if users := workspace_group_info.users:
if users := workspace_group_info.get("users", []) or []:
for user in users:
if isinstance(user, dict):
workspace_group_user_ids.append(user.get("user_id"))
Expand Down
38 changes: 28 additions & 10 deletions src/spaceone/identity/service/workspace_group_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,24 @@ def add_users_to_workspace_group(
def add_user_name_and_state_to_users(
self,
workspace_group_user_ids: List[str],
workspace_group_info: WorkspaceGroup,
workspace_group_info: Union[WorkspaceGroup, Dict[str, str]],
domain_id: str,
) -> Dict[str, str]:
"""Add user's name and state to users in workspace group.
Since the user's name and state are not in user of workspace group in database,
we need to add user's name and state to users in the Application layer.
Args:
workspace_group_user_ids: 'List[str]'
workspace_group_info: 'WorkspaceGroup'
workspace_group_info: 'Union[WorkspaceGroup, Dict[str, str]]'
domain_id: 'str'
Returns:
workspace_group_dict:
"""
if isinstance(workspace_group_info, dict):
wg_users = workspace_group_info.get("users", [])
else:
wg_users = workspace_group_info.users or []

user_vos = self.user_mgr.filter_users(
user_id=workspace_group_user_ids, domain_id=domain_id
)
Expand All @@ -559,18 +564,31 @@ def add_user_name_and_state_to_users(
"state": user_vo.state,
}

wg_users = workspace_group_info.users or []
users = []

for user in wg_users:
user_id = user.user_id or ""
user.user_name = user_info_map.get(user_id, {}).get("name", "")
user.state = user_info_map.get(user_id, {}).get("state", "")
users.append(user)
if isinstance(user, dict):
user_id = user.get("user_id", "")
else:
user_id = getattr(user, "user_id", "") or ""

workspace_group_info["users"] = users
user_name = user_info_map.get(user_id, {}).get("name", "")
user_state = user_info_map.get(user_id, {}).get("state", "")

return workspace_group_info.to_dict()
if isinstance(user, dict):
user["user_name"] = user_name
user["state"] = user_state
else:
setattr(user, "user_name", user_name)
setattr(user, "state", user_state)

users.append(user)

if isinstance(workspace_group_info, dict):
workspace_group_info["users"] = users
return workspace_group_info
else:
workspace_group_info.users = users
return workspace_group_info.to_dict()

def remove_users_from_workspace_group(
self,
Expand Down
Loading