diff --git a/radicale/__init__.py b/radicale/__init__.py index b79a1be..4115852 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -429,7 +429,7 @@ class Application(object): props = xmlutils.props_from_request(content) # TODO: use this? # timezone = props.get("C:calendar-timezone") - collection = storage.create_collection( + collection = storage.Collection.create_collection( collection.path, tag="VCALENDAR") for key, value in props.items(): collection.set_meta(key, value) @@ -444,7 +444,7 @@ class Application(object): collection = write_collections[0] props = xmlutils.props_from_request(content) - collection = storage.create_collection(collection.path) + collection = storage.Collection.create_collection(collection.path) for key, value in props.items(): collection.set_meta(key, value) return client.CREATED, {}, None diff --git a/radicale/rights.py b/radicale/rights.py index 9c40bc5..ff9c03c 100644 --- a/radicale/rights.py +++ b/radicale/rights.py @@ -127,7 +127,7 @@ def authorized(user, collection, permission): If the user is empty, check for anonymous rights. """ - collection_url = collection.url.rstrip("/") or "/" + collection_url = collection.path.rstrip("/") or "/" if collection_url in (".well-known/carddav", ".well-known/caldav"): return permission == "r" rights_type = config.get("rights", "type").lower() diff --git a/radicale/storage.py b/radicale/storage.py index b11e7d9..5a63434 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -180,17 +180,17 @@ class Collection: collection = cls(path, principal) yield collection if depth != "0": + # TODO: fix this items = list(collection.list()) if items: for item in items: yield collection.get(item[0]) else: - _, directories, files = next(os.walk(collection._filesystem_path)) - for sub_path in directories + files: + _, directories, _ = next(os.walk(collection._filesystem_path)) + for sub_path in directories: full_path = os.path.join(collection._filesystem_path, sub_path) if os.path.exists(path_to_filesystem(full_path)): - collection = cls(posixpath.join(path, sub_path)) - yield collection + yield cls(posixpath.join(path, sub_path)) @classmethod def create_collection(cls, href, collection=None, tag=None): @@ -364,7 +364,7 @@ class Collection: items = [] for href in os.listdir(self._filesystem_path): path = os.path.join(self._filesystem_path, href) - if os.path.isfile(path): + if os.path.isfile(path) and not path.endswith(".props"): with open(path, encoding=STORAGE_ENCODING) as fd: items.append(vobject.readOne(fd.read())) if self.get_meta("tag") == "VCALENDAR": @@ -377,6 +377,7 @@ class Collection: return collection.serialize() elif self.get_meta("tag") == "VADDRESSBOOK": return "".join([item.serialize() for item in items]) + return "" @property def etag(self): diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 483832c..2e09993 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -239,7 +239,18 @@ def _propfind_response(path, item, props, user, write=False): response = ET.Element(_tag("D", "response")) href = ET.Element(_tag("D", "href")) - uri = item.path if is_collection else "%s/%s" % (path, item.href) + if is_collection: + uri = item.path + else: + # TODO: fix this + if path.split("/")[-1] == item.href: + # Happening when depth is 0 + uri = path + else: + # Happening when depth is 1 + uri = "/".join((path, item.href)) + + # TODO: fix this href.text = _href(uri.replace("//", "/")) response.append(href) @@ -549,8 +560,15 @@ def report(path, xml_request, collection): else: not_found_props.append(element) + # TODO: fix this + if hreference.split("/")[-1] == item.href: + # Happening when depth is 0 + uri = "/" + hreference + else: + # Happening when depth is 1 + uri = posixpath.join(hreference, item.href) multistatus.append(_item_response( - posixpath.join(hreference, item.href), found_props=found_props, + uri, found_props=found_props, not_found_props=not_found_props, found_item=True)) return _pretty_xml(multistatus)