Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add * option to project channel of internal type #25

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/spaceone/notification/manager/identity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})

Expand All @@ -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", [])
22 changes: 22 additions & 0 deletions src/spaceone/notification/service/notification_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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}"
)
Expand Down
Loading