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 find method #322

Merged
merged 1 commit into from
Aug 27, 2024
Merged
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
45 changes: 42 additions & 3 deletions src/spaceone/identity/service/workspace_group_user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
convert_model,
)

from spaceone.identity.model.workspace_group.response import (
WorkspaceGroupUsersSummaryResponse,
)
from spaceone.identity.manager.user_manager import UserManager
from spaceone.identity.manager.workspace_group_manager import WorkspaceGroupManager
from spaceone.identity.model.workspace_group_user.request import (
WorkspaceGroupUserAddRequest,
WorkspaceGroupUserFindRequest,
Expand All @@ -29,6 +28,7 @@
from spaceone.identity.model.workspace_group_user.response import (
WorkspaceGroupUserResponse,
WorkspaceGroupUsersResponse,
WorkspaceGroupUsersSummaryResponse,
)


Expand All @@ -41,6 +41,7 @@ class WorkspaceGroupUserService(BaseService):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.workspace_group_mgr = WorkspaceGroupManager()

@transaction(permission="identity:WorkspaceGroupUser:write", role_types=["USER"])
@convert_model
Expand Down Expand Up @@ -123,6 +124,7 @@ def find(
Returns:
WorkspaceGroupUsersSummaryResponse:
"""
return self._find(params)

@transaction(permission="identity:WorkspaceGroupUser:read", role_types=["USER"])
@convert_model
Expand Down Expand Up @@ -182,3 +184,40 @@ def stat(self, params: WorkspaceGroupUserStatQueryRequest) -> dict:
}
"""
pass

def _find(
self, params: WorkspaceGroupUserFindRequest
) -> Union[WorkspaceGroupUsersSummaryResponse, dict]:
workspace_group = self.workspace_group_mgr.get_workspace_group(
params.workspace_group_id, params.domain_id
)
workspace_group_users = workspace_group.users or []
workspace_group_user_ids = list(set([user for user in workspace_group_users]))

query = {
"filter": [
{"k": "domain_id", "v": params.domain_id, "o": "eq"},
{"k": "user_id", "v": workspace_group_user_ids, "o": "not_in"},
],
"sort": [{"key": "user_id"}],
"page": params.page,
"only": ["user_id", "name", "state"],
}

if params.keyword:
query["filter_or"] = [
{"k": "user_id", "v": params.keyword, "o": "contain"},
{"k": "name", "v": params.keyword, "o": "contain"},
]

if params.state:
query["filter"].append({"k": "state", "v": params.state, "o": "eq"})

user_mgr = UserManager()
user_vos, total_count = user_mgr.list_users(query)

workspace_group_users_info = [user_vo.to_dict() for user_vo in user_vos]

return WorkspaceGroupUsersSummaryResponse(
results=workspace_group_users_info, total_count=total_count
)
Loading