Check if item is collection with storage.BaseCollection

The same as in xmlutils.py
This commit is contained in:
Unrud 2017-06-16 23:12:08 +02:00
parent 73a73bb0a5
commit 04c51d2ced

View File

@ -271,7 +271,7 @@ class Application:
for item in items: for item in items:
if not item: if not item:
continue continue
if isinstance(item, self.Collection): if isinstance(item, storage.BaseCollection):
path = item.path path = item.path
else: else:
path = item.collection.path path = item.collection.path
@ -493,9 +493,9 @@ class Application:
parent_path = storage.sanitize_path( parent_path = storage.sanitize_path(
"/%s/" % posixpath.dirname(path.strip("/"))) "/%s/" % posixpath.dirname(path.strip("/")))
allowed = False allowed = False
if not item or isinstance(item, self.Collection): if not item or isinstance(item, storage.BaseCollection):
allowed |= self.authorized(user, path, permission) allowed |= self.authorized(user, path, permission)
if not item or not isinstance(item, self.Collection): if not item or not isinstance(item, storage.BaseCollection):
allowed |= self.authorized(user, parent_path, permission) allowed |= self.authorized(user, parent_path, permission)
return allowed return allowed
@ -550,7 +550,7 @@ class Application:
if if_match not in ("*", item.etag): if if_match not in ("*", item.etag):
# ETag precondition not verified, do not delete item # ETag precondition not verified, do not delete item
return PRECONDITION_FAILED return PRECONDITION_FAILED
if isinstance(item, self.Collection): if isinstance(item, storage.BaseCollection):
xml_answer = xmlutils.delete(base_prefix, path, item) xml_answer = xmlutils.delete(base_prefix, path, item)
else: else:
xml_answer = xmlutils.delete( xml_answer = xmlutils.delete(
@ -580,7 +580,7 @@ class Application:
return NOT_ALLOWED return NOT_ALLOWED
if not item: if not item:
return NOT_FOUND return NOT_FOUND
if isinstance(item, self.Collection): if isinstance(item, storage.BaseCollection):
collection = item collection = item
if collection.get_meta("tag") not in ( if collection.get_meta("tag") not in (
"VADDRESSBOOK", "VCALENDAR"): "VADDRESSBOOK", "VCALENDAR"):
@ -678,11 +678,11 @@ class Application:
return NOT_ALLOWED return NOT_ALLOWED
if not item: if not item:
return NOT_FOUND return NOT_FOUND
if isinstance(item, self.Collection): if isinstance(item, storage.BaseCollection):
return WEBDAV_PRECONDITION_FAILED return WEBDAV_PRECONDITION_FAILED
to_item = next(self.Collection.discover(to_path), None) to_item = next(self.Collection.discover(to_path), None)
if (isinstance(to_item, self.Collection) or if (isinstance(to_item, storage.BaseCollection) or
to_item and environ.get("HTTP_OVERWRITE", "F") != "T"): to_item and environ.get("HTTP_OVERWRITE", "F") != "T"):
return WEBDAV_PRECONDITION_FAILED return WEBDAV_PRECONDITION_FAILED
to_parent_path = storage.sanitize_path( to_parent_path = storage.sanitize_path(
@ -751,7 +751,7 @@ class Application:
return BAD_REQUEST return BAD_REQUEST
with self.Collection.acquire_lock("w", user): with self.Collection.acquire_lock("w", user):
item = next(self.Collection.discover(path), None) item = next(self.Collection.discover(path), None)
if not isinstance(item, self.Collection): if not isinstance(item, storage.BaseCollection):
return WEBDAV_PRECONDITION_FAILED return WEBDAV_PRECONDITION_FAILED
headers = {"DAV": DAV_HEADERS, headers = {"DAV": DAV_HEADERS,
"Content-Type": "text/xml; charset=%s" % self.encoding} "Content-Type": "text/xml; charset=%s" % self.encoding}
@ -777,7 +777,7 @@ class Application:
parent_item = next(self.Collection.discover(parent_path), None) parent_item = next(self.Collection.discover(parent_path), None)
write_whole_collection = ( write_whole_collection = (
isinstance(item, self.Collection) or isinstance(item, storage.BaseCollection) or
not parent_item or ( not parent_item or (
not next(parent_item.list(), None) and not next(parent_item.list(), None) and
parent_item.get_meta("tag") not in ( parent_item.get_meta("tag") not in (
@ -850,7 +850,7 @@ class Application:
return NOT_ALLOWED return NOT_ALLOWED
if not item: if not item:
return NOT_FOUND return NOT_FOUND
if isinstance(item, self.Collection): if isinstance(item, storage.BaseCollection):
collection = item collection = item
else: else:
collection = item.collection collection = item.collection