1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-07-23 17:48:30 +00:00

Merge pull request #1465 from metallerok/processing-expand-property

Validation fixes for processing expand property
This commit is contained in:
Peter Bieringer 2024-04-06 10:54:21 +02:00 committed by GitHub
commit 76dc9dce0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 18 deletions

View file

@ -24,9 +24,11 @@ import posixpath
import socket import socket
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from http import client from http import client
from typing import Callable, Iterable, Iterator, Optional, Sequence, Tuple from typing import (Callable, Iterable, Iterator, List, Optional, Sequence,
Tuple, Union)
from urllib.parse import unquote, urlparse from urllib.parse import unquote, urlparse
import vobject.base
from vobject.base import ContentLine from vobject.base import ContentLine
import radicale.item as radicale_item import radicale.item as radicale_item
@ -69,7 +71,7 @@ def xml_report(base_prefix: str, path: str, xml_request: Optional[ET.Element],
xmlutils.make_human_tag(root.tag), path) xmlutils.make_human_tag(root.tag), path)
return client.FORBIDDEN, xmlutils.webdav_error("D:supported-report") return client.FORBIDDEN, xmlutils.webdav_error("D:supported-report")
props = root.find(xmlutils.make_clark("D:prop")) or [] props: Union[ET.Element, List] = root.find(xmlutils.make_clark("D:prop")) or []
hreferences: Iterable[str] hreferences: Iterable[str]
if root.tag in ( if root.tag in (
@ -203,21 +205,21 @@ def _expand(
if rruleset: if rruleset:
recurrences = rruleset.between(start, end) recurrences = rruleset.between(start, end)
expanded = None expanded: vobject.base.Component = copy.copy(expanded_item.vobject_item)
for recurrence_dt in recurrences: is_expanded_filled: bool = False
vobject_item = copy.copy(expanded_item.vobject_item)
for recurrence_dt in recurrences:
recurrence_utc = recurrence_dt.astimezone(datetime.timezone.utc) recurrence_utc = recurrence_dt.astimezone(datetime.timezone.utc)
vevent = copy.deepcopy(vobject_item.vevent) vevent = copy.deepcopy(expanded.vevent)
vevent.recurrence_id = ContentLine( vevent.recurrence_id = ContentLine(
name='RECURRENCE-ID', name='RECURRENCE-ID',
value=recurrence_utc.strftime('%Y%m%dT%H%M%SZ'), params={} value=recurrence_utc.strftime('%Y%m%dT%H%M%SZ'), params={}
) )
if expanded is None: if is_expanded_filled is False:
vobject_item.vevent = vevent expanded.vevent = vevent
expanded = vobject_item is_expanded_filled = True
else: else:
expanded.add(vevent) expanded.add(vevent)

View file

@ -1526,6 +1526,7 @@ permissions: RrWw""")
assert not sync_token assert not sync_token
def test_report_with_expand_property(self) -> None: def test_report_with_expand_property(self) -> None:
"""Test report with expand property"""
self.put("/calendar.ics/", get_file_content("event_daily_rrule.ics")) self.put("/calendar.ics/", get_file_content("event_daily_rrule.ics"))
req_body_without_expand = \ req_body_without_expand = \
"""<?xml version="1.0" encoding="utf-8" ?> """<?xml version="1.0" encoding="utf-8" ?>
@ -1546,21 +1547,22 @@ permissions: RrWw""")
_, responses = self.report("/calendar.ics/", req_body_without_expand) _, responses = self.report("/calendar.ics/", req_body_without_expand)
assert len(responses) == 1 assert len(responses) == 1
response = responses['/calendar.ics/event_daily_rrule.ics'] response_without_expand = responses['/calendar.ics/event_daily_rrule.ics']
status, element = list(response.values())[0] assert not isinstance(response_without_expand, int)
status, element = response_without_expand["C:calendar-data"]
assert status == 200 assert status == 200 and element.text
assert "RRULE" in element.text assert "RRULE" in element.text
assert "BEGIN:VTIMEZONE" in element.text assert "BEGIN:VTIMEZONE" in element.text
assert "RECURRENCE-ID" not in element.text assert "RECURRENCE-ID" not in element.text
uids = [] uids: List[str] = []
for line in element.text.split("\n"): for line in element.text.split("\n"):
if line.startswith("UID:"): if line.startswith("UID:"):
uid = line[len("UID:"):] uid = line[len("UID:"):]
assert uid == "event_daily_rrule" assert uid == "event_daily_rrule"
uids.append(uids) uids.append(uid)
assert len(uids) == 1 assert len(uids) == 1
@ -1586,10 +1588,11 @@ permissions: RrWw""")
assert len(responses) == 1 assert len(responses) == 1
response = responses['/calendar.ics/event_daily_rrule.ics'] response_with_expand = responses['/calendar.ics/event_daily_rrule.ics']
status, element = list(response.values())[0] assert not isinstance(response_with_expand, int)
status, element = response_with_expand["C:calendar-data"]
assert status == 200 assert status == 200 and element.text
assert "RRULE" not in element.text assert "RRULE" not in element.text
assert "BEGIN:VTIMEZONE" not in element.text assert "BEGIN:VTIMEZONE" not in element.text
@ -1598,7 +1601,7 @@ permissions: RrWw""")
for line in element.text.split("\n"): for line in element.text.split("\n"):
if line.startswith("UID:"): if line.startswith("UID:"):
assert line == "UID:event_daily_rrule" assert line == "UID:event_daily_rrule"
uids.append(uids) uids.append(line)
if line.startswith("RECURRENCE-ID:"): if line.startswith("RECURRENCE-ID:"):
recurrence_ids.append(line) recurrence_ids.append(line)