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

Make emails case-insensitive for ICal schedules #1297

Merged
merged 3 commits into from
Feb 6, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion engine/apps/schedules/ical_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions engine/apps/schedules/tests/test_custom_on_call_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,37 @@ def _extract_oncall_users_from_schedules(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()
Expand Down