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

Fix slack schedule notification settings dialog #2902

Merged
merged 2 commits into from
Aug 29, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
updated to reflect the latest state by @joeyorlando ([#2886](https://github.com/grafana/oncall/pull/2886))
- Fix issue where Grafana integration would fail to parse alerting config for routes without receivers @mderynck
([#2894](https://github.com/grafana/oncall/pull/2894))
- Fix slack schedule notification settings dialog ([#2902](https://github.com/grafana/oncall/pull/2902))

## v1.3.27 (2023-08-25)

Expand Down
32 changes: 32 additions & 0 deletions engine/apps/slack/tests/test_interactive_api_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from apps.slack.scenarios.manage_responders import ManageRespondersUserChange
from apps.slack.scenarios.paging import OnPagingTeamChange
from apps.slack.scenarios.schedules import EditScheduleShiftNotifyStep
from apps.slack.scenarios.shift_swap_requests import AcceptShiftSwapRequestStep
from apps.slack.types import PayloadType

Expand Down Expand Up @@ -200,6 +201,37 @@ def test_organization_not_found_scenario_doesnt_break_manage_responders(
mock_process_scenario.assert_called_once()


@patch("apps.slack.views.SlackEventApiEndpointView.verify_signature", return_value=True)
@patch.object(EditScheduleShiftNotifyStep, "process_scenario")
@pytest.mark.django_db
def test_organization_not_found_scenario_doesnt_break_edit_schedule_notifications(
mock_edit_schedule_notifications,
_,
make_organization,
make_slack_user_identity,
make_user,
slack_team_identity,
):
"""
Check EditScheduleShiftNotifyStep.process_scenario gets called when a user clicks settings in shift notification.
"""
organization = make_organization(slack_team_identity=slack_team_identity)
slack_user_identity = make_slack_user_identity(slack_team_identity=slack_team_identity, slack_id=SLACK_USER_ID)
make_user(organization=organization, slack_user_identity=slack_user_identity)

response = _make_request(
{
"team_id": SLACK_TEAM_ID,
"user_id": SLACK_USER_ID,
"type": "block_actions",
"actions": [{"action_id": EditScheduleShiftNotifyStep.routing_uid(), "type": "button"}],
}
)

assert response.status_code == status.HTTP_200_OK
mock_edit_schedule_notifications.assert_called_once()


@patch("apps.slack.views.SlackEventApiEndpointView.verify_signature", return_value=True)
@patch.object(AcceptShiftSwapRequestStep, "process_scenario")
@pytest.mark.django_db
Expand Down
13 changes: 11 additions & 2 deletions engine/apps/slack/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ def post(self, request):
payload_user = payload.get("user")
payload_user_id = payload.get("user_id")

edit_schedule_actions = {s["block_action_id"] for s in SCHEDULES_ROUTING}
payload_action_edit_schedule = (
payload_actions[0].get("action_id") in edit_schedule_actions if payload_actions else False
)

payload_event = payload.get("event", {})
payload_event_type = payload_event.get("type")
payload_event_subtype = payload_event.get("subtype")
Expand Down Expand Up @@ -272,8 +277,12 @@ def post(self, request):
# Open pop-up to inform user why OnCall bot doesn't work if any action was triggered
self._open_warning_window_if_needed(payload, slack_team_identity, warning_text)
return Response(status=200)
# direct paging / manual incident dialogs don't require organization to be set
elif organization is None and payload_type_is_block_actions and not payload.get("view"):
# direct paging / manual incident / schedule update dialogs don't require organization to be set
elif (
organization is None
and payload_type_is_block_actions
and not (payload.get("view") or payload_action_edit_schedule)
):
# see this GitHub issue for more context on how this situation can arise
# https://github.com/grafana/oncall-private/issues/1836
warning_text = (
Expand Down