Skip to content

Commit d40db5a

Browse files
authored
Make emails case-insensitive for ICal schedules (#1297)
# What this PR does Fixes a bug when current on-call users for web UI and Slack user group are incorrect. This happens when both conditions below are true: - Using an ICal schedule - Email of a user in Grafana has a different case than an event in ICal (e.g. `[email protected]` in Grafana, `[email protected]` in ICal event) The bug was introduced by #1169 ## Which issue(s) this PR fixes #1296 ## Checklist - [x] Tests updated - [x] `CHANGELOG.md` updated
1 parent 1b7ada4 commit d40db5a

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Fix bug with email case sensitivity for ICal on-call schedules ([1297](https://github.com/grafana/oncall/pull/1297))
13+
814
## v1.1.22 (2023-02-03)
915

1016
### Fixed

engine/apps/schedules/ical_utils.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ def users_in_ical(
7272

7373
if users_to_filter is not None:
7474
return list(
75-
{user for user in users_to_filter if user.username in usernames_from_ical or user.email in emails_from_ical}
75+
{
76+
user
77+
for user in users_to_filter
78+
if user.username in usernames_from_ical or user.email.lower() in emails_from_ical
79+
}
7680
)
7781

7882
users_found_in_ical = organization.users
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
BEGIN:VCALENDAR
2+
PRODID:-//Google Inc//Google Calendar 70.9054//EN
3+
VERSION:2.0
4+
CALSCALE:GREGORIAN
5+
METHOD:PUBLISH
6+
X-WR-CALNAME:test
7+
X-WR-TIMEZONE:Europe/London
8+
BEGIN:VEVENT
9+
DTSTART:20230206T110000Z
10+
DTEND:20230206T120000Z
11+
DTSTAMP:20230206T112228Z
12+
13+
CREATED:20230206T112217Z
14+
DESCRIPTION:
15+
LAST-MODIFIED:20230206T112217Z
16+
SEQUENCE:0
17+
STATUS:CONFIRMED
18+
19+
TRANSP:OPAQUE
20+
END:VEVENT
21+
END:VCALENDAR

engine/apps/schedules/tests/test_custom_on_call_shift.py

+31
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,37 @@ def _extract_oncall_users_from_schedules(schedules):
13821382
)
13831383

13841384

1385+
@pytest.mark.django_db
1386+
def test_get_oncall_users_for_multiple_schedules_emails_case_insensitive(
1387+
get_ical,
1388+
make_organization,
1389+
make_user_for_organization,
1390+
make_on_call_shift,
1391+
make_schedule,
1392+
):
1393+
"""
1394+
Test that emails are case insensitive when matching users to on-call shifts.
1395+
https://github.com/grafana/oncall/issues/1296
1396+
"""
1397+
organization = make_organization()
1398+
1399+
# user's email case is the opposite of the one in the ICal file below ([email protected])
1400+
user = make_user_for_organization(organization, email="[email protected]")
1401+
schedule = make_schedule(organization, schedule_class=OnCallScheduleCalendar)
1402+
1403+
# Load ICal file with an event for user with email [email protected] for 6 February 2023, 11:00 UTC - 12:00 UTC
1404+
calendar = get_ical("override_email_case_sensitivity.ics")
1405+
schedule.cached_ical_file_overrides = calendar.to_ical().decode()
1406+
schedule.save(update_fields=["cached_ical_file_overrides"])
1407+
1408+
# Get on-call users for 6 February 2023 11:30 UTC
1409+
events_datetime = timezone.datetime(2023, 2, 6, 11, 30, tzinfo=timezone.utc)
1410+
schedules = OnCallSchedule.objects.filter(pk=schedule.pk)
1411+
oncall_users = schedules.get_oncall_users(events_datetime=events_datetime)
1412+
1413+
assert oncall_users == {schedule.pk: [user]}
1414+
1415+
13851416
@pytest.mark.django_db
13861417
def test_shift_convert_to_ical(make_organization_and_user, make_on_call_shift):
13871418
organization, user = make_organization_and_user()

0 commit comments

Comments
 (0)