Skip to content

Commit

Permalink
Adding ability to report incident from shortcut (#3655)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Aug 4, 2023
1 parent 00e7192 commit 367c07f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dispatch/plugins/dispatch_slack/incident/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class IncidentReportActions(DispatchEnum):
project_select = "incident-report-project-select"


class IncidentShortcutCallbacks(DispatchEnum):
report = "incident-report"


class UpdateNotificationGroupActions(DispatchEnum):
submit = "update-notification-group-submit"

Expand Down
52 changes: 52 additions & 0 deletions src/dispatch/plugins/dispatch_slack/incident/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
IncidentNotificationActions,
IncidentReportActions,
IncidentUpdateActions,
IncidentShortcutCallbacks,
LinkMonitorActionIds,
LinkMonitorBlockIds,
RemindAgainActions,
Expand Down Expand Up @@ -106,6 +107,7 @@
subject_middleware,
user_middleware,
select_context_middleware,
shortcut_context_middleware,
)
from dispatch.plugins.dispatch_slack.modals.common import send_success_modal
from dispatch.plugins.dispatch_slack.models import MonitorMetadata, TaskMetadata
Expand Down Expand Up @@ -1849,6 +1851,56 @@ def handle_update_incident_submission_event(
)


@app.shortcut(
IncidentShortcutCallbacks.report, middleware=[db_middleware, shortcut_context_middleware]
)
def report_incident(
ack: Ack,
body: dict,
client: WebClient,
context: BoltContext,
db_session: Session,
shortcut: dict,
):
ack()
initial_description = None
if body.get("message"):
permalink = (
client.chat_getPermalink(
channel=context["subject"].channel_id, message_ts=body["message"]["ts"]
)
)["permalink"]
initial_description = f"{body['message']['text']}\n\n{permalink}"

blocks = [
Context(
elements=[
MarkdownText(
text="If you suspect an incident and need help, please fill out this form to the best of your abilities."
)
]
),
title_input(),
description_input(initial_value=initial_description),
project_select(
db_session=db_session,
action_id=IncidentReportActions.project_select,
dispatch_action=True,
),
]

modal = Modal(
title="Report Incident",
blocks=blocks,
submit="Report",
close="Cancel",
callback_id=IncidentReportActions.submit,
private_metadata=context["subject"].json(),
).build()

client.views_open(trigger_id=shortcut["trigger_id"], view=modal)


def handle_report_incident_command(
ack: Ack,
body: dict,
Expand Down

0 comments on commit 367c07f

Please sign in to comment.