Skip to content

Commit

Permalink
feat: delete role bindings when role bindings exist
Browse files Browse the repository at this point in the history
Signed-off-by: Youngjin Jo <[email protected]>
  • Loading branch information
yjinjo committed Aug 29, 2024
1 parent c70ad80 commit 58102f4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/spaceone/identity/service/workspace_group_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Union

from spaceone.core.error import (
ERROR_EXIST_RESOURCE,
ERROR_INVALID_PARAMETER,
ERROR_NOT_FOUND,
ERROR_PERMISSION_DENIED,
Expand Down Expand Up @@ -147,9 +146,6 @@ def delete(self, params: WorkspaceGroupDeleteRequest) -> None:
params.workspace_group_id, params.domain_id
)

if workspace_group_vo.users:
_LOGGER.error("Workspace Group has users. Please remove users first.")
raise ERROR_EXIST_RESOURCE(child="users", parent="workspace_group")
self.workspace_group_mgr.delete_workspace_group_by_vo(workspace_group_vo)

@transaction(
Expand Down Expand Up @@ -454,12 +450,17 @@ def remove_users(
raise ERROR_NOT_FOUND(key="params_user_id", value=params_user_id)

workspace_group_users = [users for users in workspace_group_vo["users"]]
role_binding_vos = self.rb_mgr.filter_role_bindings(
rb_vos = self.rb_mgr.filter_role_bindings(
user_id=params_user_ids,
workspace_group_id=params.workspace_group_id,
domain_id=params.domain_id,
)
role_binding_vos.delete()

if rb_vos.count() > 0:
_LOGGER.debug(
f"[remove_users] Delete role bindings count with {workspace_group_vo.workspaces}: {rb_vos.count()}"
)
rb_vos.delete()

params.users = []
for user in workspace_group_users:
Expand Down

0 comments on commit 58102f4

Please sign in to comment.