From d669a5c6b90daf6bcefc1a394747e572f5082d48 Mon Sep 17 00:00:00 2001 From: Youngjin Jo Date: Mon, 30 Sep 2024 15:40:42 +0900 Subject: [PATCH] fix: modify code when user is not dict type Signed-off-by: Youngjin Jo --- .../service/workspace_group_service.py | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/spaceone/identity/service/workspace_group_service.py b/src/spaceone/identity/service/workspace_group_service.py index b439e7d..064f2f6 100644 --- a/src/spaceone/identity/service/workspace_group_service.py +++ b/src/spaceone/identity/service/workspace_group_service.py @@ -563,27 +563,25 @@ def add_user_name_and_state_to_users( "name": user_vo.name, "state": user_vo.state, } - if wg_users is None: wg_users = [] users = [] for user in wg_users: if isinstance(user, dict): user_id = user.get("user_id", "") - else: - user_id = getattr(user, "user_id", "") or "" - - user_name = user_info_map.get(user_id, {}).get("name", "") - user_state = user_info_map.get(user_id, {}).get("state", "") - - if isinstance(user, dict): + user_name = user_info_map.get(user_id, {}).get("name", "") + user_state = user_info_map.get(user_id, {}).get("state", "") user["user_name"] = user_name user["state"] = user_state + users.append(user) else: - setattr(user, "user_name", user_name) - setattr(user, "state", user_state) - - users.append(user) + user_id = getattr(user, "user_id", "") or "" + user_name = user_info_map.get(user_id, {}).get("name", "") + user_state = user_info_map.get(user_id, {}).get("state", "") + user_dict = user.to_mongo().to_dict() + user_dict["user_name"] = user_name + user_dict["state"] = user_state + users.append(user_dict) if isinstance(workspace_group_info, dict): workspace_group_info["users"] = users