Skip to content

Commit

Permalink
feat: add edge case when workspace group deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Youngjin Jo <[email protected]>
  • Loading branch information
yjinjo committed Sep 6, 2024
1 parent 76f4fe1 commit 7084083
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 7084083

Please sign in to comment.