Skip to content

Commit

Permalink
feat: refactor code such that unify workspace group user response
Browse files Browse the repository at this point in the history
Signed-off-by: Youngjin Jo <[email protected]>
  • Loading branch information
yjinjo committed Sep 9, 2024
1 parent ec51c2e commit 05cb2e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 53 deletions.
37 changes: 1 addition & 36 deletions src/spaceone/identity/model/workspace_group_user/response.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
from datetime import datetime
from typing import List, Union
from typing import List

from pydantic.main import BaseModel
from spaceone.core import utils

__all__ = [
"WorkspaceGroupUserResponse",
"WorkspaceGroupUsersResponse",
"WorkspaceGroupUserSummaryResponse",
"WorkspaceGroupUsersSummaryResponse",
]

from spaceone.identity.model.workspace_group.request import State


class WorkspaceGroupUser(BaseModel):
user_id: str
role_id: str
role_type: str
user_name: Union[str, None] = None
state: Union[str, None] = None


class WorkspaceGroupUserResponse(BaseModel):
workspace_group_id: Union[str, None] = None
name: Union[str, None] = None
users: Union[List[WorkspaceGroupUser], None] = None
tags: Union[dict, None] = None
created_by: Union[str, None] = None
updated_by: Union[str, None] = None
domain_id: Union[str, None] = None
created_at: Union[datetime, None] = None
updated_at: Union[datetime, None] = None

def dict(self, *args, **kwargs):
data = super().dict(*args, **kwargs)
data["created_at"] = utils.datetime_to_iso8601(data["created_at"])
data["updated_at"] = utils.datetime_to_iso8601(data["updated_at"])
return data


class WorkspaceGroupUsersResponse(BaseModel):
results: List[WorkspaceGroupUserResponse]
total_count: int


class WorkspaceGroupUserSummaryResponse(BaseModel):
user_id: str
name: str
Expand Down
36 changes: 19 additions & 17 deletions src/spaceone/identity/service/workspace_group_user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
from spaceone.identity.manager.workspace_group_user_manager import (
WorkspaceGroupUserManager,
)
from spaceone.identity.model.workspace_group.response import (
WorkspaceGroupResponse,
WorkspaceGroupsResponse,
)
from spaceone.identity.model.workspace_group_user.request import (
WorkspaceGroupUserAddRequest,
WorkspaceGroupUserFindRequest,
Expand All @@ -33,8 +37,6 @@
WorkspaceGroupUserUpdateRoleRequest,
)
from spaceone.identity.model.workspace_group_user.response import (
WorkspaceGroupUserResponse,
WorkspaceGroupUsersResponse,
WorkspaceGroupUsersSummaryResponse,
)
from spaceone.identity.service.role_binding_service import RoleBindingService
Expand Down Expand Up @@ -64,7 +66,7 @@ def __init__(self, *args, **kwargs):
@convert_model
def add(
self, params: WorkspaceGroupUserAddRequest
) -> Union[WorkspaceGroupUserResponse, dict]:
) -> Union[WorkspaceGroupResponse, dict]:
"""Add workspace group user
Args:
params (WorkspaceGroupUserAddRequest): {
Expand All @@ -79,7 +81,7 @@ def add(
'domain_id': 'str', # injected from auth (required)
}
Returns:
WorkspaceGroupUserResponse:
WorkspaceGroupResponse:
"""
workspace_group_id = params.workspace_group_id
users: List[Dict[str, str]] = params.users
Expand Down Expand Up @@ -133,13 +135,13 @@ def add(
)
)

return WorkspaceGroupUserResponse(**workspace_group_user_dict)
return WorkspaceGroupResponse(**workspace_group_user_dict)

