Skip to content

Commit 0e75be9

Browse files
authored
Fix slack schedule notification settings dialog (#2902)
Fixes #2647
1 parent 65bceaa commit 0e75be9

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
updated to reflect the latest state by @joeyorlando ([#2886](https://github.com/grafana/oncall/pull/2886))
2424
- Fix issue where Grafana integration would fail to parse alerting config for routes without receivers @mderynck
2525
([#2894](https://github.com/grafana/oncall/pull/2894))
26+
- Fix slack schedule notification settings dialog ([#2902](https://github.com/grafana/oncall/pull/2902))
2627

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

engine/apps/slack/tests/test_interactive_api_endpoint.py

+32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from apps.slack.scenarios.manage_responders import ManageRespondersUserChange
1010
from apps.slack.scenarios.paging import OnPagingTeamChange
11+
from apps.slack.scenarios.schedules import EditScheduleShiftNotifyStep
1112
from apps.slack.scenarios.shift_swap_requests import AcceptShiftSwapRequestStep
1213
from apps.slack.types import PayloadType
1314

@@ -200,6 +201,37 @@ def test_organization_not_found_scenario_doesnt_break_manage_responders(
200201
mock_process_scenario.assert_called_once()
201202

202203

204+
@patch("apps.slack.views.SlackEventApiEndpointView.verify_signature", return_value=True)
205+
@patch.object(EditScheduleShiftNotifyStep, "process_scenario")
206+
@pytest.mark.django_db
207+
def test_organization_not_found_scenario_doesnt_break_edit_schedule_notifications(
208+
mock_edit_schedule_notifications,
209+
_,
210+
make_organization,
211+
make_slack_user_identity,
212+
make_user,
213+
slack_team_identity,
214+
):
215+
"""
216+
Check EditScheduleShiftNotifyStep.process_scenario gets called when a user clicks settings in shift notification.
217+
"""
218+
organization = make_organization(slack_team_identity=slack_team_identity)
219+
slack_user_identity = make_slack_user_identity(slack_team_identity=slack_team_identity, slack_id=SLACK_USER_ID)
220+
make_user(organization=organization, slack_user_identity=slack_user_identity)
221+
222+
response = _make_request(
223+
{
224+
"team_id": SLACK_TEAM_ID,
225+
"user_id": SLACK_USER_ID,
226+
"type": "block_actions",
227+
"actions": [{"action_id": EditScheduleShiftNotifyStep.routing_uid(), "type": "button"}],
228+
}
229+
)
230+
231+
assert response.status_code == status.HTTP_200_OK
232+
mock_edit_schedule_notifications.assert_called_once()
233+
234+
203235
@patch("apps.slack.views.SlackEventApiEndpointView.verify_signature", return_value=True)
204236
@patch.object(AcceptShiftSwapRequestStep, "process_scenario")
205237
@pytest.mark.django_db

engine/apps/slack/views.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ def post(self, request):
143143
payload_user = payload.get("user")
144144
payload_user_id = payload.get("user_id")
145145

146+
edit_schedule_actions = {s["block_action_id"] for s in SCHEDULES_ROUTING}
147+
payload_action_edit_schedule = (
148+
payload_actions[0].get("action_id") in edit_schedule_actions if payload_actions else False
149+
)
150+
146151
payload_event = payload.get("event", {})
147152
payload_event_type = payload_event.get("type")
148153
payload_event_subtype = payload_event.get("subtype")
@@ -272,8 +277,12 @@ def post(self, request):
272277
# Open pop-up to inform user why OnCall bot doesn't work if any action was triggered
273278
self._open_warning_window_if_needed(payload, slack_team_identity, warning_text)
274279
return Response(status=200)
275-
# direct paging / manual incident dialogs don't require organization to be set
276-
elif organization is None and payload_type_is_block_actions and not payload.get("view"):
280+
# direct paging / manual incident / schedule update dialogs don't require organization to be set
281+
elif (
282+
organization is None
283+
and payload_type_is_block_actions
284+
and not (payload.get("view") or payload_action_edit_schedule)
285+
):
277286
# see this GitHub issue for more context on how this situation can arise
278287
# https://github.com/grafana/oncall-private/issues/1836
279288
warning_text = (

0 commit comments

Comments
 (0)