Ver código fonte

iCal bootstrapping using a default URL works

Lukasz Langa 14 anos atrás
pai
commit
f7868afed1
3 arquivos alterados com 12 adições e 6 exclusões
  1. 2 1
      radicale/__init__.py
  2. 1 1
      radicale/ical.py
  3. 9 4
      radicale/xmlutils.py

+ 2 - 1
radicale/__init__.py

@@ -169,6 +169,7 @@ class Application(object):
                 auth = authorization.lstrip("Basic").strip().encode("ascii")
                 user, password = self.decode(
                     base64.b64decode(auth), environ).split(":")
+                environ['USER'] = user
             else:
                 user = password = None
 
@@ -290,7 +291,7 @@ class Application(object):
             "DAV": "1, calendar-access",
             "Content-Type": "text/xml"}
         answer = xmlutils.propfind(
-            environ["PATH_INFO"], content, calendars)
+            environ["PATH_INFO"], content, calendars, environ.get("USER"))
         return client.MULTI_STATUS, headers, answer
 
     def proppatch(self, environ, calendars, content):

+ 1 - 1
radicale/ical.py

@@ -162,7 +162,7 @@ class Calendar(object):
         split_path = path.split("/")
         self.owner = split_path[0] if len(split_path) > 1 else None
         self.path = os.path.join(FOLDER, path.replace("/", os.sep))
-        self.local_path = path
+        self.local_path = path if path != '.' else ''
         self.is_principal = principal
 
     @classmethod

+ 9 - 4
radicale/xmlutils.py

@@ -167,7 +167,7 @@ def delete(path, calendar):
     return _pretty_xml(multistatus)
 
 
-def propfind(path, xml_request, calendars):
+def propfind(path, xml_request, calendars, user=None):
     """Read and answer PROPFIND requests.
 
     Read rfc4918-9.1 for info.
@@ -183,13 +183,13 @@ def propfind(path, xml_request, calendars):
     multistatus = ET.Element(_tag("D", "multistatus"))
 
     for calendar in calendars:
-        response = _propfind_response(path, calendar, props)
+        response = _propfind_response(path, calendar, props, user)
         multistatus.append(response)
 
     return _pretty_xml(multistatus)
 
 
-def _propfind_response(path, item, props):
+def _propfind_response(path, item, props, user):
     is_calendar = isinstance(item, ical.Calendar)
     if is_calendar:
         with item.props as cal_props:
@@ -217,10 +217,11 @@ def _propfind_response(path, item, props):
         if tag == _tag("D", "getetag"):
             element.text = item.etag
         elif tag == _tag("D", "principal-URL"):
-            # TODO: use a real principal URL, read rfc3744-4.2 for info
             tag = ET.Element(_tag("D", "href"))
             if item.owner_url:
                 tag.text = item.owner_url
+            elif user:
+                tag.text = '/{}/'.format(user)
             else:
                 tag.text = path
             element.append(tag)
@@ -239,6 +240,10 @@ def _propfind_response(path, item, props):
                 comp.set("name", component)
                 element.append(comp)
             # pylint: enable=W0511
+        elif tag == _tag("D", "current-user-principal") and user:
+            tag = ET.Element(_tag("D", "href"))
+            tag.text = '/{}/'.format(user)
+            element.append(tag)
         elif tag == _tag("D", "current-user-privilege-set"):
             privilege = ET.Element(_tag("D", "privilege"))
             privilege.append(ET.Element(_tag("D", "all")))