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

Handle date values coming from ical in final schedule caching #2025

Merged
merged 2 commits into from
May 25, 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 error when updating closed modal window in Slack by @vadimkerr ([#2019](https://github.com/grafana/oncall/pull/2019))
- Fix final schedule export failing to update when ical imported events set start/end as date ([#2025](https://github.com/grafana/oncall/pull/2025))

## v1.2.30 (2023-05-25)

Expand Down
8 changes: 7 additions & 1 deletion engine/apps/schedules/models/on_call_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,13 @@ def refresh_ical_final_schedule(self):
if component.name == ICAL_COMPONENT_VEVENT and component[ICAL_UID] not in updated_ids:
# check if event was ended or cancelled, update ical
dtend = component.get(ICAL_DATETIME_END)
if dtend and dtend.dt < starting_datetime:
dtend_datetime = dtend.dt if dtend else None
if dtend_datetime and type(dtend_datetime) == datetime.date:
# shift or overrides coming from ical calendars can be all day events, change to datetime
dtend_datetime = datetime.datetime.combine(
dtend.dt, datetime.datetime.min.time(), tzinfo=pytz.UTC
)
if dtend_datetime and dtend_datetime < starting_datetime:
# event ended before window start
continue
is_cancelled = component.get(ICAL_STATUS)
Expand Down
46 changes: 45 additions & 1 deletion engine/apps/schedules/tests/test_on_call_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,51 @@ def test_refresh_ical_final_schedule_event_in_the_past(

schedule.refresh_ical_final_schedule()

# check old event is dropped, recent one is kept unchanged
# check old event is dropped
calendar = icalendar.Calendar.from_ical(schedule.cached_ical_final_schedule)
events = [component for component in calendar.walk() if component.name == ICAL_COMPONENT_VEVENT]
assert len(events) == 0


@pytest.mark.django_db
def test_refresh_ical_final_schedule_all_day_date_event(
make_organization,
make_user_for_organization,
make_schedule,
):
organization = make_organization()
u1 = make_user_for_organization(organization)
cached_ical_final_schedule = textwrap.dedent(
"""
BEGIN:VCALENDAR
VERSION:2.0
PRODID://Grafana Labs//Grafana On-Call//
CALSCALE:GREGORIAN
X-WR-CALNAME:Cup cut.
X-WR-TIMEZONE:UTC
BEGIN:VEVENT
SUMMARY:{}
DTSTART;VALUE=DATE:20221203
DTEND;VALUE=DATE:20221205
DTSTAMP;VALUE=DATE-TIME:20220414T190951Z
UID:O231U3VXVIYRX-202304140000-U5FWIHEASEWS2
LAST-MODIFIED;VALUE=DATE-TIME:20220414T190951Z
END:VEVENT
END:VCALENDAR
""".format(
u1.username
)
)

schedule = make_schedule(
organization,
schedule_class=OnCallScheduleWeb,
cached_ical_final_schedule=cached_ical_final_schedule,
)

schedule.refresh_ical_final_schedule()

# check old event is dropped
calendar = icalendar.Calendar.from_ical(schedule.cached_ical_final_schedule)
events = [component for component in calendar.walk() if component.name == ICAL_COMPONENT_VEVENT]
assert len(events) == 0