Skip to content

Commit

Permalink
Fix slack schedule notification settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasb committed Aug 29, 2023
1 parent 65bceaa commit 9bc1be2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
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

0 comments on commit 9bc1be2

Please sign in to comment.