@transaction(permission="identity:WorkspaceGroupUser:write", role_types=["USER"])
@convert_model
def remove(
self, params: WorkspaceGroupUserRemoveRequest
) -> Union[WorkspaceGroupUserResponse, dict]:
) -> Union[WorkspaceGroupResponse, dict]:
"""Remove workspace group user
Args:
params (WorkspaceGroupUserRemoveRequest): {
Expand All @@ -153,7 +155,7 @@ def remove(
'domain_id': 'str', # injected from auth (required)
}
Returns:
WorkspaceGroupUserResponse:
WorkspaceGroupResponse:
"""
# user_id = self.transaction.get_meta("authorization.user_id")
workspace_group_id = params.workspace_group_id
Expand Down Expand Up @@ -190,13 +192,13 @@ def remove(
params.dict(exclude_unset=True), workspace_group_vo
)

return WorkspaceGroupUserResponse(**workspace_group_vo.to_dict())
return WorkspaceGroupResponse(**workspace_group_vo.to_dict())

@transaction(permission="identity:WorkspaceGroupUser:write", role_types=["USER"])
@convert_model
def update_role(
self, params: WorkspaceGroupUserUpdateRoleRequest
) -> Union[WorkspaceGroupUserResponse, dict]:
) -> Union[WorkspaceGroupResponse, dict]:
"""Update workspace group user role
Args:
params (WorkspaceGroupUserUpdateRoleRequest): {
Expand All @@ -207,7 +209,7 @@ def update_role(
'domain_id': 'str', # injected from auth (required)
}
Returns:
WorkspaceGroupUserResponse:
WorkspaceGroupResponse:
"""
workspace_group_id = params.workspace_group_id
role_id = params.role_id
Expand Down Expand Up @@ -247,7 +249,7 @@ def update_role(
update_workspace_group_params, workspace_group_vo
)

return WorkspaceGroupUserResponse(**workspace_group_vo.to_dict())
return WorkspaceGroupResponse(**workspace_group_vo.to_dict())

@transaction(permission="identity:WorkspaceGroupUser:read", role_types=["USER"])
@convert_model
Expand All @@ -273,7 +275,7 @@ def find(
@convert_model
def get(
self, params: WorkspaceGroupUserGetRequest
) -> Union[WorkspaceGroupUserResponse, dict]:
) -> Union[WorkspaceGroupResponse, dict]:
"""Get workspace groups
Args:
params (WorkspaceGroupUserGetRequest): {
Expand All @@ -282,7 +284,7 @@ def get(
'domain_id': 'str', # injected from auth (required)
}
Returns:
WorkspaceGroupUserResponse:
WorkspaceGroupResponse:
"""
workspace_group_id = params.workspace_group_id
domain_id = params.domain_id
Expand All @@ -302,15 +304,15 @@ def get(
workspace_group_user_ids, workspace_group_vo, domain_id
)
)
return WorkspaceGroupUserResponse(**workspace_group_dict)
return WorkspaceGroupResponse(**workspace_group_dict)

@transaction(permission="identity:WorkspaceGroupUser.read", role_types=["USER"])
@append_query_filter(["workspace_group_id", "name", "domain_id"])
@append_keyword_filter(["workspace_group_id", "name"])
@convert_model
def list(
self, params: WorkspaceGroupUserSearchQueryRequest
) -> Union[WorkspaceGroupUsersResponse, dict]:
) -> Union[WorkspaceGroupsResponse, dict]:
"""List workspace group users
Args:
params (WorkspaceGroupUserSearchQueryRequest): {
Expand All @@ -323,7 +325,7 @@ def list(
'domain_id': 'str', # injected from auth (required)
}
Returns:
WorkspaceGroupUsersResponse:
WorkspaceGroupsResponse:
"""
query = params.query

Expand Down Expand Up @@ -354,7 +356,7 @@ def list(
)
workspace_groups_info.append(workspace_group_dict)

return WorkspaceGroupUsersResponse(
return WorkspaceGroupsResponse(
results=workspace_groups_info, total_count=total_count
)

Expand Down

0 comments on commit 05cb2e5

Please sign in to comment.