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)
This commit is contained in:
Vadim Stepanov 2023-06-29 11:09:02 +01:00 committed by GitHub
parent be4176b947
commit 3ebfd9c8b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 44 deletions

View file

@ -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',
),
]

View file

@ -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

View file

@ -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)

View file

@ -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"

View file

@ -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 = [
{

View file

@ -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,
]
)