Skip to content

Commit

Permalink
fix: modify code when change workspace's workspace group
Browse files Browse the repository at this point in the history
Signed-off-by: Youngjin Jo <[email protected]>
  • Loading branch information
yjinjo committed Sep 23, 2024
1 parent c29a683 commit f68461a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/spaceone/identity/service/workspace_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def change_workspace_group(
WorkspaceResponse:
"""
workspace_id = params.workspace_id
workspace_group_id = params.workspace_group_id
new_workspace_group_id = params.workspace_group_id
domain_id = params.domain_id

workspace_vo = self.workspace_mgr.get_workspace(
Expand All @@ -112,12 +112,12 @@ def change_workspace_group(
old_workspace_group_id = workspace_vo.workspace_group_id
is_updatable = True
workspace_group_vo = None
if workspace_group_id:
if new_workspace_group_id:
workspace_group_vo = self.workspace_group_mgr.get_workspace_group(
workspace_group_id, domain_id
new_workspace_group_id, domain_id
)
is_updatable = self._add_workspace_to_group(
workspace_id, workspace_group_id, domain_id
workspace_id, new_workspace_group_id, domain_id
)
elif old_workspace_group_id:
workspace_group_vo = self.workspace_group_mgr.get_workspace_group(
Expand All @@ -132,17 +132,23 @@ def change_workspace_group(
params.dict(exclude_unset=False), workspace_vo
)

workspace_vos = None
if workspace_group_id:
if new_workspace_group_id:
workspace_vos = self.workspace_mgr.filter_workspaces(
workspace_group_id=workspace_group_id, domain_id=domain_id
workspace_group_id=new_workspace_group_id, domain_id=domain_id
)

self.workspace_group_mgr.update_workspace_group_by_vo(
{"workspace_count": len(workspace_vos)}, workspace_group_vo
)
elif old_workspace_group_id:
if old_workspace_group_id:
workspace_vos = self.workspace_mgr.filter_workspaces(
workspace_group_id=old_workspace_group_id, domain_id=domain_id
)

if workspace_vos:
workspace_group_vo = self.workspace_group_mgr.get_workspace_group(
old_workspace_group_id, domain_id
)

self.workspace_group_mgr.update_workspace_group_by_vo(
{"workspace_count": len(workspace_vos)}, workspace_group_vo
)
Expand Down Expand Up @@ -445,8 +451,10 @@ def _remove_workspace_from_group(
workspace_id=workspace_id, domain_id=domain_id
)
workspace_vo.changed_at = datetime.utcnow()
workspace_vo.workspace_group_id = None
self.workspace_mgr.update_workspace_by_vo(
{"changed_at": workspace_vo.changed_at}, workspace_vo
{"changed_at": workspace_vo.changed_at, "workspace_group_id": None},
workspace_vo,
)

@staticmethod
Expand Down

0 comments on commit f68461a

Please sign in to comment.