2022-06-03 08:09:47 -06:00
|
|
|
import pytest
|
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
2023-01-05 12:42:55 +08:00
|
|
|
from django.urls import reverse
|
2022-06-03 08:09:47 -06:00
|
|
|
from django.utils import timezone
|
2023-01-05 12:42:55 +08:00
|
|
|
from rest_framework.test import APIClient
|
2022-06-03 08:09:47 -06:00
|
|
|
|
2023-01-05 12:42:55 +08:00
|
|
|
from apps.alerts.models import AlertGroupLogRecord, AlertReceiveChannel, EscalationPolicy
|
2022-06-03 08:09:47 -06:00
|
|
|
from apps.base.models import UserNotificationPolicy, UserNotificationPolicyLogRecord
|
2023-03-28 19:26:24 +01:00
|
|
|
from apps.schedules.models import OnCallScheduleICal, OnCallScheduleWeb
|
2022-06-03 08:09:47 -06:00
|
|
|
from apps.telegram.models import TelegramMessage
|
2023-01-05 12:42:55 +08:00
|
|
|
from apps.user_management.models import Organization
|
2024-10-11 14:57:59 -04:00
|
|
|
from common.constants.plugin_ids import PluginID
|
2022-06-03 08:09:47 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
2023-01-05 12:42:55 +08:00
|
|
|
def test_organization_soft_delete(
|
|
|
|
|
make_organization_and_user_with_token,
|
|
|
|
|
make_alert_receive_channel,
|
|
|
|
|
):
|
|
|
|
|
organization, _, token = make_organization_and_user_with_token()
|
|
|
|
|
alert_receive_channel = make_alert_receive_channel(
|
|
|
|
|
organization=organization, integration=AlertReceiveChannel.INTEGRATION_ALERTMANAGER
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
org_id = organization.id
|
|
|
|
|
organization.delete()
|
|
|
|
|
|
|
|
|
|
deleted_organization = Organization.objects_with_deleted.get(id=org_id)
|
|
|
|
|
# check if org soft-deleted
|
|
|
|
|
assert deleted_organization.deleted_at is not None
|
|
|
|
|
|
|
|
|
|
# check if public api responds with 404
|
|
|
|
|
client = APIClient()
|
|
|
|
|
url = reverse("api-public:integrations-list")
|
|
|
|
|
response = client.get(url, format="json", HTTP_AUTHORIZATION=f"{token}")
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 404
|
|
|
|
|
|
|
|
|
|
# check if alert receiver view responds with 403
|
|
|
|
|
url = reverse("integrations:alertmanager", kwargs={"alert_channel_key": alert_receive_channel.token})
|
|
|
|
|
data = {"a": "b"}
|
|
|
|
|
response = client.post(url, data, format="json")
|
|
|
|
|
assert response.status_code == 403
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
|
|
|
|
def test_organization_hard_delete(
|
2022-06-03 08:09:47 -06:00
|
|
|
make_organization,
|
|
|
|
|
make_user,
|
|
|
|
|
make_team,
|
|
|
|
|
make_slack_team_identity,
|
|
|
|
|
make_slack_user_identity,
|
2024-11-26 06:03:38 -05:00
|
|
|
make_slack_channel,
|
2022-06-03 08:09:47 -06:00
|
|
|
make_slack_message,
|
|
|
|
|
make_schedule,
|
|
|
|
|
make_custom_action,
|
|
|
|
|
make_alert_receive_channel,
|
|
|
|
|
make_escalation_chain,
|
|
|
|
|
make_escalation_policy,
|
|
|
|
|
make_channel_filter,
|
|
|
|
|
make_user_notification_policy,
|
|
|
|
|
make_telegram_user_connector,
|
|
|
|
|
make_telegram_channel,
|
|
|
|
|
make_telegram_verification_code,
|
|
|
|
|
make_telegram_channel_verification_code,
|
|
|
|
|
make_telegram_message,
|
|
|
|
|
make_alert,
|
|
|
|
|
make_alert_group,
|
|
|
|
|
make_alert_group_log_record,
|
|
|
|
|
make_user_notification_policy_log_record,
|
2023-05-24 14:27:48 +08:00
|
|
|
make_sms_record,
|
|
|
|
|
make_phone_call_record,
|
2022-06-03 08:09:47 -06:00
|
|
|
make_token_for_organization,
|
|
|
|
|
make_public_api_token,
|
|
|
|
|
make_invitation,
|
|
|
|
|
make_resolution_note,
|
|
|
|
|
make_resolution_note_slack_message,
|
|
|
|
|
):
|
|
|
|
|
slack_team_identity = make_slack_team_identity()
|
|
|
|
|
organization = make_organization(slack_team_identity=slack_team_identity)
|
|
|
|
|
|
|
|
|
|
slack_user_identity_1 = make_slack_user_identity(slack_team_identity=slack_team_identity, slack_id="USER_1")
|
|
|
|
|
slack_user_identity_2 = make_slack_user_identity(slack_team_identity=slack_team_identity, slack_id="USER_2")
|
|
|
|
|
|
|
|
|
|
user_1 = make_user(organization=organization, slack_user_identity=slack_user_identity_1)
|
|
|
|
|
user_2 = make_user(organization=organization, slack_user_identity=slack_user_identity_2)
|
|
|
|
|
|
|
|
|
|
user_notification_policy = make_user_notification_policy(
|
|
|
|
|
user=user_1, step=UserNotificationPolicy.Step.WAIT, wait_delay=timezone.timedelta(minutes=15), important=False
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
team = make_team(organization=organization)
|
|
|
|
|
team.users.add(user_1)
|
|
|
|
|
|
2023-03-28 19:26:24 +01:00
|
|
|
# Creating different types of schedules to check that deletion works well with PolymorphicModel
|
|
|
|
|
schedule_web = make_schedule(organization=organization, schedule_class=OnCallScheduleWeb)
|
|
|
|
|
schedule_ical = make_schedule(organization=organization, schedule_class=OnCallScheduleICal)
|
|
|
|
|
|
2022-06-03 08:09:47 -06:00
|
|
|
custom_action = make_custom_action(organization=organization)
|
|
|
|
|
|
|
|
|
|
escalation_chain = make_escalation_chain(organization=organization)
|
|
|
|
|
escalation_policy = make_escalation_policy(
|
|
|
|
|
escalation_chain=escalation_chain,
|
|
|
|
|
escalation_policy_step=EscalationPolicy.STEP_WAIT,
|
|
|
|
|
wait_delay=EscalationPolicy.ONE_MINUTE,
|
|
|
|
|
last_notified_user=user_1,
|
|
|
|
|
)
|
|
|
|
|
escalation_policy.notify_to_users_queue.set([user_1, user_2])
|
|
|
|
|
|
|
|
|
|
alert_receive_channel = make_alert_receive_channel(organization=organization, author=user_1)
|
|
|
|
|
channel_filter = make_channel_filter(alert_receive_channel, is_default=True, escalation_chain=escalation_chain)
|
|
|
|
|
|
|
|
|
|
alert_group = make_alert_group(
|
|
|
|
|
alert_receive_channel=alert_receive_channel,
|
|
|
|
|
acknowledged_by_user=user_1,
|
|
|
|
|
silenced_by_user=user_2,
|
|
|
|
|
wiped_by=user_2,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
alert = make_alert(alert_group=alert_group, raw_request_data={})
|
|
|
|
|
|
|
|
|
|
user_notification_policy_log_record = make_user_notification_policy_log_record(
|
|
|
|
|
author=user_1,
|
|
|
|
|
type=UserNotificationPolicyLogRecord.TYPE_PERSONAL_NOTIFICATION_FAILED,
|
|
|
|
|
notification_policy=user_notification_policy,
|
|
|
|
|
notification_step=user_notification_policy.step,
|
|
|
|
|
notification_channel=user_notification_policy.notify_by,
|
|
|
|
|
alert_group=alert_group,
|
|
|
|
|
)
|
|
|
|
|
|
2023-05-24 14:27:48 +08:00
|
|
|
sms_record = make_sms_record(receiver=user_1, represents_alert=alert, represents_alert_group=alert_group)
|
2022-06-03 08:09:47 -06:00
|
|
|
|
2023-05-24 14:27:48 +08:00
|
|
|
phone_call_record = make_phone_call_record(
|
|
|
|
|
receiver=user_1, represents_alert=alert, represents_alert_group=alert_group
|
2022-06-03 08:09:47 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
telegram_user_connector = make_telegram_user_connector(user=user_1)
|
|
|
|
|
telegram_channel = make_telegram_channel(organization=organization)
|
|
|
|
|
telegram_verification_code = make_telegram_verification_code(user=user_1)
|
|
|
|
|
telegram_channel_verification_code = make_telegram_channel_verification_code(
|
|
|
|
|
organization=organization, author=user_1
|
|
|
|
|
)
|
|
|
|
|
telegram_message = make_telegram_message(alert_group=alert_group, message_type=TelegramMessage.ALERT_GROUP_MESSAGE)
|
|
|
|
|
|
2024-11-26 06:03:38 -05:00
|
|
|
slack_channel = make_slack_channel(slack_team_identity)
|
2024-12-06 11:43:40 -05:00
|
|
|
slack_message = make_slack_message(slack_channel, alert_group=alert_group)
|
2022-06-03 08:09:47 -06:00
|
|
|
|
|
|
|
|
plugin_token, _ = make_token_for_organization(organization)
|
|
|
|
|
public_api_token, _ = make_public_api_token(user_1, organization)
|
|
|
|
|
|
|
|
|
|
invitation = make_invitation(alert_group=alert_group, author=user_1, invitee=user_2)
|
|
|
|
|
|
|
|
|
|
alert_group_log_record = make_alert_group_log_record(
|
|
|
|
|
alert_group=alert_group, author=user_1, type=AlertGroupLogRecord.TYPE_ACK, invitation=invitation
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
resolution_note_slack_message = make_resolution_note_slack_message(
|
|
|
|
|
alert_group=alert_group, user=user_1, added_by_user=user_2
|
|
|
|
|
)
|
|
|
|
|
resolution_note = make_resolution_note(
|
|
|
|
|
alert_group=alert_group, author=user_1, resolution_note_slack_message=resolution_note_slack_message
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cascading_objects = [
|
|
|
|
|
user_1,
|
|
|
|
|
user_2,
|
|
|
|
|
team,
|
|
|
|
|
user_notification_policy,
|
2023-03-28 19:26:24 +01:00
|
|
|
schedule_web,
|
|
|
|
|
schedule_ical,
|
2022-06-03 08:09:47 -06:00
|
|
|
custom_action,
|
|
|
|
|
escalation_chain,
|
|
|
|
|
escalation_policy,
|
|
|
|
|
alert_receive_channel,
|
|
|
|
|
channel_filter,
|
|
|
|
|
alert_group,
|
|
|
|
|
alert,
|
|
|
|
|
alert_group_log_record,
|
|
|
|
|
user_notification_policy_log_record,
|
2023-05-24 14:27:48 +08:00
|
|
|
phone_call_record,
|
|
|
|
|
sms_record,
|
2022-06-03 08:09:47 -06:00
|
|
|
telegram_message,
|
|
|
|
|
telegram_user_connector,
|
|
|
|
|
telegram_channel,
|
|
|
|
|
telegram_verification_code,
|
|
|
|
|
telegram_channel_verification_code,
|
|
|
|
|
slack_message,
|
|
|
|
|
plugin_token,
|
|
|
|
|
public_api_token,
|
|
|
|
|
invitation,
|
|
|
|
|
resolution_note,
|
|
|
|
|
resolution_note_slack_message,
|
|
|
|
|
]
|
|
|
|
|
|
2023-01-05 12:42:55 +08:00
|
|
|
organization.hard_delete()
|
2022-06-03 08:09:47 -06:00
|
|
|
for obj in cascading_objects:
|
|
|
|
|
with pytest.raises(ObjectDoesNotExist):
|
|
|
|
|
obj.refresh_from_db()
|
Add responders improvements (#3128)
# What this PR does
https://www.loom.com/share/c5e10b5ec51343d0954c6f41cfd6a5fb
## Summary of backend changes
- Add `AlertReceiveChannel.get_orgs_direct_paging_integrations` method
and `AlertReceiveChannel.is_contactable` property. These are needed to
be able to (optionally) filter down teams, in the `GET /teams` internal
API endpoint
([here](https://github.com/grafana/oncall/pull/3128/files#diff-a4bd76e557f7e11dafb28a52c1034c075028c693b3c12d702d53c07fc6f24c05R55-R63)),
to just teams that have a "contactable" Direct Paging integration
- `engine/apps/alerts/paging.py`
- update these functions to support new UX. In short `direct_paging` no
longer takes a list of `ScheduleNotifications` or an `EscalationChain`
object
- add `user_is_oncall` helper function
- add `_construct_title` helper function. In short if no `title` is
provided, which is the case for Direct Pages originating from OnCall
(either UI or Slack), then the format is `f"{from_user.username} is
paging <team.name (if team is specified> <comma separated list of
user.usernames> to join escalation"`
- `engine/apps/api/serializers/team.py` - add
`number_of_users_currently_oncall` attribute to response schema
([code](https://github.com/grafana/oncall/pull/3128/files#diff-26af48f796c9e987a76447586dd0f92349783d6ea6a0b6039a2f0f28bd58c2ebR45-R52))
- `engine/apps/api/serializers/user.py` - add `is_currently_oncall`
attribute to response schema
([code](https://github.com/grafana/oncall/pull/3128/files#diff-6744b5544ebb120437af98a996da5ad7d48ee1139a6112c7e3904010ab98f232R157-R162))
- `engine/apps/api/views/team.py` - add support for two new optional
query params `only_include_notifiable_teams` and `include_no_team`
([code](https://github.com/grafana/oncall/pull/3128/files#diff-a4bd76e557f7e11dafb28a52c1034c075028c693b3c12d702d53c07fc6f24c05R55-R70))
- `engine/apps/api/views/user.py`
- in the `GET /users` internal API endpoint, when specifying the
`search` query param now also search on `teams__name`
([code](https://github.com/grafana/oncall/pull/3128/files#diff-30309629484ad28e6fe09816e1bd226226d652ea977b6f3b6775976c729bf4b5R223);
this is a new UX requirement)
- add support for a new optional query param, `is_currently_oncall`, to
allow filtering users based on.. whether they are currently on call or
not
([code](https://github.com/grafana/oncall/pull/3128/files#diff-30309629484ad28e6fe09816e1bd226226d652ea977b6f3b6775976c729bf4b5R272-R282))
- remove `check_availability` endpoint (no longer used with new UX; also
removed references in frontend code)
- `engine/apps/slack/scenarios/paging.py` and
`engine/apps/slack/scenarios/manage_responders.py` - update Slack
workflows to support new UX. Schedules are no longer a concept here.
When creating a new alert group via `/escalate` the user either
specifies a team and/or user(s) (they must specify at least one of the
two and validation is done here to check this). When adding responders
to an existing alert group it's simply a list of users that they can
add, no more schedules.
- add `Organization.slack_is_configured` and
`Organization.telegram_is_configured` properties. These are needed to
support [this new functionality
](https://github.com/grafana/oncall/pull/3128/files#diff-9d96504027309f2bd1e95352bac1433b09b60eb4fafb611b52a6c15ed16cbc48R271-R272)
in the `AlertReceiveChannel` model.
## Summary of frontend changes
- Refactor/rename `EscalationVariants` component to `AddResponders` +
remove `grafana-plugin/src/containers/UserWarningModal` (no longer
needed with new UX)
- Remove `grafana-plugin/src/models/user.ts` as it seemed to be a
duplicate of `grafana-plugin/src/models/user/user.types.ts`
Related to https://github.com/grafana/incident/issues/4278
- Closes #3115
- Closes #3116
- Closes #3117
- Closes #3118
- Closes #3177
## TODO
- [x] make frontend changes
- [x] update Slack backend functionality
- [x] update public documentation
- [x] add/update e2e tests
## Post-deploy To-dos
- [ ] update dev/ops/production Slack bots to update `/escalate` command
description (should now say "Direct page a team or user(s)")
## 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-10-27 12:12:07 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
2023-11-03 12:40:54 -04:00
|
|
|
def test_get_notifiable_direct_paging_integrations(
|
|
|
|
|
make_organization,
|
|
|
|
|
make_alert_receive_channel,
|
|
|
|
|
make_channel_filter,
|
|
|
|
|
make_escalation_chain,
|
|
|
|
|
make_slack_team_identity,
|
|
|
|
|
make_telegram_channel,
|
|
|
|
|
):
|
|
|
|
|
def _make_org_and_arc(**arc_kwargs):
|
|
|
|
|
org = make_organization()
|
|
|
|
|
arc = make_alert_receive_channel(org, integration=AlertReceiveChannel.INTEGRATION_DIRECT_PAGING, **arc_kwargs)
|
|
|
|
|
return org, arc
|
|
|
|
|
|
|
|
|
|
def _assert(org, arc, should_be_returned=True):
|
|
|
|
|
notifiable_direct_paging_integrations = org.get_notifiable_direct_paging_integrations()
|
|
|
|
|
if should_be_returned:
|
|
|
|
|
assert arc in notifiable_direct_paging_integrations
|
|
|
|
|
else:
|
|
|
|
|
assert arc not in notifiable_direct_paging_integrations
|
2023-12-22 07:36:54 -05:00
|
|
|
return notifiable_direct_paging_integrations
|
2023-11-03 12:40:54 -04:00
|
|
|
|
|
|
|
|
# integration has no default channel filter
|
|
|
|
|
org, arc = _make_org_and_arc()
|
|
|
|
|
make_channel_filter(arc, is_default=False)
|
|
|
|
|
_assert(org, arc, should_be_returned=False)
|
|
|
|
|
|
|
|
|
|
# integration has more than one channel filter
|
|
|
|
|
org, arc = _make_org_and_arc()
|
|
|
|
|
make_channel_filter(arc, is_default=False)
|
|
|
|
|
make_channel_filter(arc, is_default=False)
|
|
|
|
|
_assert(org, arc)
|
|
|
|
|
|
|
|
|
|
# integration's default channel filter is setup to notify via slack but Slack is not configured for the org
|
|
|
|
|
org, arc = _make_org_and_arc()
|
|
|
|
|
make_channel_filter(arc, is_default=True, notify_in_slack=True)
|
|
|
|
|
_assert(org, arc, should_be_returned=False)
|
|
|
|
|
|
|
|
|
|
# integration's default channel filter is setup to notify via slack and Slack is configured for the org
|
|
|
|
|
org, arc = _make_org_and_arc()
|
Add responders improvements (#3128)
# What this PR does
https://www.loom.com/share/c5e10b5ec51343d0954c6f41cfd6a5fb
## Summary of backend changes
- Add `AlertReceiveChannel.get_orgs_direct_paging_integrations` method
and `AlertReceiveChannel.is_contactable` property. These are needed to
be able to (optionally) filter down teams, in the `GET /teams` internal
API endpoint
([here](https://github.com/grafana/oncall/pull/3128/files#diff-a4bd76e557f7e11dafb28a52c1034c075028c693b3c12d702d53c07fc6f24c05R55-R63)),
to just teams that have a "contactable" Direct Paging integration
- `engine/apps/alerts/paging.py`
- update these functions to support new UX. In short `direct_paging` no
longer takes a list of `ScheduleNotifications` or an `EscalationChain`
object
- add `user_is_oncall` helper function
- add `_construct_title` helper function. In short if no `title` is
provided, which is the case for Direct Pages originating from OnCall
(either UI or Slack), then the format is `f"{from_user.username} is
paging <team.name (if team is specified> <comma separated list of
user.usernames> to join escalation"`
- `engine/apps/api/serializers/team.py` - add
`number_of_users_currently_oncall` attribute to response schema
([code](https://github.com/grafana/oncall/pull/3128/files#diff-26af48f796c9e987a76447586dd0f92349783d6ea6a0b6039a2f0f28bd58c2ebR45-R52))
- `engine/apps/api/serializers/user.py` - add `is_currently_oncall`
attribute to response schema
([code](https://github.com/grafana/oncall/pull/3128/files#diff-6744b5544ebb120437af98a996da5ad7d48ee1139a6112c7e3904010ab98f232R157-R162))
- `engine/apps/api/views/team.py` - add support for two new optional
query params `only_include_notifiable_teams` and `include_no_team`
([code](https://github.com/grafana/oncall/pull/3128/files#diff-a4bd76e557f7e11dafb28a52c1034c075028c693b3c12d702d53c07fc6f24c05R55-R70))
- `engine/apps/api/views/user.py`
- in the `GET /users` internal API endpoint, when specifying the
`search` query param now also search on `teams__name`
([code](https://github.com/grafana/oncall/pull/3128/files#diff-30309629484ad28e6fe09816e1bd226226d652ea977b6f3b6775976c729bf4b5R223);
this is a new UX requirement)
- add support for a new optional query param, `is_currently_oncall`, to
allow filtering users based on.. whether they are currently on call or
not
([code](https://github.com/grafana/oncall/pull/3128/files#diff-30309629484ad28e6fe09816e1bd226226d652ea977b6f3b6775976c729bf4b5R272-R282))
- remove `check_availability` endpoint (no longer used with new UX; also
removed references in frontend code)
- `engine/apps/slack/scenarios/paging.py` and
`engine/apps/slack/scenarios/manage_responders.py` - update Slack
workflows to support new UX. Schedules are no longer a concept here.
When creating a new alert group via `/escalate` the user either
specifies a team and/or user(s) (they must specify at least one of the
two and validation is done here to check this). When adding responders
to an existing alert group it's simply a list of users that they can
add, no more schedules.
- add `Organization.slack_is_configured` and
`Organization.telegram_is_configured` properties. These are needed to
support [this new functionality
](https://github.com/grafana/oncall/pull/3128/files#diff-9d96504027309f2bd1e95352bac1433b09b60eb4fafb611b52a6c15ed16cbc48R271-R272)
in the `AlertReceiveChannel` model.
## Summary of frontend changes
- Refactor/rename `EscalationVariants` component to `AddResponders` +
remove `grafana-plugin/src/containers/UserWarningModal` (no longer
needed with new UX)
- Remove `grafana-plugin/src/models/user.ts` as it seemed to be a
duplicate of `grafana-plugin/src/models/user/user.types.ts`
Related to https://github.com/grafana/incident/issues/4278
- Closes #3115
- Closes #3116
- Closes #3117
- Closes #3118
- Closes #3177
## TODO
- [x] make frontend changes
- [x] update Slack backend functionality
- [x] update public documentation
- [x] add/update e2e tests
## Post-deploy To-dos
- [ ] update dev/ops/production Slack bots to update `/escalate` command
description (should now say "Direct page a team or user(s)")
## 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-10-27 12:12:07 -04:00
|
|
|
slack_team_identity = make_slack_team_identity()
|
2023-11-03 12:40:54 -04:00
|
|
|
org.slack_team_identity = slack_team_identity
|
|
|
|
|
org.save()
|
|
|
|
|
|
|
|
|
|
make_channel_filter(arc, is_default=True, notify_in_slack=True)
|
|
|
|
|
_assert(org, arc)
|
|
|
|
|
|
|
|
|
|
# integration's default channel filter is setup to notify via telegram but Telegram is not configured for the org
|
|
|
|
|
org, arc = _make_org_and_arc()
|
|
|
|
|
make_channel_filter(arc, is_default=True, notify_in_slack=False, notify_in_telegram=True)
|
|
|
|
|
_assert(org, arc, should_be_returned=False)
|
|
|
|
|
|
|
|
|
|
# integration's default channel filter is setup to notify via telegram and Telegram is configured for the org
|
|
|
|
|
org, arc = _make_org_and_arc()
|
|
|
|
|
make_channel_filter(arc, is_default=True, notify_in_slack=False, notify_in_telegram=True)
|
|
|
|
|
make_telegram_channel(org)
|
|
|
|
|
_assert(org, arc)
|
|
|
|
|
|
|
|
|
|
# integration's default channel filter is contactable via a custom messaging backend
|
|
|
|
|
org, arc = _make_org_and_arc()
|
|
|
|
|
make_channel_filter(
|
|
|
|
|
arc,
|
|
|
|
|
is_default=True,
|
|
|
|
|
notify_in_slack=False,
|
|
|
|
|
notification_backends={"MSTEAMS": {"channel": "test", "enabled": True}},
|
Add responders improvements (#3128)
# What this PR does
https://www.loom.com/share/c5e10b5ec51343d0954c6f41cfd6a5fb
## Summary of backend changes
- Add `AlertReceiveChannel.get_orgs_direct_paging_integrations` method
and `AlertReceiveChannel.is_contactable` property. These are needed to
be able to (optionally) filter down teams, in the `GET /teams` internal
API endpoint
([here](https://github.com/grafana/oncall/pull/3128/files#diff-a4bd76e557f7e11dafb28a52c1034c075028c693b3c12d702d53c07fc6f24c05R55-R63)),
to just teams that have a "contactable" Direct Paging integration
- `engine/apps/alerts/paging.py`
- update these functions to support new UX. In short `direct_paging` no
longer takes a list of `ScheduleNotifications` or an `EscalationChain`
object
- add `user_is_oncall` helper function
- add `_construct_title` helper function. In short if no `title` is
provided, which is the case for Direct Pages originating from OnCall
(either UI or Slack), then the format is `f"{from_user.username} is
paging <team.name (if team is specified> <comma separated list of
user.usernames> to join escalation"`
- `engine/apps/api/serializers/team.py` - add
`number_of_users_currently_oncall` attribute to response schema
([code](https://github.com/grafana/oncall/pull/3128/files#diff-26af48f796c9e987a76447586dd0f92349783d6ea6a0b6039a2f0f28bd58c2ebR45-R52))
- `engine/apps/api/serializers/user.py` - add `is_currently_oncall`
attribute to response schema
([code](https://github.com/grafana/oncall/pull/3128/files#diff-6744b5544ebb120437af98a996da5ad7d48ee1139a6112c7e3904010ab98f232R157-R162))
- `engine/apps/api/views/team.py` - add support for two new optional
query params `only_include_notifiable_teams` and `include_no_team`
([code](https://github.com/grafana/oncall/pull/3128/files#diff-a4bd76e557f7e11dafb28a52c1034c075028c693b3c12d702d53c07fc6f24c05R55-R70))
- `engine/apps/api/views/user.py`
- in the `GET /users` internal API endpoint, when specifying the
`search` query param now also search on `teams__name`
([code](https://github.com/grafana/oncall/pull/3128/files#diff-30309629484ad28e6fe09816e1bd226226d652ea977b6f3b6775976c729bf4b5R223);
this is a new UX requirement)
- add support for a new optional query param, `is_currently_oncall`, to
allow filtering users based on.. whether they are currently on call or
not
([code](https://github.com/grafana/oncall/pull/3128/files#diff-30309629484ad28e6fe09816e1bd226226d652ea977b6f3b6775976c729bf4b5R272-R282))
- remove `check_availability` endpoint (no longer used with new UX; also
removed references in frontend code)
- `engine/apps/slack/scenarios/paging.py` and
`engine/apps/slack/scenarios/manage_responders.py` - update Slack
workflows to support new UX. Schedules are no longer a concept here.
When creating a new alert group via `/escalate` the user either
specifies a team and/or user(s) (they must specify at least one of the
two and validation is done here to check this). When adding responders
to an existing alert group it's simply a list of users that they can
add, no more schedules.
- add `Organization.slack_is_configured` and
`Organization.telegram_is_configured` properties. These are needed to
support [this new functionality
](https://github.com/grafana/oncall/pull/3128/files#diff-9d96504027309f2bd1e95352bac1433b09b60eb4fafb611b52a6c15ed16cbc48R271-R272)
in the `AlertReceiveChannel` model.
## Summary of frontend changes
- Refactor/rename `EscalationVariants` component to `AddResponders` +
remove `grafana-plugin/src/containers/UserWarningModal` (no longer
needed with new UX)
- Remove `grafana-plugin/src/models/user.ts` as it seemed to be a
duplicate of `grafana-plugin/src/models/user/user.types.ts`
Related to https://github.com/grafana/incident/issues/4278
- Closes #3115
- Closes #3116
- Closes #3117
- Closes #3118
- Closes #3177
## TODO
- [x] make frontend changes
- [x] update Slack backend functionality
- [x] update public documentation
- [x] add/update e2e tests
## Post-deploy To-dos
- [ ] update dev/ops/production Slack bots to update `/escalate` command
description (should now say "Direct page a team or user(s)")
## 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-10-27 12:12:07 -04:00
|
|
|
)
|
2023-11-03 12:40:54 -04:00
|
|
|
_assert(org, arc)
|
Add responders improvements (#3128)
# What this PR does
https://www.loom.com/share/c5e10b5ec51343d0954c6f41cfd6a5fb
## Summary of backend changes
- Add `AlertReceiveChannel.get_orgs_direct_paging_integrations` method
and `AlertReceiveChannel.is_contactable` property. These are needed to
be able to (optionally) filter down teams, in the `GET /teams` internal
API endpoint
([here](https://github.com/grafana/oncall/pull/3128/files#diff-a4bd76e557f7e11dafb28a52c1034c075028c693b3c12d702d53c07fc6f24c05R55-R63)),
to just teams that have a "contactable" Direct Paging integration
- `engine/apps/alerts/paging.py`
- update these functions to support new UX. In short `direct_paging` no
longer takes a list of `ScheduleNotifications` or an `EscalationChain`
object
- add `user_is_oncall` helper function
- add `_construct_title` helper function. In short if no `title` is
provided, which is the case for Direct Pages originating from OnCall
(either UI or Slack), then the format is `f"{from_user.username} is
paging <team.name (if team is specified> <comma separated list of
user.usernames> to join escalation"`
- `engine/apps/api/serializers/team.py` - add
`number_of_users_currently_oncall` attribute to response schema
([code](https://github.com/grafana/oncall/pull/3128/files#diff-26af48f796c9e987a76447586dd0f92349783d6ea6a0b6039a2f0f28bd58c2ebR45-R52))
- `engine/apps/api/serializers/user.py` - add `is_currently_oncall`
attribute to response schema
([code](https://github.com/grafana/oncall/pull/3128/files#diff-6744b5544ebb120437af98a996da5ad7d48ee1139a6112c7e3904010ab98f232R157-R162))
- `engine/apps/api/views/team.py` - add support for two new optional
query params `only_include_notifiable_teams` and `include_no_team`
([code](https://github.com/grafana/oncall/pull/3128/files#diff-a4bd76e557f7e11dafb28a52c1034c075028c693b3c12d702d53c07fc6f24c05R55-R70))
- `engine/apps/api/views/user.py`
- in the `GET /users` internal API endpoint, when specifying the
`search` query param now also search on `teams__name`
([code](https://github.com/grafana/oncall/pull/3128/files#diff-30309629484ad28e6fe09816e1bd226226d652ea977b6f3b6775976c729bf4b5R223);
this is a new UX requirement)
- add support for a new optional query param, `is_currently_oncall`, to
allow filtering users based on.. whether they are currently on call or
not
([code](https://github.com/grafana/oncall/pull/3128/files#diff-30309629484ad28e6fe09816e1bd226226d652ea977b6f3b6775976c729bf4b5R272-R282))
- remove `check_availability` endpoint (no longer used with new UX; also
removed references in frontend code)
- `engine/apps/slack/scenarios/paging.py` and
`engine/apps/slack/scenarios/manage_responders.py` - update Slack
workflows to support new UX. Schedules are no longer a concept here.
When creating a new alert group via `/escalate` the user either
specifies a team and/or user(s) (they must specify at least one of the
two and validation is done here to check this). When adding responders
to an existing alert group it's simply a list of users that they can
add, no more schedules.
- add `Organization.slack_is_configured` and
`Organization.telegram_is_configured` properties. These are needed to
support [this new functionality
](https://github.com/grafana/oncall/pull/3128/files#diff-9d96504027309f2bd1e95352bac1433b09b60eb4fafb611b52a6c15ed16cbc48R271-R272)
in the `AlertReceiveChannel` model.
## Summary of frontend changes
- Refactor/rename `EscalationVariants` component to `AddResponders` +
remove `grafana-plugin/src/containers/UserWarningModal` (no longer
needed with new UX)
- Remove `grafana-plugin/src/models/user.ts` as it seemed to be a
duplicate of `grafana-plugin/src/models/user/user.types.ts`
Related to https://github.com/grafana/incident/issues/4278
- Closes #3115
- Closes #3116
- Closes #3117
- Closes #3118
- Closes #3177
## TODO
- [x] make frontend changes
- [x] update Slack backend functionality
- [x] update public documentation
- [x] add/update e2e tests
## Post-deploy To-dos
- [ ] update dev/ops/production Slack bots to update `/escalate` command
description (should now say "Direct page a team or user(s)")
## 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-10-27 12:12:07 -04:00
|
|
|
|
2023-11-03 12:40:54 -04:00
|
|
|
# integration's default channel filter has an escalation chain attached to it
|
|
|
|
|
org, arc = _make_org_and_arc()
|
|
|
|
|
escalation_chain = make_escalation_chain(org)
|
|
|
|
|
make_channel_filter(arc, is_default=True, notify_in_slack=False, escalation_chain=escalation_chain)
|
|
|
|
|
_assert(org, arc)
|
2023-12-22 07:36:54 -05:00
|
|
|
|
|
|
|
|
# integration has more than one channel filter associated with it, nevertheless the integration should only
|
|
|
|
|
# be returned once
|
|
|
|
|
org, arc = _make_org_and_arc()
|
|
|
|
|
make_channel_filter(arc, is_default=True)
|
|
|
|
|
make_channel_filter(arc, is_default=False)
|
|
|
|
|
notifiable_direct_paging_integrations = _assert(org, arc)
|
|
|
|
|
assert notifiable_direct_paging_integrations.count() == 1
|
2024-10-11 14:57:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"is_grafana_irm_enabled,expected",
|
|
|
|
|
[
|
|
|
|
|
(True, PluginID.IRM),
|
|
|
|
|
(False, PluginID.ONCALL),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
@pytest.mark.django_db
|
|
|
|
|
def test_active_ui_plugin_id(make_organization, is_grafana_irm_enabled, expected):
|
|
|
|
|
org = make_organization(is_grafana_irm_enabled=is_grafana_irm_enabled)
|
|
|
|
|
assert org.active_ui_plugin_id == expected
|