Skip to content

Commit 5674385

Browse files
authored
Update Slack "invite" feature to use direct paging (#2562)
# What this PR does Refactors the "invite" functionality in Slack to use direct paging and be more consistent with the web UI and `/escalate` Slack command. ## Screenshots ### Alert group buttons Before: <img width="609" alt="Screenshot 2023-07-17 at 22 40 47" src="https://github.com/grafana/oncall/assets/20116910/68fad5a4-5011-4d74-b1c7-362bdb4f8cf0"> After (replace "Invite..." dropdown with "Responders" button, swap it with the silence button): <img width="587" alt="Screenshot 2023-07-17 at 22 37 19" src="https://github.com/grafana/oncall/assets/20116910/50b42057-f46b-4558-ab1c-56c34a15af5e"> ### What happens when clicking on "Responders" The following modal opens up with a list of currently paged users and inputs to page more users/schedules: <img width="514" alt="Screenshot 2023-07-17 at 22 37 52" src="https://github.com/grafana/oncall/assets/20116910/70bd2853-d459-4343-8b25-8519ac0098f7"> This is supposed to be the Slack equivalent of this part of the web UI: <img width="601" alt="Screenshot 2023-07-17 at 22 47 17" src="https://github.com/grafana/oncall/assets/20116910/101e1229-a5c4-404f-8388-eceee3e4820f"> ## Which issue(s) this PR fixes #2336 ## 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)
1 parent 8e3ceb4 commit 5674385

File tree

12 files changed

+586
-54
lines changed

12 files changed

+586
-54
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Changed
11+
12+
- Update Slack "invite" feature to use direct paging by @vadimkerr ([#2562](https://github.com/grafana/oncall/pull/2562))
13+
1014
## v1.3.14 (2023-07-17)
1115

1216
### Changed

engine/apps/alerts/incident_appearance/renderers/slack_renderer.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ def _get_buttons_blocks(self):
213213
},
214214
)
215215

216-
if self.alert_group.invitations.filter(is_active=True).count() < 5:
217-
action_id = ScenarioStep.get_step("distribute_alerts", "InviteOtherPersonToIncident").routing_uid()
218-
text = "Invite..."
219-
invitation_element = self._get_select_user_element(action_id, text=text)
220-
buttons.append(invitation_element)
221-
222216
if not self.alert_group.silenced:
223217
silence_options = [
224218
{
@@ -245,6 +239,15 @@ def _get_buttons_blocks(self):
245239
},
246240
)
247241

242+
buttons.append(
243+
{
244+
"text": {"type": "plain_text", "text": "Responders", "emoji": True},
245+
"type": "button",
246+
"value": self._alert_group_action_value(),
247+
"action_id": ScenarioStep.get_step("manage_responders", "StartManageResponders").routing_uid(),
248+
},
249+
)
250+
248251
attach_button = {
249252
"text": {"type": "plain_text", "text": "Attach to ...", "emoji": True},
250253
"type": "button",

engine/apps/alerts/models/alert_group.py

+17
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,23 @@ def declare_incident_link(self) -> str:
498498
def happened_while_maintenance(self):
499499
return self.root_alert_group is not None and self.root_alert_group.maintenance_uuid is not None
500500

501+
def get_paged_users(self) -> QuerySet[User]:
502+
from apps.alerts.models import AlertGroupLogRecord
503+
504+
users_ids = set()
505+
for log_record in self.log_records.filter(
506+
type__in=(AlertGroupLogRecord.TYPE_DIRECT_PAGING, AlertGroupLogRecord.TYPE_UNPAGE_USER)
507+
):
508+
# filter paging events, track still active escalations
509+
info = log_record.get_step_specific_info()
510+
user_id = info.get("user") if info else None
511+
if user_id is not None:
512+
users_ids.add(
513+
user_id
514+
) if log_record.type == AlertGroupLogRecord.TYPE_DIRECT_PAGING else users_ids.discard(user_id)
515+
516+
return User.objects.filter(public_primary_key__in=users_ids)
517+
501518
def _get_response_time(self):
502519
"""Return response_time based on current alert group status."""
503520
response_time = None

engine/apps/alerts/paging.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
def _trigger_alert(
3030
organization: Organization,
31-
team: Team,
31+
team: Team | None,
3232
title: str,
3333
message: str,
3434
from_user: User,
@@ -133,7 +133,7 @@ def check_user_availability(user: User) -> list[dict[str, Any]]:
133133

134134
def direct_paging(
135135
organization: Organization,
136-
team: Team,
136+
team: Team | None,
137137
from_user: User,
138138
title: str = None,
139139
message: str = None,

engine/apps/api/serializers/alert_group.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
from apps.alerts.incident_appearance.renderers.classic_markdown_renderer import AlertGroupClassicMarkdownRenderer
88
from apps.alerts.incident_appearance.renderers.web_renderer import AlertGroupWebRenderer
9-
from apps.alerts.models import AlertGroup, AlertGroupLogRecord
10-
from apps.user_management.models import User
9+
from apps.alerts.models import AlertGroup
1110
from common.api_helpers.custom_fields import TeamPrimaryKeyRelatedField
1211
from common.api_helpers.mixins import EagerLoadingMixin
1312

@@ -216,17 +215,4 @@ def get_limited_alerts(self, obj):
216215
return AlertSerializer(alerts, many=True).data
217216

218217
def get_paged_users(self, obj):
219-
users_ids = set()
220-
for log_record in obj.log_records.filter(
221-
type__in=(AlertGroupLogRecord.TYPE_DIRECT_PAGING, AlertGroupLogRecord.TYPE_UNPAGE_USER)
222-
):
223-
# filter paging events, track still active escalations
224-
info = log_record.get_step_specific_info()
225-
user_id = info.get("user") if info else None
226-
if user_id is not None:
227-
users_ids.add(
228-
user_id
229-
) if log_record.type == AlertGroupLogRecord.TYPE_DIRECT_PAGING else users_ids.discard(user_id)
230-
231-
users = [u.short() for u in User.objects.filter(public_primary_key__in=users_ids)]
232-
return users
218+
return [u.short() for u in obj.get_paged_users()]

engine/apps/slack/scenarios/distribute_alerts.py

+10
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ def process_scenario(self, slack_user_identity, slack_team_identity, payload):
212212

213213

214214
class InviteOtherPersonToIncident(AlertGroupActionsMixin, scenario_step.ScenarioStep):
215+
"""
216+
THIS SCENARIO STEP IS DEPRECATED AND WILL BE REMOVED IN THE FUTURE.
217+
Check out apps/slack/scenarios/manage_responders.py for the new version that uses direct paging.
218+
"""
219+
215220
REQUIRED_PERMISSIONS = [RBACPermission.Permissions.CHATOPS_WRITE]
216221

217222
def process_scenario(self, slack_user_identity, slack_team_identity, payload):
@@ -490,6 +495,11 @@ def process_signal(self, log_record):
490495

491496

492497
class StopInvitationProcess(AlertGroupActionsMixin, scenario_step.ScenarioStep):
498+
"""
499+
THIS SCENARIO STEP IS DEPRECATED AND WILL BE REMOVED IN THE FUTURE.
500+
Check out apps/slack/scenarios/manage_responders.py for the new version that uses direct paging.
501+
"""
502+
493503
REQUIRED_PERMISSIONS = [RBACPermission.Permissions.CHATOPS_WRITE]
494504

495505
def process_scenario(self, slack_user_identity, slack_team_identity, payload):

0 commit comments

Comments
 (0)