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

Fix/incident alert buttons #612

Merged
merged 2 commits into from
Aug 6, 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
1 change: 1 addition & 0 deletions app/locales/incident.en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ en-US:
close: "Close"
modal:
title: "SRE - Start an incident"
launching: "Launching incident process..."
congratulations: "Congratulations!"
something_wrong: "Something has gone wrong. You've got this!"
app_help: "This app is going to help you get set up. It will create the following: \n \n • a channel \n • an incident report \n • a Google Meet\n\n"
Expand Down
1 change: 1 addition & 0 deletions app/locales/incident.fr-FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fr-FR:
close: "Fermer"
modal:
title: "IFS - Lancer un incident"
launching: "Lancement du processus d'incident..."
congratulations: "Félicitations!"
something_wrong: "Il y a eu un problème. Vous pouvez y arriver!"
app_help: "Cette application vous aidera à vous préparer. Elle créera les choses suivantes: \n \n • un canal \n • un rapport d'incident \n • une rencontre Google Meet\n\n"
Expand Down
32 changes: 24 additions & 8 deletions app/modules/incident/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@ def generate_incident_modal_view(command, options=[], locale="en-US"):

def open_modal(client, ack, command, body):
ack()
if "user" in body:
user_id = body["user"]["id"]
else:
user_id = body["user_id"]
locale = slack_users.get_user_locale(client, user_id)
i18n.set("locale", locale)
loading_view = {
"type": "modal",
"callback_id": "incident_view",
"title": {"type": "plain_text", "text": i18n.t("incident.modal.title")},
"submit": {"type": "plain_text", "text": i18n.t("incident.submit")},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f":beach-ball: {i18n.t('incident.modal.launching')}",
},
},
],
}
view = client.views_open(trigger_id=body["trigger_id"], view=loading_view)["view"]
folders = google_drive.list_folders()
options = [
{
Expand All @@ -193,14 +215,8 @@ def open_modal(client, ack, command, body):
}
for i in folders
]
if "user" in body:
user_id = body["user"]["id"]
else:
user_id = body["user_id"]
locale = slack_users.get_user_locale(client, user_id)
i18n.set("locale", locale)
view = generate_incident_modal_view(command, options, locale)
client.views_open(trigger_id=body["trigger_id"], view=view)
loaded_view = generate_incident_modal_view(command, options, locale)
client.views_update(view_id=view["id"], view=loaded_view)


def handle_change_locale_button(ack, client, body):
Expand Down
29 changes: 22 additions & 7 deletions app/tests/modules/incident/test_incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,23 @@ def test_handle_incident_action_buttons_link_preview(
)


@patch("modules.incident.incident.generate_incident_modal_view")
@patch("modules.incident.incident.i18n")
@patch("modules.incident.incident.slack_users.get_user_locale")
@patch("modules.incident.incident.google_drive.list_folders")
def test_incident_open_modal_calls_ack(mock_list_folders):
def test_incident_open_modal_calls_ack(
mock_list_folders,
mock_get_user_locale,
mock_i18n,
mock_generate_incident_modal_view,
):
loaded_view = mock_generate_incident_modal_view.return_value = ANY
mock_i18n.t.side_effect = [
"SRE - Start an incident",
"Submit",
"Launching incident process...",
]
mock_get_user_locale.return_value = "en-US"
mock_list_folders.return_value = [{"id": "id", "name": "name"}]
client = MagicMock()
ack = MagicMock()
Expand All @@ -298,14 +313,14 @@ def test_incident_open_modal_calls_ack(mock_list_folders):
assert kwargs["trigger_id"] == "trigger_id"
assert kwargs["view"]["type"] == "modal"
assert kwargs["view"]["callback_id"] == "incident_view"
assert kwargs["view"]["title"]["text"] == "SRE - Start an incident"
assert kwargs["view"]["submit"]["text"] == "Submit"
assert (
kwargs["view"]["blocks"][6]["element"]["initial_value"]
== "incident description"
)
assert kwargs["view"]["blocks"][7]["element"]["options"][0]["value"] == "id"
assert (
kwargs["view"]["blocks"][7]["element"]["options"][0]["text"]["text"] == "name"
kwargs["view"]["blocks"][0]["text"]["text"]
== ":beach-ball: Launching incident process..."
)
mock_generate_incident_modal_view.assert_called_once_with(command, ANY, "en-US")
client.views_update.assert_called_once_with(view_id=ANY, view=loaded_view)


@patch("modules.incident.incident.generate_incident_modal_view")
Expand Down
Loading