Sfoglia il codice sorgente

Clean owner-less calendars support (fixes #254)

Guillaume Ayoub 15 anni fa
parent
commit
5673444ba7
3 ha cambiato i file con 7 aggiunte e 18 eliminazioni
  1. 3 8
      radicale/__init__.py
  2. 2 1
      radicale/acl/htpasswd.py
  3. 2 9
      radicale/ical.py

+ 3 - 8
radicale/__init__.py

@@ -175,14 +175,9 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler):
         # ``self.path`` must be something like a posix path
         # ``normpath`` should clean malformed and malicious request paths
         attributes = posixpath.normpath(self.path.strip("/")).split("/")
-        if len(attributes) >= 2:
-            path = "%s/%s" % (attributes[0], attributes[1])
-        elif len(attributes) == 1: # no owner
-            path = attributes[0]
-        else:
-            return
-            
-        return ical.Calendar(path)
+        if attributes:
+            path = "/".join(attributes[:min(len(attributes), 2)])
+            return ical.Calendar(path)
 
     def _decode(self, text):
         """Try to decode text according to various parameters."""

+ 2 - 1
radicale/acl/htpasswd.py

@@ -56,7 +56,8 @@ def _sha1(hash_value, password):
 
 def has_right(owner, user, password):
     """Check if ``user``/``password`` couple is valid."""
-    if owner is None: # no owner - everybody is allowed
+    if owner is None and PERSONAL:
+        # No owner and personal calendars, everybody is allowed
         return True
 
     for line in open(FILENAME).readlines():

+ 2 - 9
radicale/ical.py

@@ -135,16 +135,9 @@ class Calendar(object):
 
     def __init__(self, path):
         """Initialize the calendar with ``cal`` and ``user`` parameters."""
-
-        split_path = path.split("/")
-
         self.encoding = "utf-8"
-        
-        if len(split_path) > 1:
-            self.owner = split_path[0]
-        else:
-            self.owner = None
-
+        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.path.sep))
 
     @staticmethod