diff --git a/response/slack/incident_commands.py b/response/slack/incident_commands.py index 75f8b01b..d38fbe99 100644 --- a/response/slack/incident_commands.py +++ b/response/slack/incident_commands.py @@ -6,6 +6,7 @@ from response.slack.client import SlackError, reference_to_id from datetime import datetime + @incident_command(['help'], helptext='Display a list of commands and usage') def send_help_text(incident: Incident, user_id: str, message: str): return True, get_help() diff --git a/response/slack/signals.py b/response/slack/signals.py index 403df2bc..3165e996 100644 --- a/response/slack/signals.py +++ b/response/slack/signals.py @@ -1,12 +1,13 @@ -from django.db.models.signals import post_save -from django.core.signals import request_finished +from urllib.parse import urljoin + +from django.db.models.signals import pre_save, post_save from django.dispatch import receiver +from django.conf import settings +from django.urls import reverse from response.core.models import Incident from response.slack.models import HeadlinePost -from time import sleep - @receiver(post_save, sender=Incident) def update_headline_after_incident_save(sender, instance, **kwargs): @@ -28,6 +29,28 @@ def update_headline_after_incident_save(sender, instance, **kwargs): ) +@receiver(pre_save, sender=Incident) +def prompt_incident_report(sender, instance: Incident, **kwargs): + """ + Prompt incident lead to complete a report when an incident is closed. + """ + + try: + prev_state = Incident.objects.get(pk=instance.pk) + except Incident.DoesNotExist: + # Incident hasn't been saved yet, nothing to do here. + return + + if instance.is_closed() and not prev_state.is_closed(): + user_to_notify = instance.lead or instance.reporter + doc_url = urljoin( + settings.SITE_URL, + reverse('incident_doc', kwargs={'incident_id': instance.pk}) + ) + settings.SLACK_CLIENT.send_message( + user_to_notify.external_id, f"👋 Don't forget to fill out an incident report here: {doc_url}") + + @receiver(post_save, sender=HeadlinePost) def update_headline_after_save(sender, instance, **kwargs): """ diff --git a/response/slack/slack_utils.py b/response/slack/slack_utils.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/conftest.py b/tests/conftest.py index c0003d32..c4989c97 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,10 +8,10 @@ import pytest from unittest.mock import MagicMock -from response.slack import dialog_builder, slack_utils, block_kit from response.slack.authentication import generate_signature from response.slack.client import SlackClient + @pytest.fixture(autouse=True) def mock_slack(monkeypatch): mock_slack = MagicMock(spec=SlackClient(""))