This commit is contained in:
Guillaume Ayoub 2016-04-08 15:05:56 +02:00
commit 44ba2c36a7
2 changed files with 15 additions and 10 deletions

View File

@ -514,9 +514,8 @@ class Application(object):
headers = { headers = {
"DAV": "1, 2, 3, calendar-access, addressbook, extended-mkcol", "DAV": "1, 2, 3, calendar-access, addressbook, extended-mkcol",
"Content-Type": "text/xml"} "Content-Type": "text/xml"}
collections = set(read_collections + write_collections)
answer = xmlutils.propfind( answer = xmlutils.propfind(
environ["PATH_INFO"], content, collections, user) environ["PATH_INFO"], content, read_collections, write_collections, user)
return client.MULTI_STATUS, headers, answer return client.MULTI_STATUS, headers, answer
def do_PROPPATCH(self, environ, read_collections, write_collections, def do_PROPPATCH(self, environ, read_collections, write_collections,

View File

@ -30,7 +30,7 @@ import xml.etree.ElementTree as ET
from collections import OrderedDict from collections import OrderedDict
from urllib.parse import unquote, urlparse from urllib.parse import unquote, urlparse
from . import client, config, ical, rights from . import client, config, ical
NAMESPACES = { NAMESPACES = {
@ -187,7 +187,7 @@ def delete(path, collection):
return _pretty_xml(multistatus) return _pretty_xml(multistatus)
def propfind(path, xml_request, collections, user=None): def propfind(path, xml_request, read_collections, write_collections, user=None):
"""Read and answer PROPFIND requests. """Read and answer PROPFIND requests.
Read rfc4918-9.1 for info. Read rfc4918-9.1 for info.
@ -213,14 +213,21 @@ def propfind(path, xml_request, collections, user=None):
# Writing answer # Writing answer
multistatus = ET.Element(_tag("D", "multistatus")) multistatus = ET.Element(_tag("D", "multistatus"))
for collection in collections: collections = []
response = _propfind_response(path, collection, props, user) for collection in write_collections:
collections.append(collection)
response = _propfind_response(path, collection, props, user, write=True)
multistatus.append(response)
for collection in read_collections:
if collection in collections:
continue
response = _propfind_response(path, collection, props, user, write=False)
multistatus.append(response) multistatus.append(response)
return _pretty_xml(multistatus) return _pretty_xml(multistatus)
def _propfind_response(path, item, props, user): def _propfind_response(path, item, props, user, write=False):
"""Build and return a PROPFIND response.""" """Build and return a PROPFIND response."""
is_collection = isinstance(item, ical.Collection) is_collection = isinstance(item, ical.Collection)
if is_collection: if is_collection:
@ -280,13 +287,12 @@ def _propfind_response(path, item, props, user):
element.append(tag) element.append(tag)
elif tag == _tag("D", "current-user-privilege-set"): elif tag == _tag("D", "current-user-privilege-set"):
privilege = ET.Element(_tag("D", "privilege")) privilege = ET.Element(_tag("D", "privilege"))
if rights.authorized(user, item, "w"): if write:
privilege.append(ET.Element(_tag("D", "all"))) privilege.append(ET.Element(_tag("D", "all")))
privilege.append(ET.Element(_tag("D", "read")))
if rights.authorized(user, item, "w"):
privilege.append(ET.Element(_tag("D", "write"))) privilege.append(ET.Element(_tag("D", "write")))
privilege.append(ET.Element(_tag("D", "write-properties"))) privilege.append(ET.Element(_tag("D", "write-properties")))
privilege.append(ET.Element(_tag("D", "write-content"))) privilege.append(ET.Element(_tag("D", "write-content")))
privilege.append(ET.Element(_tag("D", "read")))
element.append(privilege) element.append(privilege)
elif tag == _tag("D", "supported-report-set"): elif tag == _tag("D", "supported-report-set"):
for report_name in ( for report_name in (