-
Notifications
You must be signed in to change notification settings - Fork 113
fix(jmap): correctness fixes + dedup from June 2026 review #688
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
Open
tobixen
wants to merge
1
commit into
master
Choose a base branch
from
jmap-code-review-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """ | ||
| RFC 8620 PatchObject helpers for CalendarEvent/set update calls. | ||
|
|
||
| When updating an event, absent keys preserve the server's current value. | ||
| To delete an optional property the patch must set it to null explicitly. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| # Optional JSCalendar top-level properties that must be explicitly nulled in | ||
| # a CalendarEvent/set update when they are absent from the converted result. | ||
| # This ensures properties removed client-side (e.g. LOCATION deleted from | ||
| # the iCalendar) are actually removed on the server, not silently preserved. | ||
| _NULL_FOR_UPDATE: frozenset[str] = frozenset( | ||
| { | ||
| "description", | ||
| "color", | ||
| "locations", | ||
| "keywords", | ||
| "priority", | ||
| "privacy", | ||
| "freeBusyStatus", | ||
| "status", | ||
| "sequence", | ||
| "showWithoutTime", | ||
| "timeZone", | ||
| "recurrenceRules", | ||
| "excludedRecurrenceRules", | ||
| "recurrenceOverrides", | ||
| "participants", | ||
| "alerts", | ||
| } | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,12 +12,40 @@ | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import uuid | ||||||||||||||||||||||||||||||||
| from datetime import date, datetime, timedelta | ||||||||||||||||||||||||||||||||
| from zoneinfo import ZoneInfo, ZoneInfoNotFoundError | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import icalendar | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| from caldav.jmap.convert._utils import _format_local_dt, _timedelta_to_duration | ||||||||||||||||||||||||||||||||
| from caldav.lib import vcal | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # RFC 5545 STATUS -> RFC 8984 status; module-level constant (cf. _CLASS_MAP etc.) | ||||||||||||||||||||||||||||||||
| _STATUS_ICAL_TO_JSCAL = { | ||||||||||||||||||||||||||||||||
| "CONFIRMED": "confirmed", | ||||||||||||||||||||||||||||||||
| "TENTATIVE": "tentative", | ||||||||||||||||||||||||||||||||
| "CANCELLED": "cancelled", | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def _to_event_local(dt, time_zone): | ||||||||||||||||||||||||||||||||
| """Shift a tz-aware datetime to naive wall-clock in the event's timeZone. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| RFC 8984 LocalDateTime values (RRULE ``until``, EXDATE override keys) are | ||||||||||||||||||||||||||||||||
| expressed in the recurring event's own time zone. A UTC UNTIL/EXDATE on a | ||||||||||||||||||||||||||||||||
| TZID event must therefore be converted to that zone before being formatted | ||||||||||||||||||||||||||||||||
| as a (suffix-less) LocalDateTime, otherwise the series ends at the wrong | ||||||||||||||||||||||||||||||||
| wall-clock time and the round-trip emits a Z-less UNTIL that RFC 5545 | ||||||||||||||||||||||||||||||||
| §3.3.10 forbids for TZID events. Floating / all-day / naive values (and | ||||||||||||||||||||||||||||||||
| unknown time zones) pass through unchanged. | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| if time_zone and isinstance(dt, datetime) and dt.tzinfo is not None: | ||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||
| return dt.astimezone(ZoneInfo(time_zone)).replace(tzinfo=None) | ||||||||||||||||||||||||||||||||
| except ZoneInfoNotFoundError: | ||||||||||||||||||||||||||||||||
| return dt | ||||||||||||||||||||||||||||||||
| return dt | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| _CLASS_MAP = { | ||||||||||||||||||||||||||||||||
| "PRIVATE": "private", | ||||||||||||||||||||||||||||||||
| "CONFIDENTIAL": "secret", | ||||||||||||||||||||||||||||||||
|
|
@@ -68,11 +96,14 @@ def _dtstart_to_jscal(dtstart_prop) -> tuple[str, str | None, bool]: | |||||||||||||||||||||||||||||||
| return dt.strftime("%Y-%m-%dT%H:%M:%S"), None, False | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def _rrule_to_jscal(rrule_prop) -> dict: | ||||||||||||||||||||||||||||||||
| def _rrule_to_jscal(rrule_prop, time_zone=None) -> dict: | ||||||||||||||||||||||||||||||||
| """Convert an iCalendar RRULE property to a JSCalendar RecurrenceRule dict. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Always emits @type, interval, rscale, skip, firstDayOfWeek to match the | ||||||||||||||||||||||||||||||||
| fields Cyrus returns — makes round-trip comparison predictable. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ``time_zone`` is the event's IANA time zone; a UTC ``UNTIL`` is shifted to | ||||||||||||||||||||||||||||||||
| it so the LocalDateTime value matches the event frame (see _to_event_local). | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| rule: dict = { | ||||||||||||||||||||||||||||||||
| "@type": "RecurrenceRule", | ||||||||||||||||||||||||||||||||
|
|
@@ -97,7 +128,7 @@ def _rrule_to_jscal(rrule_prop) -> dict: | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| until_list = rrule_prop.get("UNTIL", []) | ||||||||||||||||||||||||||||||||
| if until_list: | ||||||||||||||||||||||||||||||||
| rule["until"] = _format_local_dt(until_list[0]) | ||||||||||||||||||||||||||||||||
| rule["until"] = _format_local_dt(_to_event_local(until_list[0], time_zone)) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| byday_list = rrule_prop.get("BYDAY", []) | ||||||||||||||||||||||||||||||||
| if byday_list: | ||||||||||||||||||||||||||||||||
|
|
@@ -145,9 +176,12 @@ def _rrule_to_jscal(rrule_prop) -> dict: | |||||||||||||||||||||||||||||||
| return rule | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def _exdate_to_overrides(exdate_prop) -> dict: | ||||||||||||||||||||||||||||||||
| def _exdate_to_overrides(exdate_prop, time_zone=None) -> dict: | ||||||||||||||||||||||||||||||||
| """Convert an EXDATE property (single or list) to recurrenceOverrides entries. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ``time_zone`` is the event's IANA time zone; a UTC EXDATE is shifted to it | ||||||||||||||||||||||||||||||||
| so the override key matches the occurrence key (see _to_event_local). | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||
| Dict mapping LocalDateTime/UTCDateTime string → {"excluded": True} | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
|
|
@@ -160,7 +194,7 @@ def _exdate_to_overrides(exdate_prop) -> dict: | |||||||||||||||||||||||||||||||
| dts = getattr(ex, "dts", [ex]) | ||||||||||||||||||||||||||||||||
| for dt_prop in dts: | ||||||||||||||||||||||||||||||||
| dt = getattr(dt_prop, "dt", dt_prop) | ||||||||||||||||||||||||||||||||
| overrides[_format_local_dt(dt)] = {"excluded": True} | ||||||||||||||||||||||||||||||||
| overrides[_format_local_dt(_to_event_local(dt, time_zone))] = {"excluded": True} | ||||||||||||||||||||||||||||||||
| return overrides | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -386,6 +420,12 @@ def ical_to_jscal(ical_str: str, calendar_id: str | None = None) -> dict: | |||||||||||||||||||||||||||||||
| if location: | ||||||||||||||||||||||||||||||||
| jscal["locations"] = _location_str_to_jscal(str(location)) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| status = master.get("STATUS") | ||||||||||||||||||||||||||||||||
| if status: | ||||||||||||||||||||||||||||||||
| jscal_status = _STATUS_ICAL_TO_JSCAL.get(str(status).upper()) | ||||||||||||||||||||||||||||||||
| if jscal_status: | ||||||||||||||||||||||||||||||||
| jscal["status"] = jscal_status | ||||||||||||||||||||||||||||||||
|
Comment on lines
+423
to
+427
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue:
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| participants: dict = {} | ||||||||||||||||||||||||||||||||
| organizer = master.get("ORGANIZER") | ||||||||||||||||||||||||||||||||
| if organizer is not None: | ||||||||||||||||||||||||||||||||
|
|
@@ -411,19 +451,19 @@ def ical_to_jscal(ical_str: str, calendar_id: str | None = None) -> dict: | |||||||||||||||||||||||||||||||
| if rrules is not None: | ||||||||||||||||||||||||||||||||
| if not isinstance(rrules, list): | ||||||||||||||||||||||||||||||||
| rrules = [rrules] | ||||||||||||||||||||||||||||||||
| jscal["recurrenceRules"] = [_rrule_to_jscal(r) for r in rrules] | ||||||||||||||||||||||||||||||||
| jscal["recurrenceRules"] = [_rrule_to_jscal(r, time_zone) for r in rrules] | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| exrules = master.get("EXRULE") | ||||||||||||||||||||||||||||||||
| if exrules is not None: | ||||||||||||||||||||||||||||||||
| if not isinstance(exrules, list): | ||||||||||||||||||||||||||||||||
| exrules = [exrules] | ||||||||||||||||||||||||||||||||
| jscal["excludedRecurrenceRules"] = [_rrule_to_jscal(r) for r in exrules] | ||||||||||||||||||||||||||||||||
| jscal["excludedRecurrenceRules"] = [_rrule_to_jscal(r, time_zone) for r in exrules] | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| recurrence_overrides: dict = {} | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| exdate = master.get("EXDATE") | ||||||||||||||||||||||||||||||||
| if exdate is not None: | ||||||||||||||||||||||||||||||||
| recurrence_overrides.update(_exdate_to_overrides(exdate)) | ||||||||||||||||||||||||||||||||
| recurrence_overrides.update(_exdate_to_overrides(exdate, time_zone)) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for rid_key, child in overrides_by_recurrence_id.items(): | ||||||||||||||||||||||||||||||||
| # Build a patch: only fields that differ from the master | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.