From db8744f7328c9fe27742eaf2ff795377251d06ee Mon Sep 17 00:00:00 2001 From: Pat Heard Date: Thu, 7 Dec 2023 15:17:29 +0000 Subject: [PATCH] fix: retrieve security users and add individually --- app/commands/incident.py | 6 ++++-- app/tests/commands/test_incident.py | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/commands/incident.py b/app/commands/incident.py index ac560f9d..6589abf0 100644 --- a/app/commands/incident.py +++ b/app/commands/incident.py @@ -310,8 +310,10 @@ def submit(ack, view, say, body, client, logger): for user in oncall: client.conversations_invite(channel=channel_id, users=user["id"]) - # Invite the @security user group to channel - client.conversations_invite(channel=channel_id, users=SLACK_SECURITY_USER_GROUP_ID) + # Invite the @security users to channel + response = client.usergroups_users_list(usergroup=SLACK_SECURITY_USER_GROUP_ID) + if response.get("ok"): + client.conversations_invite(channel=channel_id, users=response["users"]) text = "Run `/sre incident roles` to assign roles to the incident" say(text=text, channel=channel_id) diff --git a/app/tests/commands/test_incident.py b/app/tests/commands/test_incident.py index aff8bf5f..46885f58 100644 --- a/app/tests/commands/test_incident.py +++ b/app/tests/commands/test_incident.py @@ -555,12 +555,14 @@ def test_incident_submit_adds_creator_to_channel( client.conversations_create.return_value = { "channel": {"id": "channel_id", "name": "channel_name"} } + client.usergroups_users_list.return_value = { + "ok": False, + } client.users_lookupByEmail.return_value = {"ok": False, "error": "users_not_found"} incident.submit(ack, view, say, body, client, logger) client.conversations_invite.assert_has_calls( [ call(channel="channel_id", users="creator_user_id"), - call(channel="channel_id", users='"SLACK_SECURITY_USER_GROUP_ID"'), ] ) @@ -711,6 +713,13 @@ def test_incident_submit_pulls_oncall_people_into_the_channel( "profile": {"display_name_normalized": "name"}, }, } + client.usergroups_users_list.return_value = { + "ok": True, + "users": [ + "security_user_id_1", + "security_user_id_2", + ], + } mock_create_new_incident.return_value = "id" @@ -720,11 +729,14 @@ def test_incident_submit_pulls_oncall_people_into_the_channel( incident.submit(ack, view, say, body, client, logger) mock_get_on_call_users.assert_called_once_with("oncall") client.users_lookupByEmail.assert_any_call(email="email") + client.usergroups_users_list(usergroup="SLACK_SECURITY_USER_GROUP_ID") client.conversations_invite.assert_has_calls( [ call(channel="channel_id", users="creator_user_id"), call(channel="channel_id", users="on_call_user_id"), - call(channel="channel_id", users='"SLACK_SECURITY_USER_GROUP_ID"'), + call( + channel="channel_id", users=["security_user_id_1", "security_user_id_2"] + ), ] )