1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00

Respond to all authenticated PROPFIND requests

This commit is contained in:
Christoph Polcin 2014-01-05 20:54:17 +01:00
parent 2ddec14535
commit 83db27303f
2 changed files with 67 additions and 48 deletions

View file

@ -234,8 +234,12 @@ def propfind(path, xml_request, collections, user=None):
# Writing answer
multistatus = ET.Element(_tag("D", "multistatus"))
for collection in collections:
response = _propfind_response(path, collection, props, user)
if collections:
for collection in collections:
response = _propfind_response(path, collection, props, user)
multistatus.append(response)
else:
response = _propfind_response(path, None, props, user)
multistatus.append(response)
return _pretty_xml(multistatus)
@ -251,8 +255,11 @@ def _propfind_response(path, item, props, user):
response = ET.Element(_tag("D", "response"))
href = ET.Element(_tag("D", "href"))
uri = item.url if is_collection else "%s/%s" % (path, item.name)
href.text = _href(uri.replace("//", "/"))
if item:
uri = item.url if is_collection else "%s/%s" % (path, item.name)
href.text = _href(uri.replace("//", "/"))
else:
href.text = _href(path)
response.append(href)
propstat404 = ET.Element(_tag("D", "propstat"))
@ -268,10 +275,8 @@ def _propfind_response(path, item, props, user):
for tag in props:
element = ET.Element(tag)
is404 = False
if tag == _tag("D", "getetag"):
element.text = item.etag
elif tag in (_tag("D", "principal-URL"),
_tag("D", "current-user-principal")):
if tag in (_tag("D", "principal-URL"),
_tag("D", "current-user-principal")):
if user:
tag = ET.Element(_tag("D", "href"))
tag.text = _href("%s/" % user)
@ -317,45 +322,55 @@ def _propfind_response(path, item, props, user):
report_tag.text = report_name
supported.append(report_tag)
element.append(supported)
elif is_collection:
if tag == _tag("D", "getcontenttype"):
element.text = item.mimetype
elif tag == _tag("D", "resourcetype"):
if item.is_principal:
tag = ET.Element(_tag("D", "principal"))
element.append(tag)
if item.is_leaf(item.path) or (
not item.exists and item.resource_type):
# 2nd case happens when the collection is not stored yet,
# but the resource type is guessed
if item.resource_type == "addressbook":
tag = ET.Element(_tag("CR", item.resource_type))
else:
tag = ET.Element(_tag("C", item.resource_type))
element.append(tag)
tag = ET.Element(_tag("D", "collection"))
element.append(tag)
elif tag == _tag("D", "owner") and item.owner_url:
element.text = item.owner_url
elif tag == _tag("CS", "getctag"):
# item related properties
elif item:
if tag == _tag("D", "getetag"):
element.text = item.etag
elif tag == _tag("C", "calendar-timezone"):
element.text = ical.serialize(
item.tag, item.headers, item.timezones)
elif tag == _tag("D", "displayname"):
element.text = item.name
elif tag == _tag("A", "calendar-color"):
element.text = item.color
else:
human_tag = _tag_from_clark(tag)
if human_tag in collection_props:
element.text = collection_props[human_tag]
elif is_collection:
if tag == _tag("D", "getcontenttype"):
element.text = item.mimetype
elif tag == _tag("D", "resourcetype"):
if item.is_principal:
tag = ET.Element(_tag("D", "principal"))
element.append(tag)
if item.is_leaf(item.path) or (
not item.exists and item.resource_type):
# 2nd case happens when the collection is not stored yet,
# but the resource type is guessed
if item.resource_type == "addressbook":
tag = ET.Element(_tag("CR", item.resource_type))
else:
tag = ET.Element(_tag("C", item.resource_type))
element.append(tag)
tag = ET.Element(_tag("D", "collection"))
element.append(tag)
elif tag == _tag("D", "owner") and item.owner_url:
element.text = item.owner_url
elif tag == _tag("CS", "getctag"):
element.text = item.etag
elif tag == _tag("C", "calendar-timezone"):
element.text = ical.serialize(
item.tag, item.headers, item.timezones)
elif tag == _tag("D", "displayname"):
element.text = item.name
elif tag == _tag("A", "calendar-color"):
element.text = item.color
else:
is404 = True
# Not for collections
elif tag == _tag("D", "getcontenttype"):
element.text = "%s; component=%s" % (
item.mimetype, item.tag.lower())
human_tag = _tag_from_clark(tag)
if human_tag in collection_props:
element.text = collection_props[human_tag]
else:
is404 = True
# Not for collections
elif tag == _tag("D", "getcontenttype"):
element.text = "%s; component=%s" % (
item.mimetype, item.tag.lower())
elif tag == _tag("D", "resourcetype"):
# resourcetype must be returned empty for non-collection elements
pass
else:
is404 = True
# Not for items
elif tag == _tag("D", "resourcetype"):
# resourcetype must be returned empty for non-collection elements
pass