Fix returned shift PK in current user events endpoint (#3036)
This commit is contained in:
parent
69fcb58408
commit
78849d2e43
5 changed files with 33 additions and 14 deletions
|
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Fixed
|
||||
|
||||
- Fix Slack access token length issue by @toolchainX ([#3016](https://github.com/grafana/oncall/pull/3016))
|
||||
- Fix shifts for current user internal endpoint to return the right shift PK ([#3036](https://github.com/grafana/oncall/pull/3036))
|
||||
|
||||
## v1.3.37 (2023-09-12)
|
||||
|
||||
|
|
|
|||
|
|
@ -2115,8 +2115,8 @@ def test_current_user_events(
|
|||
|
||||
shifts = (
|
||||
# schedule, user, priority, start time (h), duration (seconds)
|
||||
(schedule_with_current_user, current_user, 1, 0, (24 * 60 * 60) - 1), # r1-1: 0-23:59:59
|
||||
(other_schedule, other_user, 1, 0, (24 * 60 * 60) - 1), # r1-1: 0-23:59:59
|
||||
(schedule_with_current_user, current_user, 1, 0, (24 * 60 * 60) - 1), # r1-1: 0-23:59:59
|
||||
)
|
||||
now = timezone.now()
|
||||
today = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
|
@ -2146,6 +2146,9 @@ def test_current_user_events(
|
|||
assert result["schedules"][0]["id"] == schedule_with_current_user.public_primary_key
|
||||
assert result["schedules"][0]["name"] == schedule_with_current_user.name
|
||||
assert len(result["schedules"][0]["events"]) > 0
|
||||
for event in result["schedules"][0]["events"]:
|
||||
# check the current user shift pk is set in the event
|
||||
assert event["shift"]["pk"] == on_call_shift.public_primary_key
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ ICAL_STATUS = "STATUS"
|
|||
ICAL_STATUS_CANCELLED = "CANCELLED"
|
||||
ICAL_COMPONENT_VEVENT = "VEVENT"
|
||||
RE_PRIORITY = re.compile(r"^\[L(\d+)\]")
|
||||
RE_EVENT_UID_EXPORT = re.compile(r"([\w\d]+)-(\d+)-([\w\d]+)")
|
||||
RE_EVENT_UID_V1 = re.compile(r"amixr-([\w\d-]+)-U(\d+)-E(\d+)-S(\d+)")
|
||||
RE_EVENT_UID_V2 = re.compile(r"oncall-([\w\d-]+)-PK([\w\d]+)-U(\d+)-E(\d+)-S(\d+)")
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ from apps.schedules.constants import (
|
|||
ICAL_STATUS_CANCELLED,
|
||||
ICAL_SUMMARY,
|
||||
ICAL_UID,
|
||||
RE_EVENT_UID_EXPORT,
|
||||
RE_EVENT_UID_V1,
|
||||
RE_EVENT_UID_V2,
|
||||
RE_PRIORITY,
|
||||
|
|
@ -421,21 +422,25 @@ def parse_event_uid(string: str, sequence: str = None, recurrence_id: str = None
|
|||
if match:
|
||||
_, pk, _, _, source = match.groups()
|
||||
else:
|
||||
# eventually this path would be automatically deprecated
|
||||
# once all ical representations are refreshed
|
||||
match = RE_EVENT_UID_V1.match(string)
|
||||
match = RE_EVENT_UID_EXPORT.match(string)
|
||||
if match:
|
||||
_, _, _, source = match.groups()
|
||||
pk, _, _ = match.groups()
|
||||
else:
|
||||
# fallback to use the UID string as the rotation ID
|
||||
pk = string
|
||||
# in ical imported calendars, sequence and/or recurrence_id
|
||||
# distinguish main recurring event vs instance modification
|
||||
# (see https://icalendar.org/iCalendar-RFC-5545/3-8-4-4-recurrence-id.html)
|
||||
if sequence:
|
||||
pk = f"{pk}_{sequence}"
|
||||
if recurrence_id:
|
||||
pk = f"{pk}_{recurrence_id}"
|
||||
# eventually this path would be automatically deprecated
|
||||
# once all ical representations are refreshed
|
||||
match = RE_EVENT_UID_V1.match(string)
|
||||
if match:
|
||||
_, _, _, source = match.groups()
|
||||
else:
|
||||
# fallback to use the UID string as the rotation ID
|
||||
pk = string
|
||||
# in ical imported calendars, sequence and/or recurrence_id
|
||||
# distinguish main recurring event vs instance modification
|
||||
# (see https://icalendar.org/iCalendar-RFC-5545/3-8-4-4-recurrence-id.html)
|
||||
if sequence:
|
||||
pk = f"{pk}_{sequence}"
|
||||
if recurrence_id:
|
||||
pk = f"{pk}_{recurrence_id}"
|
||||
|
||||
if source is not None:
|
||||
source = int(source)
|
||||
|
|
|
|||
|
|
@ -317,6 +317,15 @@ def test_shifts_dict_from_cached_final(
|
|||
assert shifts == expected_events
|
||||
|
||||
|
||||
def test_parse_event_uid_from_export():
|
||||
shift_pk = "OUCE6WAHL35PP"
|
||||
user_pk = "UHZ38D6AQXXBY"
|
||||
event_uid = f"{shift_pk}-202309200300-{user_pk}"
|
||||
pk, source = parse_event_uid(event_uid)
|
||||
assert pk == shift_pk
|
||||
assert source is None
|
||||
|
||||
|
||||
def test_parse_event_uid_v1():
|
||||
uuid = uuid4()
|
||||
event_uid = f"amixr-{uuid}-U1-E2-S1"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue