Skip to content

Commit

Permalink
Update Slack "invite" feature to use direct paging (#2562)
Browse files Browse the repository at this point in the history
# 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)
  • Loading branch information
vadimkerr authored Jul 18, 2023
1 parent 8e3ceb4 commit 5674385
Show file tree
Hide file tree
Showing 12 changed files with 586 additions and 54 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Changed

- Update Slack "invite" feature to use direct paging by @vadimkerr ([#2562](https://github.com/grafana/oncall/pull/2562))

## v1.3.14 (2023-07-17)

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ def _get_buttons_blocks(self):
},
)

if self.alert_group.invitations.filter(is_active=True).count() < 5:
action_id = ScenarioStep.get_step("distribute_alerts", "InviteOtherPersonToIncident").routing_uid()
text = "Invite..."
invitation_element = self._get_select_user_element(action_id, text=text)
buttons.append(invitation_element)

if not self.alert_group.silenced:
silence_options = [
{
Expand All @@ -245,6 +239,15 @@ def _get_buttons_blocks(self):
},
)

buttons.append(
{
"text": {"type": "plain_text", "text": "Responders", "emoji": True},
"type": "button",
"value": self._alert_group_action_value(),
"action_id": ScenarioStep.get_step("manage_responders", "StartManageResponders").routing_uid(),
},
)

attach_button = {
"text": {"type": "plain_text", "text": "Attach to ...", "emoji": True},
"type": "button",
Expand Down
17 changes: 17 additions & 0 deletions engine/apps/alerts/models/alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,23 @@ def declare_incident_link(self) -> str:
def happened_while_maintenance(self):
return self.root_alert_group is not None and self.root_alert_group.maintenance_uuid is not None

def get_paged_users(self) -> QuerySet[User]:
from apps.alerts.models import AlertGroupLogRecord

users_ids = set()
for log_record in self.log_records.filter(
type__in=(AlertGroupLogRecord.TYPE_DIRECT_PAGING, AlertGroupLogRecord.TYPE_UNPAGE_USER)
):
# filter paging events, track still active escalations
info = log_record.get_step_specific_info()
user_id = info.get("user") if info else None
if user_id is not None:
users_ids.add(
user_id
) if log_record.type == AlertGroupLogRecord.TYPE_DIRECT_PAGING else users_ids.discard(user_id)

return User.objects.filter(public_primary_key__in=users_ids)

def _get_response_time(self):
"""Return response_time based on current alert group status."""
response_time = None
Expand Down
4 changes: 2 additions & 2 deletions engine/apps/alerts/paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

def _trigger_alert(
organization: Organization,
team: Team,
team: Team | None,
title: str,
message: str,
from_user: User,
Expand Down Expand Up @@ -133,7 +133,7 @@ def check_user_availability(user: User) -> list[dict[str, Any]]:

def direct_paging(
organization: Organization,
team: Team,
team: Team | None,
from_user: User,
title: str = None,
message: str = None,
Expand Down
18 changes: 2 additions & 16 deletions engine/apps/api/serializers/alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

from apps.alerts.incident_appearance.renderers.classic_markdown_renderer import AlertGroupClassicMarkdownRenderer
from apps.alerts.incident_appearance.renderers.web_renderer import AlertGroupWebRenderer
from apps.alerts.models import AlertGroup, AlertGroupLogRecord
from apps.user_management.models import User
from apps.alerts.models import AlertGroup
from common.api_helpers.custom_fields import TeamPrimaryKeyRelatedField
from common.api_helpers.mixins import EagerLoadingMixin

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

def get_paged_users(self, obj):
users_ids = set()
for log_record in obj.log_records.filter(
type__in=(AlertGroupLogRecord.TYPE_DIRECT_PAGING, AlertGroupLogRecord.TYPE_UNPAGE_USER)
):
# filter paging events, track still active escalations
info = log_record.get_step_specific_info()
user_id = info.get("user") if info else None
if user_id is not None:
users_ids.add(
user_id
) if log_record.type == AlertGroupLogRecord.TYPE_DIRECT_PAGING else users_ids.discard(user_id)

users = [u.short() for u in User.objects.filter(public_primary_key__in=users_ids)]
return users
return [u.short() for u in obj.get_paged_users()]
10 changes: 10 additions & 0 deletions engine/apps/slack/scenarios/distribute_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ def process_scenario(self, slack_user_identity, slack_team_identity, payload):


class InviteOtherPersonToIncident(AlertGroupActionsMixin, scenario_step.ScenarioStep):
"""
THIS SCENARIO STEP IS DEPRECATED AND WILL BE REMOVED IN THE FUTURE.
Check out apps/slack/scenarios/manage_responders.py for the new version that uses direct paging.
"""

REQUIRED_PERMISSIONS = [RBACPermission.Permissions.CHATOPS_WRITE]

def process_scenario(self, slack_user_identity, slack_team_identity, payload):
Expand Down Expand Up @@ -490,6 +495,11 @@ def process_signal(self, log_record):


class StopInvitationProcess(AlertGroupActionsMixin, scenario_step.ScenarioStep):
"""
THIS SCENARIO STEP IS DEPRECATED AND WILL BE REMOVED IN THE FUTURE.
Check out apps/slack/scenarios/manage_responders.py for the new version that uses direct paging.
"""

REQUIRED_PERMISSIONS = [RBACPermission.Permissions.CHATOPS_WRITE]

def process_scenario(self, slack_user_identity, slack_team_identity, payload):
Expand Down
Loading

0 comments on commit 5674385

Please sign in to comment.