Skip to content

Commit

Permalink
fix: retrieve security users and add individually
Browse files Browse the repository at this point in the history
  • Loading branch information
patheard authored Dec 7, 2023
1 parent 8ee8db3 commit db8744f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/commands/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions app/tests/commands/test_incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"'),
]
)

Expand Down Expand Up @@ -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"

Expand All @@ -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"]
),
]
)

Expand Down

0 comments on commit db8744f

Please sign in to comment.