Просмотр исходного кода

Softly ignore /user/ PROPFIND and REPORT requests (references #181)

Guillaume Ayoub 15 лет назад
Родитель
Сommit
2e1b51e3c1
2 измененных файлов с 21 добавлено и 10 удалено
  1. 5 0
      radicale/__init__.py
  2. 16 10
      radicale/xmlutils.py

+ 5 - 0
radicale/__init__.py

@@ -55,6 +55,11 @@ def _check(request, function):
     """Check if user has sufficient rights for performing ``request``."""
     # ``_check`` decorator can access ``request`` protected functions
     # pylint: disable=W0212
+
+    # If we have no calendar, don't check rights
+    if not request._calendar:
+        return function(request)
+
     authorization = request.headers.get("Authorization", None)
     if authorization:
         challenge = authorization.lstrip("Basic").strip().encode("ascii")

+ 16 - 10
radicale/xmlutils.py

@@ -95,12 +95,15 @@ def propfind(path, xml_request, calendar, depth):
     # Writing answer
     multistatus = ET.Element(_tag("D", "multistatus"))
 
-    if depth == "0":
-        items = [calendar]
+    if calendar:
+        if depth == "0":
+            items = [calendar]
+        else:
+            # depth is 1, infinity or not specified
+            # we limit ourselves to depth == 1
+            items = [calendar] + calendar.events + calendar.todos
     else:
-        # depth is 1, infinity or not specified
-        # we limit ourselves to depth == 1
-        items = [calendar] + calendar.events + calendar.todos
+        items = []
 
     for item in items:
         is_calendar = isinstance(item, ical.Calendar)
@@ -191,12 +194,15 @@ def report(path, xml_request, calendar):
     prop_list = prop_element.getchildren()
     props = [prop.tag for prop in prop_list]
 
-    if root.tag == _tag("C", "calendar-multiget"):
-        # Read rfc4791-7.9 for info
-        hreferences = set((href_element.text for href_element
-                           in root.findall(_tag("D", "href"))))
+    if calendar:
+        if root.tag == _tag("C", "calendar-multiget"):
+            # Read rfc4791-7.9 for info
+            hreferences = set((href_element.text for href_element
+                               in root.findall(_tag("D", "href"))))
+        else:
+            hreferences = (path,)
     else:
-        hreferences = (path,)
+        hreferences = ()
 
     # Writing answer
     multistatus = ET.Element(_tag("D", "multistatus"))