From 3ebfd9c8b26c65585ad7b7e555e36cfeb413c7ed Mon Sep 17 00:00:00 2001 From: Vadim Stepanov Date: Thu, 29 Jun 2023 11:09:02 +0100 Subject: [PATCH] Remove outdated Slack functionality to create alerts (#2383) # What this PR does There's an outdated Slack handler that creates alerts when a file is shared in a channel. I can't remember why it was introduced in the first place, but I'm pretty sure that it's deprecated a long time ago, and this feature is not documented anywhere. The PR also removes `AlertReceiveChannel.integration_slack_channel_id` as it's no longer used. ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- ...ivechannel_integration_slack_channel_id.py | 19 ++++++++++ .../alerts/models/alert_receive_channel.py | 2 -- engine/apps/alerts/tests/test_alert_group.py | 6 ++-- engine/apps/slack/scenarios/scenario_step.py | 1 - .../scenarios/slack_channel_integration.py | 36 ------------------- engine/apps/slack/views.py | 2 -- 6 files changed, 22 insertions(+), 44 deletions(-) create mode 100644 engine/apps/alerts/migrations/0018_remove_alertreceivechannel_integration_slack_channel_id.py diff --git a/engine/apps/alerts/migrations/0018_remove_alertreceivechannel_integration_slack_channel_id.py b/engine/apps/alerts/migrations/0018_remove_alertreceivechannel_integration_slack_channel_id.py new file mode 100644 index 00000000..97be1856 --- /dev/null +++ b/engine/apps/alerts/migrations/0018_remove_alertreceivechannel_integration_slack_channel_id.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.19 on 2023-06-28 16:00 + +from django.db import migrations +import django_migration_linter as linter + + +class Migration(migrations.Migration): + + dependencies = [ + ('alerts', '0017_alertgroup_is_restricted'), + ] + + operations = [ + linter.IgnoreMigration(), # This field is deprecated a long time ago. + migrations.RemoveField( + model_name='alertreceivechannel', + name='integration_slack_channel_id', + ), + ] diff --git a/engine/apps/alerts/models/alert_receive_channel.py b/engine/apps/alerts/models/alert_receive_channel.py index 5d17e86f..42d6ce0b 100644 --- a/engine/apps/alerts/models/alert_receive_channel.py +++ b/engine/apps/alerts/models/alert_receive_channel.py @@ -160,8 +160,6 @@ class AlertReceiveChannel(IntegrationOptionsMixin, MaintainableObject): verbal_name = models.CharField(max_length=150, null=True, default=None) description_short = models.CharField(max_length=250, null=True, default=None) - integration_slack_channel_id = models.CharField(max_length=150, null=True, default=None) - is_finished_alerting_setup = models.BooleanField(default=False) # *_*_template fields are legacy way of storing templates diff --git a/engine/apps/alerts/tests/test_alert_group.py b/engine/apps/alerts/tests/test_alert_group.py index d673567c..87a23d84 100644 --- a/engine/apps/alerts/tests/test_alert_group.py +++ b/engine/apps/alerts/tests/test_alert_group.py @@ -14,7 +14,7 @@ def test_render_for_phone_call( make_alert, ): organization, _ = make_organization_with_slack_team_identity() - alert_receive_channel = make_alert_receive_channel(organization, integration_slack_channel_id="CWER1ASD") + alert_receive_channel = make_alert_receive_channel(organization) alert_group = make_alert_group(alert_receive_channel) SlackMessage.objects.create(channel_id="CWER1ASD", alert_group=alert_group) @@ -60,7 +60,7 @@ def test_delete( slack_channel = make_slack_channel(slack_team_identity, name="general", slack_id="CWER1ASD") user = make_user(organization=organization) - alert_receive_channel = make_alert_receive_channel(organization, integration_slack_channel_id="CWER1ASD") + alert_receive_channel = make_alert_receive_channel(organization) alert_group = make_alert_group(alert_receive_channel) SlackMessage.objects.create(channel_id="CWER1ASD", alert_group=alert_group) @@ -104,7 +104,7 @@ def test_alerts_count_gt( make_alert, ): organization = make_organization() - alert_receive_channel = make_alert_receive_channel(organization, integration_slack_channel_id="CWER1ASD") + alert_receive_channel = make_alert_receive_channel(organization) alert_group = make_alert_group(alert_receive_channel) diff --git a/engine/apps/slack/scenarios/scenario_step.py b/engine/apps/slack/scenarios/scenario_step.py index e6cd768f..38de8d0c 100644 --- a/engine/apps/slack/scenarios/scenario_step.py +++ b/engine/apps/slack/scenarios/scenario_step.py @@ -32,7 +32,6 @@ EVENT_SUBTYPE_MESSAGE_CHANGED = "message_changed" EVENT_SUBTYPE_MESSAGE_DELETED = "message_deleted" EVENT_SUBTYPE_BOT_MESSAGE = "bot_message" EVENT_SUBTYPE_THREAD_BROADCAST = "thread_broadcast" -EVENT_SUBTYPE_FILE_SHARE = "file_share" EVENT_TYPE_CHANNEL_DELETED = "channel_deleted" EVENT_TYPE_CHANNEL_CREATED = "channel_created" EVENT_TYPE_CHANNEL_RENAMED = "channel_rename" diff --git a/engine/apps/slack/scenarios/slack_channel_integration.py b/engine/apps/slack/scenarios/slack_channel_integration.py index 348b6209..8d5a0147 100644 --- a/engine/apps/slack/scenarios/slack_channel_integration.py +++ b/engine/apps/slack/scenarios/slack_channel_integration.py @@ -1,9 +1,7 @@ -import json import logging from django.apps import apps -from apps.integrations.tasks import create_alert from apps.slack.scenarios import scenario_step logger = logging.getLogger(__name__) @@ -30,9 +28,6 @@ class SlackChannelMessageEventStep(scenario_step.ScenarioStep): and "thread_ts" in payload["event"]["previous_message"] ): self.delete_thread_message_from_resolution_note(slack_user_identity, payload) - # Otherwise check if it is a message from channel with Slack Channel Integration - else: - self.create_alert_for_slack_channel_integration_if_needed(payload) def save_thread_message_for_resolution_note(self, slack_user_identity, payload): ResolutionNoteSlackMessage = apps.get_model("alerts", "ResolutionNoteSlackMessage") @@ -144,37 +139,6 @@ class SlackChannelMessageEventStep(scenario_step.ScenarioStep): slack_thread_message.delete() self.alert_group_slack_service.update_alert_group_slack_message(alert_group) - def create_alert_for_slack_channel_integration_if_needed(self, payload): - if "subtype" in payload["event"] and payload["event"]["subtype"] != scenario_step.EVENT_SUBTYPE_FILE_SHARE: - return - AlertReceiveChannel = apps.get_model("alerts", "AlertReceiveChannel") - alert_receive_channels = AlertReceiveChannel.objects.filter( - integration_slack_channel_id=payload["event"]["channel"], organization=self.organization - ).all() - for alert_receive_channel in alert_receive_channels: - r = self._slack_client.api_call( - "chat.getPermalink", - channel=payload["event"]["channel"], - message_ts=payload["event"]["ts"], - ) - # insert permalink to payload to have access to it in templaters - payload["event"]["amixr_mixin"] = {"permalink": r["permalink"]} - - create_alert.apply_async( - [], - { - "title": "<#{}>".format(payload["event"]["channel"]), - "message": "{}\n_New message in <#{}> channel_".format( - payload["event"]["text"], payload["event"]["channel"] - ), - "image_url": None, - "link_to_upstream_details": r["permalink"], - "alert_receive_channel_pk": alert_receive_channel.pk, - "integration_unique_data": json.dumps(payload["event"]), - "raw_request_data": payload["event"], - }, - ) - STEPS_ROUTING = [ { diff --git a/engine/apps/slack/views.py b/engine/apps/slack/views.py index 5b0616e7..9e6bc929 100644 --- a/engine/apps/slack/views.py +++ b/engine/apps/slack/views.py @@ -28,7 +28,6 @@ from apps.slack.scenarios.profile_update import STEPS_ROUTING as PROFILE_UPDATE_ from apps.slack.scenarios.resolution_note import STEPS_ROUTING as RESOLUTION_NOTE_ROUTING from apps.slack.scenarios.scenario_step import ( EVENT_SUBTYPE_BOT_MESSAGE, - EVENT_SUBTYPE_FILE_SHARE, EVENT_SUBTYPE_MESSAGE_CHANGED, EVENT_SUBTYPE_MESSAGE_DELETED, EVENT_TYPE_APP_MENTION, @@ -334,7 +333,6 @@ class SlackEventApiEndpointView(APIView): in [ EVENT_SUBTYPE_BOT_MESSAGE, EVENT_SUBTYPE_MESSAGE_CHANGED, - EVENT_SUBTYPE_FILE_SHARE, EVENT_SUBTYPE_MESSAGE_DELETED, ] )