diff --git a/CHANGELOG.md b/CHANGELOG.md index e660e716fc..c0bf94ae84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix schedule final_events datetime filtering when splitting override ([#2715](https://github.com/grafana/oncall/pull/2715)) +- Fix swap requests event filter limits in schedule events ([#2716](https://github.com/grafana/oncall/pull/2716)) ## v1.3.21 (2023-08-01) diff --git a/engine/apps/schedules/models/on_call_schedule.py b/engine/apps/schedules/models/on_call_schedule.py index 28c0dbc311..1c14e39b00 100644 --- a/engine/apps/schedules/models/on_call_schedule.py +++ b/engine/apps/schedules/models/on_call_schedule.py @@ -646,7 +646,7 @@ def _insert_event(index, event): while i < len(events): event = events.pop(i) - if event["start"] > swap.swap_end or event["end"] < swap.swap_start: + if event["start"] >= swap.swap_end or event["end"] <= swap.swap_start: # event outside the swap period, keep as it is and continue i = _insert_event(i, event) continue diff --git a/engine/apps/schedules/tests/test_on_call_schedule.py b/engine/apps/schedules/tests/test_on_call_schedule.py index beb707d8ff..27af60a90c 100644 --- a/engine/apps/schedules/tests/test_on_call_schedule.py +++ b/engine/apps/schedules/tests/test_on_call_schedule.py @@ -2188,18 +2188,25 @@ def test_swap_request_whole_shift( swap_request = make_shift_swap_request( schedule, user, - swap_start=tomorrow + timezone.timedelta(hours=12), - swap_end=tomorrow + timezone.timedelta(hours=15), + # swap request starting right after shift ends + swap_start=tomorrow + timezone.timedelta(hours=15), + # swap request ending right before shift starts + swap_end=tomorrow + timezone.timedelta(days=2, hours=12), ) if swap_taken: swap_request.take(other_user) - events = schedule.filter_events(today, today + timezone.timedelta(days=2)) + events = schedule.filter_events(tomorrow, tomorrow + timezone.timedelta(days=2)) + tomorrow_start = start + timezone.timedelta(days=1) expected = [ # start, end, swap requested - (start, start + duration, False), # today shift unchanged - (start + timezone.timedelta(days=1), start + timezone.timedelta(days=1, hours=3), True), # no splits + (tomorrow_start, tomorrow_start + duration, False), # today shift unchanged + ( + tomorrow_start + timezone.timedelta(days=1), + tomorrow_start + timezone.timedelta(days=1, hours=3), + True, + ), # no splits ] returned = [(e["start"], e["end"], bool(e["users"][0].get("swap_request", False))) for e in events] assert returned == expected