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 edge case when workspace group deleted #345

Merged
merged 1 commit into from
Sep 6, 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
5 changes: 5 additions & 0 deletions src/spaceone/identity/error/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ class ERROR_NOT_ALLOWED_TO_DELETE_ROLE_BINDING(ERROR_INVALID_ARGUMENT):

class ERROR_ROLE_IN_USED_AT_ROLE_BINDING(ERROR_INVALID_ARGUMENT):
_message = "Role is in used at RoleBinding. (role_id = {role_id})"


class ERROR_WORKSPACE_EXIST_IN_WORKSPACE_GROUP(ERROR_INVALID_ARGUMENT):
_message = """Workspace exists in WorkspaceGroup. (workspace_id = {workspace_id}, workspace_group_id = {workspace_group_id})
Remove the workspace from the workspace group before deleting the workspace group."""
17 changes: 17 additions & 0 deletions src/spaceone/identity/manager/workspace_group_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from spaceone.core.error import ERROR_INVALID_PARAMETER, ERROR_NOT_FOUND
from spaceone.core.manager import BaseManager

from spaceone.identity.error import ERROR_WORKSPACE_EXIST_IN_WORKSPACE_GROUP
from spaceone.identity.manager.role_binding_manager import RoleBindingManager
from spaceone.identity.manager.workspace_manager import WorkspaceManager
from spaceone.identity.model.workspace_group.database import WorkspaceGroup
Expand All @@ -15,6 +16,7 @@
class WorkspaceGroupManager(BaseManager):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.workspace_manager = WorkspaceManager()
self.workspace_group_model = WorkspaceGroup
self.rb_mgr = RoleBindingManager()

Expand Down Expand Up @@ -44,6 +46,21 @@ def _rollback(old_data):
return workspace_group_vo.update(params)

def delete_workspace_group_by_vo(self, workspace_group_vo: WorkspaceGroup) -> None:
workspace_vos = self.workspace_manager.filter_workspaces(
workspace_group_id=workspace_group_vo.workspace_group_id,
domain_id=workspace_group_vo.domain_id,
)
for workspace_vo in workspace_vos:
if workspace_vo:
_LOGGER.error(
f"Workspace exists in WorkspaceGroup. ({workspace_vo.workspace_id}, {workspace_group_vo.workspace_group_id})"
"Remove the workspace from the workspace group before deleting the workspace group."
)
raise ERROR_WORKSPACE_EXIST_IN_WORKSPACE_GROUP(
workspace_id=workspace_vo.workspace_id,
workspace_group_id=workspace_group_vo.workspace_group_id,
)

if workspace_group_vo.users:
user_ids = [user["user_id"] for user in workspace_group_vo.users]
rb_vos = self.rb_mgr.filter_role_bindings(
Expand Down
Loading