Skip to content

Commit

Permalink
feat: refactor code such that unify debug code
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 8568114 commit d9f589b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
7 changes: 2 additions & 5 deletions src/spaceone/identity/manager/workspace_group_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ def delete_workspace_group_by_vo(self, workspace_group_vo: WorkspaceGroup) -> No
f"[delete_workspace_group_by_vo] Delete role bindings count with {workspace_group_vo.users}: {rb_vos.count()}"
)
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()
self.rb_mgr.delete_role_binding_by_vo(rb_vo)

workspace_mgr = WorkspaceManager()
workspace_vos = workspace_mgr.filter_workspaces(
Expand Down Expand Up @@ -124,7 +121,7 @@ def check_user_id_in_users(user_id: str, workspace_group_vo: WorkspaceGroup):
for workspace_group_user_id in workspace_group_vo["users"]
)

def get_old_users_and_new_users(
def get_unique_old_users_and_new_users(
self,
new_users_info_list: List[Dict[str, str]],
workspace_group_id: str,
Expand Down
13 changes: 4 additions & 9 deletions src/spaceone/identity/manager/workspace_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class WorkspaceManager(BaseManager):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.workspace_model = Workspace
self.rb_mgr = RoleBindingManager()

def create_workspace(self, params: dict) -> Workspace:
def _rollback(vo: Workspace):
Expand Down Expand Up @@ -49,10 +50,8 @@ def _rollback(old_data):

return workspace_vo.update(params)

@staticmethod
def delete_workspace_by_vo(workspace_vo: Workspace) -> None:
rb_mgr = RoleBindingManager()
rb_vos = rb_mgr.filter_role_bindings(
def delete_workspace_by_vo(self, workspace_vo: Workspace) -> None:
rb_vos = self.rb_mgr.filter_role_bindings(
workspace_id=workspace_vo.workspace_id, domain_id=workspace_vo.domain_id
)

Expand All @@ -61,11 +60,7 @@ def delete_workspace_by_vo(workspace_vo: Workspace) -> None:
f"[delete_workspace_by_vo] Delete role bindings count with {workspace_vo.workspace_id} : {rb_vos.count()}"
)
for rb_vo in rb_vos:
_LOGGER.debug(
f"[delete_role_binding_by_vo] Delete role binding info: {rb_vo.to_dict()}"
)
rb_vo.delete()

self.rb_mgr.delete_role_binding_by_vo(rb_vo)
workspace_vo.delete()

cache.delete_pattern(
Expand Down
23 changes: 13 additions & 10 deletions src/spaceone/identity/service/workspace_group_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ def add_users(
workspace_group_id, domain_id
)

old_users, new_users = self.workspace_group_mgr.get_old_users_and_new_users(
new_users_info_list, workspace_group_id, domain_id
old_users, new_users = (
self.workspace_group_mgr.get_unique_old_users_and_new_users(
new_users_info_list, workspace_group_id, domain_id
)
)

self.workspace_group_mgr.check_new_users_already_in_workspace_group(
Expand Down Expand Up @@ -244,8 +246,10 @@ def remove_users(
users = params.users
domain_id = params.domain_id

old_user_ids, user_ids = self.workspace_group_mgr.get_old_users_and_new_users(
users, workspace_group_id, domain_id
old_user_ids, user_ids = (
self.workspace_group_mgr.get_unique_old_users_and_new_users(
users, workspace_group_id, domain_id
)
)

self.workspace_group_mgr.check_user_ids_exist_in_workspace_group(
Expand Down Expand Up @@ -352,8 +356,10 @@ def get(
workspace_group_id, domain_id
)

old_users, new_users = self.workspace_group_mgr.get_old_users_and_new_users(
workspace_group_vo.users, workspace_group_id, domain_id
old_users, new_users = (
self.workspace_group_mgr.get_unique_old_users_and_new_users(
workspace_group_vo.users, workspace_group_id, domain_id
)
)

workspace_group_user_ids: List[str] = old_users + new_users
Expand Down Expand Up @@ -580,10 +586,7 @@ def remove_users_from_workspace_group(

if rb_vos.count() > 0:
for rb_vo in rb_vos:
_LOGGER.debug(
f"[remove_users] Delete role binding info: {rb_vo.to_dict()}"
)
rb_vo.delete()
self.rb_mgr.delete_role_binding_by_vo(rb_vo)

updated_users = [user for user in old_users if user["user_id"] not in user_ids]

Expand Down
5 changes: 1 addition & 4 deletions src/spaceone/identity/service/workspace_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,7 @@ def _delete_role_bindings(existing_workspace_group_id: str, domain_id: str):
domain_id=domain_id,
)
for rb_vo in rb_vos:
_LOGGER.debug(
f"[_delete_role_bindings] Delete role binding info: {rb_vo.to_dict()}"
)
rb_vo.delete()
rb_mgr.delete_role_binding_by_vo(rb_vo)

@staticmethod
def _create_role_bindings(
Expand Down

0 comments on commit d9f589b

Please sign in to comment.