diff --git a/src/spaceone/notification/manager/identity_manager.py b/src/spaceone/notification/manager/identity_manager.py index 8a08496..e22e875 100644 --- a/src/spaceone/notification/manager/identity_manager.py +++ b/src/spaceone/notification/manager/identity_manager.py @@ -40,6 +40,24 @@ def get_resource(self, resource_id: str, resource_type: str, domain_id: str): get_method["dispatch_method"], {get_method["key"]: resource_id} ) + def get_project(self, project_id: str, domain_id: str) -> dict: + system_token = config.get_global("TOKEN") + return self.identity_connector.dispatch( + "Project.get", + {"project_id": project_id}, + x_domain_id=domain_id, + token=system_token, + ) + + def get_workspace_users(self, workspace_id: str, domain_id: str) -> dict: + system_token = config.get_global("TOKEN") + return self.identity_connector.dispatch( + "WorkspaceUser.list", + {"workspace_id": workspace_id}, + x_domain_id=domain_id, + token=system_token, + ) + def get_user_profile(self): return self.identity_connector.dispatch("UserProfile.get", {}) @@ -54,10 +72,9 @@ def get_all_users_in_domain(self, domain_id: str) -> list: "state": "ENABLED", } - if self.token_type == "SYSTEM_TOKEN": - response = self.identity_connector.dispatch( - "User.list", query, x_domain_id=domain_id - ) - else: - response = self.identity_connector.dispatch("User.list", query) + system_token = config.get_global("TOKEN") + response = self.identity_connector.dispatch( + "User.list", query, x_domain_id=domain_id, token=system_token + ) + return response.get("results", []) diff --git a/src/spaceone/notification/service/notification_service.py b/src/spaceone/notification/service/notification_service.py index 99cd831..b85b5d2 100644 --- a/src/spaceone/notification/service/notification_service.py +++ b/src/spaceone/notification/service/notification_service.py @@ -109,6 +109,7 @@ def dispatch_project_channel(self, params: dict): project_ch_mgr: ProjectChannelManager = self.locator.get_manager( ProjectChannelManager ) + identity_mgr: IdentityManager = self.locator.get_manager(IdentityManager) domain_id = params["domain_id"] topic = params["topic"] @@ -160,13 +161,34 @@ def dispatch_project_channel(self, params: dict): if protocol_vo.protocol_type == "INTERNAL": internal_project_channel_data = prj_ch_vo.data + users = [] for user_id in internal_project_channel_data.get("users", []): + if user_id == "*": + project_info = identity_mgr.get_project( + project_id, domain_id + ) + project_type = project_info["project_type"] + project_users = project_info.get("users", []) + if project_type == "PRIVATE": + users += project_users + else: + response = identity_mgr.get_workspace_users( + project_id, domain_id + ) + workspace_users = response.get("results", []) + users += workspace_users + else: + users.append(user_id) + + users = list(set(users)) + for user_id in users: params.update( { "resource_type": "identity.User", "resource_id": user_id, } ) + _LOGGER.debug( f"[Forward to User Channel] User ID: {user_id}" )