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

Modify code when changing workspace's workspace group #362

Merged
merged 1 commit into from
Sep 23, 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
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
Loading