oncall-engine/engine/apps
Vadim Stepanov d1373b58d2
Fix orphaned messages in Slack (#2023)
# What this PR does
Reworks Slack handlers for buttons and select menus for AG Slack
messages.

<img width="602" alt="Screenshot 2023-05-31 at 19 34 05"
src="https://github.com/grafana/oncall/assets/20116910/857bf096-7bdd-427b-94b6-15aad873a8ac">


## Current implementation

- It's possible to end up with orphaned Slack messages that are posted
to Slack but have no `SlackMessage` instance in the DB. For such
messages, clicking buttons will result in an exception and HTTP 500. See
private repo
[issue](https://github.com/grafana/oncall-private/issues/1841) for more
info.
- Bug in authorization system, which effectively bypasses any permission
checks. For example, it's possible to resolve an alert group while being
a Viewer.
- No tests covering most buttons.

## Changes in this PR

- Make the system more robust, don't use `SlackMessage` model to figure
out the alert group being interacted on, instead embed `alert_group_pk`
to every button and use it when receiving interaction requests from
Slack.
- Existing orphaned Slack messages will be repaired. Clicking buttons
under orphaned messages will work (and missing `SlackMessage` instance
will be created on interaction). This is possible because some buttons
already have `alert_group_pk` embedded, and it's possible to get this
data on button clicks (even if the clicked button itself doesn't have
`alert_group_pk` embedded).
- Fix authorization. Show warning window when unauthorized:
<img width="511" alt="Screenshot 2023-05-31 at 19 40 02"
src="https://github.com/grafana/oncall/assets/20116910/5abeeaa7-1b61-4a47-b3af-0e21d5cd1907">

- Added tests for all the buttons under AG message. Add tests checking
authorization, actual execution of scenario steps, orphan message
repairing, backward compatibility, etc. Also add tests on
`AlertGroupSlackRenderer` checking that correct data is embedded into
buttons.
- Cosmetic changes such as renaming `incident`  to `Alert Group`.

## Which issue(s) this PR fixes
Related to https://github.com/grafana/oncall-private/issues/1841

## 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)
2023-06-01 10:21:30 +00:00
..
alerts Fix orphaned messages in Slack (#2023) 2023-06-01 10:21:30 +00:00
api Change integrations page wording and add more guidance (#1986) 2023-05-31 11:26:36 +00:00
api_for_grafana_incident Include alert details in Grafana Incident alert-group endpoint (#1280) 2023-02-03 13:43:21 +00:00
auth_token Improve plugin authentication (#1995) 2023-05-23 16:13:25 +00:00
base Map country code to different Twilio resources (#1976) 2023-05-25 21:56:44 +00:00
email Change email message on_delete to not block organization delete (#2060) 2023-05-31 13:44:55 +00:00
grafana_plugin Improve plugin authentication (#1995) 2023-05-23 16:13:25 +00:00
heartbeat Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
integrations Add ratelimit for AmazonSNS (#2032) 2023-05-26 09:57:26 +00:00
metrics_exporter OnCall prometheus metrics exporter (#1605) 2023-05-25 18:26:13 +00:00
mobile_app changed notification title and subtitle; removed body (#2027) 2023-05-26 12:52:09 +00:00
oss_installation Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
phone_notifications Fix status callbacks (#2014) 2023-05-25 13:53:58 +08:00
public_api Phone provider refactoring (#1713) 2023-05-24 06:27:48 +00:00
schedules Handle date values coming from ical in final schedule caching (#2025) 2023-05-25 18:17:09 +00:00
slack Fix orphaned messages in Slack (#2023) 2023-06-01 10:21:30 +00:00
social_auth Fix insight_logs exceptions (#1757) 2023-04-17 07:16:18 +00:00
telegram Fix SQLite permission issue (#1984) 2023-05-22 19:16:31 +00:00
twilioapp Map country code to different Twilio resources (#1976) 2023-05-25 21:56:44 +00:00
user_management OnCall prometheus metrics exporter (#1605) 2023-05-25 18:26:13 +00:00
webhooks Webhook response check content length instead of header for length limit (#1900) 2023-05-09 13:55:05 +00:00
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00