From c135dc026d2155274825f021155b661885ce31fc Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 1 Jul 2017 00:11:00 +0200 Subject: [PATCH] Fix uploading of whole address books --- radicale/__init__.py | 8 ++++++-- radicale/storage.py | 6 +----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 25ac2db..74a8571 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -824,17 +824,21 @@ class Application: content_type = environ.get("CONTENT_TYPE", "").split(";")[0] tags = {value: key for key, value in xmlutils.MIMETYPES.items()} tag = tags.get(content_type) + if items and items[0].name == "VCALENDAR": + tag = "VCALENDAR" + elif items and items[0].name == "VCARD": + tag = "VADDRESSBOOK" if write_whole_collection: try: new_item = self.Collection.create_collection( - path, items, {"tag": tag}) + path, items, {"tag": tag} if tag else None) except ValueError as e: self.logger.warning( "Bad PUT request on %r: %s", path, e, exc_info=True) return BAD_REQUEST else: - if tag: + if tag and not parent_item.get_meta("tag"): parent_item.set_meta({"tag": tag}) href = posixpath.basename(path.strip("/")) try: diff --git a/radicale/storage.py b/radicale/storage.py index 29629ba..2db9706 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -708,10 +708,6 @@ class Collection(BaseCollection): sane_path = sanitize_path(href).strip("/") filesystem_path = path_to_filesystem(folder, sane_path) - if not props: - props = {} - if not props.get("tag") and collection: - props["tag"] = collection[0].name if not props: cls._makedirs_synced(filesystem_path) return cls(sane_path) @@ -747,7 +743,7 @@ class Collection(BaseCollection): vobject_items.get, suffix=".ics") vobject_items[href] = new_collection self._upload_all_nonatomic(vobject_items) - elif props.get("tag") == "VCARD": + elif props.get("tag") == "VADDRESSBOOK": vobject_items = {} for card in collection: # href must comply to is_safe_filesystem_path_component