Fix SSR push notifications for deleted orgs (#4868)

following up on https://github.com/grafana/oncall/pull/4813, stop
sending SSR reminders for on-call schedules from deleted orgs
This commit is contained in:
Vadim Stepanov 2024-08-20 12:32:20 +01:00 committed by GitHub
parent a3684a8ddc
commit 68caa12d5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -91,6 +91,24 @@ def test_get_shift_swap_requests_to_notify(make_organization, make_user, make_sc
assert _get_shift_swap_requests_to_notify(swap_start) == []
@pytest.mark.django_db
def test_get_shift_swap_requests_to_notify_deleted_organization(
make_organization, make_user, make_schedule, make_shift_swap_request
):
organization = make_organization()
user = make_user(organization=organization)
schedule = make_schedule(organization, schedule_class=OnCallScheduleWeb)
swap_start = timezone.now()
swap_end = swap_start + timezone.timedelta(days=1)
make_shift_swap_request(
schedule, user, swap_start=swap_start, swap_end=swap_end, created_at=swap_start - timezone.timedelta(days=27)
)
organization.delete()
assert _get_shift_swap_requests_to_notify(swap_start - timezone.timedelta(days=28)) == []
@pytest.mark.django_db
def test_notify_shift_swap_requests(make_organization, make_user, make_schedule, make_shift_swap_request):
organization = make_organization()

View file

@ -48,7 +48,9 @@ class ShiftSwapRequestManager(models.Manager):
return self.get_queryset().hard_delete()
def get_open_requests(self, now):
return self.get_queryset().filter(benefactor__isnull=True, swap_start__gt=now)
return self.get_queryset().filter(
schedule__organization__deleted_at__isnull=True, benefactor__isnull=True, swap_start__gt=now
)
class ShiftSwapRequest(models.Model):