Skip to content

Commit

Permalink
feat: delete user's workspace groups when delete the user
Browse files Browse the repository at this point in the history
Signed-off-by: Youngjin Jo <[email protected]>
  • Loading branch information
yjinjo committed Sep 10, 2024
1 parent 5a43b3e commit 081869a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/spaceone/identity/manager/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from spaceone.identity.manager.project_manager import ProjectManager
from spaceone.identity.manager.role_binding_manager import RoleBindingManager
from spaceone.identity.manager.user_group_manager import UserGroupManager
from spaceone.identity.manager.workspace_group_manager import WorkspaceGroupManager
from spaceone.identity.manager.workspace_group_manager import \
WorkspaceGroupManager
from spaceone.identity.model.user.database import User

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -127,16 +128,24 @@ def delete_user_by_vo(user_vo: User) -> None:
users.remove(user_vo.user_id)
project_mgr.update_project_by_vo({"users": users}, project_vo=project_vo)

# TODO: Delete Workspace Group
# Delete workspace groups
workspace_group_vos = workspace_group_mgr.filter_workspace_groups(
users=user_vo.user_id, domain_id=user_vo.domain_id
users__user_id=user_vo.user_id, domain_id=user_vo.domain_id
)

for workspace_group_vo in workspace_group_vos:
users = workspace_group_vo.users
users.remove(user_vo.user_id)
workspace_group_mgr.update_workspace_group_by_vo(
{"users": users}, workspace_group_vo=workspace_group_vo
)
workspace_group_dict = workspace_group_vo.to_mongo().to_dict()
users = workspace_group_dict.get("users", [])

if users:
updated_users = [
user for user in users if user.get("user_id") != user_vo.user_id
]

if len(updated_users) != len(users):
workspace_group_mgr.update_workspace_group_by_vo(
{"users": updated_users}, workspace_group_vo=workspace_group_vo
)

user_vo.delete()

Expand Down

0 comments on commit 081869a

Please sign in to comment.