diff --git a/CHANGELOG.md b/CHANGELOG.md index d7723287..77b3f243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Public API for actions now wraps webhooks @mderynck ([#2790](https://github.com/grafana/oncall/pull/2790)) - Allow mobile app to access status endpoint @mderynck ([#2791](https://github.com/grafana/oncall/pull/2791)) - Enable shifts export endpoint for all schedule types ([#2863](https://github.com/grafana/oncall/pull/2863)) +- Use priority field to track primary/overrides calendar in schedule iCal export ([#2871](https://github.com/grafana/oncall/pull/2871)) ## v1.3.26 (2023-08-22) diff --git a/engine/apps/schedules/constants.py b/engine/apps/schedules/constants.py index 492aa6bb..317a609f 100644 --- a/engine/apps/schedules/constants.py +++ b/engine/apps/schedules/constants.py @@ -13,6 +13,7 @@ ICAL_RRULE = "RRULE" ICAL_UNTIL = "UNTIL" ICAL_LAST_MODIFIED = "LAST-MODIFIED" ICAL_LOCATION = "LOCATION" +ICAL_PRIORITY = "PRIORITY" ICAL_STATUS = "STATUS" ICAL_STATUS_CANCELLED = "CANCELLED" ICAL_COMPONENT_VEVENT = "VEVENT" diff --git a/engine/apps/schedules/ical_utils.py b/engine/apps/schedules/ical_utils.py index bd467c10..5f3c82fa 100644 --- a/engine/apps/schedules/ical_utils.py +++ b/engine/apps/schedules/ical_utils.py @@ -22,6 +22,7 @@ from apps.schedules.constants import ( ICAL_DATETIME_START, ICAL_DESCRIPTION, ICAL_LOCATION, + ICAL_PRIORITY, ICAL_RECURRENCE_ID, ICAL_SEQUENCE, ICAL_STATUS, @@ -218,7 +219,12 @@ def get_shifts_dict( if calendar_type == CALENDAR_TYPE_FINAL: event_calendar_type = ( schedule.OVERRIDES - if event.get(ICAL_LOCATION, "") == schedule.CALENDAR_TYPE_VERBAL[schedule.OVERRIDES] + if ( + event.get(ICAL_PRIORITY, "") == schedule.OVERRIDES + or + # keep for backwards compatibility (to be removed later once schedules are refreshed) + event.get(ICAL_LOCATION, "") == schedule.CALENDAR_TYPE_VERBAL[schedule.OVERRIDES] + ) else schedule.PRIMARY ) # Define on-call shift out of ical event that has the actual user diff --git a/engine/apps/schedules/models/on_call_schedule.py b/engine/apps/schedules/models/on_call_schedule.py index 7c0820f4..c9962aa9 100644 --- a/engine/apps/schedules/models/on_call_schedule.py +++ b/engine/apps/schedules/models/on_call_schedule.py @@ -27,7 +27,7 @@ from apps.schedules.constants import ( ICAL_DATETIME_STAMP, ICAL_DATETIME_START, ICAL_LAST_MODIFIED, - ICAL_LOCATION, + ICAL_PRIORITY, ICAL_STATUS, ICAL_STATUS_CANCELLED, ICAL_SUMMARY, @@ -461,7 +461,9 @@ class OnCallSchedule(PolymorphicModel): event.add(ICAL_DATETIME_END, e["end"]) event.add(ICAL_DATETIME_STAMP, now) event.add(ICAL_LAST_MODIFIED, now) - event.add(ICAL_LOCATION, self.CALENDAR_TYPE_VERBAL.get(e["calendar_type"], "")) + # set priority based on primary/overrides + # 0: undefined priority, 1: high priority + event.add(ICAL_PRIORITY, e["calendar_type"]) event_uid = "{}-{}-{}".format(e["shift"]["pk"], e["start"].strftime("%Y%m%d%H%S"), u["pk"]) event[ICAL_UID] = event_uid calendar.add_component(event) diff --git a/engine/apps/schedules/tests/test_on_call_schedule.py b/engine/apps/schedules/tests/test_on_call_schedule.py index aeafe782..11fce2ed 100644 --- a/engine/apps/schedules/tests/test_on_call_schedule.py +++ b/engine/apps/schedules/tests/test_on_call_schedule.py @@ -13,7 +13,7 @@ from apps.schedules.constants import ( ICAL_DATETIME_END, ICAL_DATETIME_START, ICAL_LAST_MODIFIED, - ICAL_LOCATION, + ICAL_PRIORITY, ICAL_STATUS, ICAL_STATUS_CANCELLED, ICAL_SUMMARY, @@ -1663,25 +1663,25 @@ def test_refresh_ical_final_schedule_ok( u1.username, today, today + timezone.timedelta(seconds=(12 * 60 * 60) - 1), - OnCallSchedule.CALENDAR_TYPE_VERBAL[OnCallSchedule.PRIMARY], + OnCallSchedule.PRIMARY, ), ( u2.username, today + timezone.timedelta(hours=12), today + timezone.timedelta(hours=22), - OnCallSchedule.CALENDAR_TYPE_VERBAL[OnCallSchedule.PRIMARY], + OnCallSchedule.PRIMARY, ), ( u1.username, today + timezone.timedelta(hours=22), today + timezone.timedelta(hours=23), - OnCallSchedule.CALENDAR_TYPE_VERBAL[OnCallSchedule.OVERRIDES], + OnCallSchedule.OVERRIDES, ), ( u2.username, today + timezone.timedelta(hours=23), today + timezone.timedelta(seconds=(24 * 60 * 60) - 1), - OnCallSchedule.CALENDAR_TYPE_VERBAL[OnCallSchedule.PRIMARY], + OnCallSchedule.PRIMARY, ), } @@ -1699,7 +1699,7 @@ def test_refresh_ical_final_schedule_ok( component[ICAL_SUMMARY], component[ICAL_DATETIME_START].dt, component[ICAL_DATETIME_END].dt, - component[ICAL_LOCATION], + component[ICAL_PRIORITY], ) assert event in expected_events