diff --git a/CHANGELOG.md b/CHANGELOG.md index cce7d1ee..8823b5bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fix bug with email case sensitivity for ICal on-call schedules ([1297](https://github.com/grafana/oncall/pull/1297)) + ## v1.1.22 (2023-02-03) ### Fixed diff --git a/engine/apps/schedules/ical_utils.py b/engine/apps/schedules/ical_utils.py index fd6cd341..5680b652 100644 --- a/engine/apps/schedules/ical_utils.py +++ b/engine/apps/schedules/ical_utils.py @@ -72,7 +72,11 @@ def users_in_ical( if users_to_filter is not None: return list( - {user for user in users_to_filter if user.username in usernames_from_ical or user.email in emails_from_ical} + { + user + for user in users_to_filter + if user.username in usernames_from_ical or user.email.lower() in emails_from_ical + } ) users_found_in_ical = organization.users diff --git a/engine/apps/schedules/tests/calendars/override_email_case_sensitivity.ics b/engine/apps/schedules/tests/calendars/override_email_case_sensitivity.ics new file mode 100644 index 00000000..8b6a4430 --- /dev/null +++ b/engine/apps/schedules/tests/calendars/override_email_case_sensitivity.ics @@ -0,0 +1,21 @@ +BEGIN:VCALENDAR +PRODID:-//Google Inc//Google Calendar 70.9054//EN +VERSION:2.0 +CALSCALE:GREGORIAN +METHOD:PUBLISH +X-WR-CALNAME:test +X-WR-TIMEZONE:Europe/London +BEGIN:VEVENT +DTSTART:20230206T110000Z +DTEND:20230206T120000Z +DTSTAMP:20230206T112228Z +UID:16m6o1qji0fdg49coeflc202ss@google.com +CREATED:20230206T112217Z +DESCRIPTION: +LAST-MODIFIED:20230206T112217Z +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:Test@TEST.test +TRANSP:OPAQUE +END:VEVENT +END:VCALENDAR diff --git a/engine/apps/schedules/tests/test_custom_on_call_shift.py b/engine/apps/schedules/tests/test_custom_on_call_shift.py index 7974ad91..47ff1d35 100644 --- a/engine/apps/schedules/tests/test_custom_on_call_shift.py +++ b/engine/apps/schedules/tests/test_custom_on_call_shift.py @@ -1382,6 +1382,37 @@ def test_get_oncall_users_for_multiple_schedules( ) +@pytest.mark.django_db +def test_get_oncall_users_for_multiple_schedules_emails_case_insensitive( + get_ical, + make_organization, + make_user_for_organization, + make_on_call_shift, + make_schedule, +): + """ + Test that emails are case insensitive when matching users to on-call shifts. + https://github.com/grafana/oncall/issues/1296 + """ + organization = make_organization() + + # user's email case is the opposite of the one in the ICal file below (Test@TEST.test) + user = make_user_for_organization(organization, email="tEST@test.TEST") + schedule = make_schedule(organization, schedule_class=OnCallScheduleCalendar) + + # Load ICal file with an event for user with email Test@TEST.test for 6 February 2023, 11:00 UTC - 12:00 UTC + calendar = get_ical("override_email_case_sensitivity.ics") + schedule.cached_ical_file_overrides = calendar.to_ical().decode() + schedule.save(update_fields=["cached_ical_file_overrides"]) + + # Get on-call users for 6 February 2023 11:30 UTC + events_datetime = timezone.datetime(2023, 2, 6, 11, 30, tzinfo=timezone.utc) + schedules = OnCallSchedule.objects.filter(pk=schedule.pk) + oncall_users = schedules.get_oncall_users(events_datetime=events_datetime) + + assert oncall_users == {schedule.pk: [user]} + + @pytest.mark.django_db def test_shift_convert_to_ical(make_organization_and_user, make_on_call_shift): organization, user = make_organization_and_user()