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

Fix swap requests event filter limits #2716

Merged
merged 2 commits into from
Aug 1, 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 @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion engine/apps/schedules/models/on_call_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions engine/apps/schedules/tests/test_on_call_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down