From 04df9afac6519cf91faa2d875b523c63808fb519 Mon Sep 17 00:00:00 2001 From: Youngjin Jo Date: Mon, 7 Oct 2024 17:55:36 +0900 Subject: [PATCH] refactor: fix add users when there is more than 1 workspace Signed-off-by: Youngjin Jo --- .../service/workspace_group_service.py | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/spaceone/identity/service/workspace_group_service.py b/src/spaceone/identity/service/workspace_group_service.py index 3f35a9ea..e0d98d39 100644 --- a/src/spaceone/identity/service/workspace_group_service.py +++ b/src/spaceone/identity/service/workspace_group_service.py @@ -532,30 +532,24 @@ def add_users_to_workspace_group( unique_user_ids = set() def add_user(user_info, workspace_group_workspace_id=None): - if user_info["user_id"] not in unique_user_ids: - role_type = new_users_role_map[user_info["role_id"]] - user_data = { - "user_id": user_info["user_id"], - "role_id": user_info["role_id"], - "role_type": role_type, + role_type = new_users_role_map[user_info["role_id"]] + user_data = { + "user_id": user_info["user_id"], + "role_id": user_info["role_id"], + "role_type": role_type, + } + + if workspace_group_workspace_id: + role_binding_params = { + **user_data, + "resource_group": "WORKSPACE", + "domain_id": domain_id, + "workspace_group_id": workspace_group_id, + "workspace_id": workspace_group_workspace_id, } + self.rb_svc.create_role_binding(role_binding_params) - if workspace_group_workspace_id: - role_binding_params = { - **user_data, - "resource_group": "WORKSPACE", - "domain_id": domain_id, - "workspace_group_id": workspace_group_id, - "workspace_id": workspace_group_workspace_id, - } - new_user_rb_vo = self.rb_svc.create_role_binding( - role_binding_params - ) - user_data = { - "user_id": new_user_rb_vo.user_id, - "role_id": new_user_rb_vo.role_id, - "role_type": new_user_rb_vo.role_type, - } + if user_info["user_id"] not in unique_user_ids: workspace_group_new_users_info_list.append(user_data) unique_user_ids.add(user_data["user_id"])