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

Exclude schedules from deleted organizations from notification list #2493

Merged
merged 6 commits into from
Jul 11, 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 @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Address issue where we were improperly parsing Grafana feature flags that were enabled via the `feature_flags.enabled`
method by @joeyorlando ([#2477](https://github.com/grafana/oncall/pull/2477))
- Fix cuddled list Markdown issue by @vadimkerr ([#2488](https://github.com/grafana/oncall/pull/2488))
- Fixed schedules slack notifications for deleted organizations ([#2493](https://github.com/grafana/oncall/pull/2493))

## v1.3.7 (2023-07-06)

Expand Down
3 changes: 3 additions & 0 deletions engine/apps/alerts/tasks/notify_ical_schedule_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ def notify_ical_schedule_shift(schedule_pk):
if schedule.organization.slack_team_identity is None:
task_logger.info(f"Trying to notify ical schedule shift with no slack team identity {schedule_pk}")
return
elif schedule.organization.deleted_at:
task_logger.info(f"Trying to notify ical schedule shift from deleted organization {schedule_pk}")
return

MIN_DAYS_TO_LOOKUP_FOR_THE_END_OF_EVENT = 3

Expand Down
4 changes: 2 additions & 2 deletions engine/apps/schedules/tasks/refresh_ical_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def start_refresh_ical_files():

task_logger.info("Start refresh ical files")

schedules = OnCallSchedule.objects.all()
schedules = OnCallSchedule.objects.filter(organization__deleted_at__isnull=True)
for schedule in schedules:
refresh_ical_file.apply_async((schedule.pk,))

Expand All @@ -30,7 +30,7 @@ def start_refresh_ical_final_schedules():

task_logger.info("Start refresh ical final schedules")

schedules = OnCallSchedule.objects.all()
schedules = OnCallSchedule.objects.filter(organization__deleted_at__isnull=True)
for schedule in schedules:
refresh_ical_final_schedule.apply_async((schedule.pk,))

Expand Down
27 changes: 25 additions & 2 deletions engine/apps/schedules/tests/test_tasks_refresh_ical_files.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import datetime
from unittest.mock import patch

import pytest

from apps.schedules.models import OnCallScheduleICal
from apps.schedules.tasks.refresh_ical_files import refresh_ical_file
from apps.schedules.models import OnCallScheduleICal, OnCallScheduleWeb
from apps.schedules.tasks.refresh_ical_files import refresh_ical_file, start_refresh_ical_files


@pytest.mark.django_db
Expand Down Expand Up @@ -56,3 +57,25 @@ def test_refresh_ical_file_trigger_run(

assert mock_notify_empty.apply_async.called == run_task
assert mock_notify_gaps.apply_async.called == run_task


@pytest.mark.django_db
@patch("apps.slack.tasks.start_update_slack_user_group_for_schedules.apply_async")
def test_refresh_ical_files_filter_orgs(
mocked_start_update_slack_user_group_for_schedules,
make_organization,
make_schedule,
):
organization = make_organization()
deleted_organization = make_organization(deleted_at=datetime.datetime.now())

schedule_from_deleted_org = make_schedule(deleted_organization, schedule_class=OnCallScheduleWeb)
schedule = make_schedule(organization, schedule_class=OnCallScheduleWeb)

with patch("apps.schedules.tasks.refresh_ical_file.apply_async") as mocked_refresh_ical_file:
start_refresh_ical_files()
assert mocked_refresh_ical_file.called
called_args = mocked_refresh_ical_file.call_args_list
assert len(called_args) == 1
assert schedule.id in called_args[0].args[0]
assert schedule_from_deleted_org.id not in called_args[0].args[0]