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 workspace group manager #341

Merged
merged 2 commits into from
Sep 6, 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
39 changes: 26 additions & 13 deletions src/spaceone/identity/manager/workspace_group_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from spaceone.core.manager import BaseManager

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

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -43,22 +44,34 @@ def _rollback(old_data):
return workspace_group_vo.update(params)

def delete_workspace_group_by_vo(self, workspace_group_vo: WorkspaceGroup) -> None:
user_ids = [user["user_id"] for user in workspace_group_vo.users]
rb_vos = self.rb_mgr.filter_role_bindings(
user_id=user_ids,
workspace_group_id=workspace_group_vo.workspace_group_id,
domain_id=workspace_group_vo.domain_id,
)

if rb_vos.count() > 0:
_LOGGER.debug(
f"[delete_workspace_group_by_vo] Delete role bindings count with {workspace_group_vo.users}: {rb_vos.count()}"
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(
user_id=user_ids,
workspace_group_id=workspace_group_vo.workspace_group_id,
domain_id=workspace_group_vo.domain_id,
)
for rb_vo in rb_vos:

if rb_vos.count() > 0:
_LOGGER.debug(
f"[delete_workspace_group_by_vo] Delete role binding info: {rb_vo.to_dict()}"
f"[delete_workspace_group_by_vo] Delete role bindings count with {workspace_group_vo.users}: {rb_vos.count()}"
)
rb_vo.delete()
for rb_vo in rb_vos:
_LOGGER.debug(
f"[delete_workspace_group_by_vo] Delete role binding info: {rb_vo.to_dict()}"
)
rb_vo.delete()

workspace_mgr = WorkspaceManager()
workspace_vos = workspace_mgr.filter_workspaces(
workspace_group_id=workspace_group_vo.workspace_group_id,
domain_id=workspace_group_vo.domain_id,
)
for workspace_vo in workspace_vos:
params = {
"workspace_group_id": None,
}
workspace_mgr.update_workspace_by_vo(params, workspace_vo)

workspace_group_vo.delete()

Expand Down
Loading