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. `User@gmail.com` in Grafana, `user@gmail.com` in ICal event) The bug was introduced by https://github.com/grafana/oncall/pull/1169 ## Which issue(s) this PR fixes https://github.com/grafana/oncall/issues/1296 ## Checklist - [x] Tests updated - [x] `CHANGELOG.md` updated
This commit is contained in:
parent
1b7ada4315
commit
d40db5a352
4 changed files with 63 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue