Skip to content

Commit

Permalink
fix: trigger_id expired issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gcharest authored Aug 6, 2024
1 parent 99f6833 commit 8f3c67f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
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

0 comments on commit 8f3c67f

Please sign in to comment.