Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Slack "invite" feature to use direct paging #2562

Merged
merged 10 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving from here to make it reusable

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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

team is None for No Team (aka default team)

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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are now deprecated, since new messages are rendered without the "Invite..." dropdown.
Leaving the old scenario steps for now so the old messages can be processed.

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