Преглед изворни кода

Fixed extraction of time-range filter from request when processing
expand property

Georgiy пре 7 месеци
родитељ
комит
2c4cd32132
2 измењених фајлова са 21 додато и 24 уклоњено
  1. 11 21
      radicale/app/report.py
  2. 10 3
      radicale/tests/test_expand.py

+ 11 - 21
radicale/app/report.py

@@ -233,22 +233,17 @@ def xml_report(base_prefix: str, path: str, xml_request: Optional[ET.Element],
     for filter_ in filters:
         # extract time-range filter for processing after main filters
         # for expand request
-        time_range_element = filter_.find(".//" + xmlutils.make_clark("C:time-range"))
+        filter_copy = copy.deepcopy(filter_)
 
-        if expand is None or time_range_element is None:
-            main_filters.append(filter_)
+        if expand is not None:
+            for comp_filter in filter_copy.findall(".//" + xmlutils.make_clark("C:comp-filter")):
+                if comp_filter.get("name", "").upper() == "VCALENDAR":
+                    continue
+                time_range_element = comp_filter.find(xmlutils.make_clark("C:time-range"))
+                if time_range_element is not None:
+                    comp_filter.remove(time_range_element)
 
-    # Extract requested component types from filters
-    requested_components = set()
-    has_vcalendar_filter = False
-    for filter_ in filters:
-        for comp_filter in filter_.findall(".//" + xmlutils.make_clark("C:comp-filter")):
-            component_name = comp_filter.get("name", "").upper()
-            if component_name:
-                if component_name == "VCALENDAR":
-                    has_vcalendar_filter = True
-                else:
-                    requested_components.add(component_name)
+        main_filters.append(filter_copy)
 
     # Retrieve everything required for finishing the request.
     retrieved_items = list(retrieve_items(
@@ -275,13 +270,6 @@ def xml_report(base_prefix: str, path: str, xml_request: Optional[ET.Element],
                 raise RuntimeError("Failed to filter item %r from %r: %s" %
                                    (item.href, collection.path, e)) from e
 
-        # Skip items that don't match requested component types, unless VCALENDAR filter allows all components
-        if requested_components and not has_vcalendar_filter:
-            if item.component_name not in requested_components:
-                logger.debug("Skipping component %r (type: %s) as it doesn't match requested components %s",
-                             item.href, item.component_name, requested_components)
-                continue
-
         found_props = []
         not_found_props = []
 
@@ -366,6 +354,8 @@ def _expand(
 ) -> Tuple[ET.Element, int]:
     vevent_component: vobject.base.Component = copy.copy(item.vobject_item)
     logger.info("Expanding event %s", item.href)
+    logger.debug(f"Expand range: {start} to {end}")
+    logger.debug(f"Time range: {time_range_start} to {time_range_end}")
 
     # Split the vevents included in the component into one that contains the
     # recurrence information and others that contain a recurrence id to

+ 10 - 3
radicale/tests/test_expand.py

@@ -376,14 +376,21 @@ permissions: RrWw""")
         self.put("/test/calendar.ics", get_file_content("event_daily_rrule.ics"))
         self.put("/test/todo.ics", get_file_content("todo1.ics"))
 
-        request = """
+        start = "20060101T000000Z"
+        end = "20060104T000000Z"
+
+        request = f"""
         <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
             <D:prop>
-                <C:calendar-data/>
+                <C:calendar-data>
+                    <C:expand start="{start}" end="{end}"/>
+                </C:calendar-data>
             </D:prop>
             <C:filter>
                 <C:comp-filter name="VCALENDAR">
-                    <C:comp-filter name="VEVENT"/>
+                    <C:comp-filter name="VEVENT">
+                        <C:time-range start="{start}" end="{end}"/>
+                    </C:comp-filter>
                 </C:comp-filter>
             </C:filter>
         </C:calendar-query>