[CalendarServer-changes] [13892] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 18 18:15:34 PDT 2014


Revision: 13892
          http://trac.calendarserver.org//changeset/13892
Author:   cdaboo at apple.com
Date:     2014-08-18 18:15:34 -0700 (Mon, 18 Aug 2014)
Log Message:
-----------
Make sync REPORT use the same property handling code as other REPORTs so that properties and Prefer are handled properly.

Modified Paths:
--------------
    CalendarServer/trunk/requirements-dev.txt
    CalendarServer/trunk/twistedcaldav/method/report_common.py
    CalendarServer/trunk/twistedcaldav/method/report_sync_collection.py

Modified: CalendarServer/trunk/requirements-dev.txt
===================================================================
--- CalendarServer/trunk/requirements-dev.txt	2014-08-19 01:13:55 UTC (rev 13891)
+++ CalendarServer/trunk/requirements-dev.txt	2014-08-19 01:15:34 UTC (rev 13892)
@@ -7,4 +7,4 @@
 mockldap
 q
 --editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVClientLibrary/trunk@13420#egg=CalDAVClientLibrary
---editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@13887#egg=CalDAVTester
+--editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@13891#egg=CalDAVTester

Modified: CalendarServer/trunk/twistedcaldav/method/report_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/report_common.py	2014-08-19 01:13:55 UTC (rev 13891)
+++ CalendarServer/trunk/twistedcaldav/method/report_common.py	2014-08-19 01:15:34 UTC (rev 13892)
@@ -334,7 +334,7 @@
 
 
 @inlineCallbacks
-def _namedPropertiesForResource(request, props, resource, calendar=None, timezone=None, vcard=None, isowner=True):
+def _namedPropertiesForResource(request, props, resource, calendar=None, timezone=None, vcard=None, isowner=True, dataAllowed=True, forbidden=False):
     """
     Return the specified properties on the specified resource.
     @param request: the L{IRequest} for the current request.
@@ -349,10 +349,15 @@
         will be used to get the vcard if needed.
     @param isowner: C{True} if the authorized principal making the request is the DAV:owner,
         C{False} otherwise.
+    @param dataAllowed: C{True} if calendar/address data is allowed to be returned,
+        C{False} otherwise.
+    @param forbidden: if C{True} then return 403 status for all properties,
+        C{False} otherwise.
     @return: a map of OK and NOT FOUND property values.
     """
     properties_by_status = {
         responsecode.OK        : [],
+        responsecode.FORBIDDEN : [],
         responsecode.NOT_FOUND : [],
     }
 
@@ -363,30 +368,40 @@
         returnMinimal = request.headers.getHeader("brief", False)
 
     for property in props:
+        if isinstance(property, element.WebDAVElement):
+            qname = property.qname()
+        else:
+            qname = property
+
+        if forbidden:
+            properties_by_status[responsecode.FORBIDDEN].append(propertyName(qname))
+            continue
+
         if isinstance(property, caldavxml.CalendarData):
-            # Handle private events access restrictions
-            if calendar is None:
-                calendar = (yield resource.iCalendarForUser())
-            filtered = HiddenInstanceFilter().filter(calendar)
-            filtered = PrivateEventFilter(resource.accessMode, isowner).filter(filtered)
-            filtered = CalendarDataFilter(property, timezone).filter(filtered)
-            propvalue = CalendarData.fromCalendar(filtered, format=property.content_type)
-            properties_by_status[responsecode.OK].append(propvalue)
+            if dataAllowed:
+                # Handle private events access restrictions
+                if calendar is None:
+                    calendar = (yield resource.iCalendarForUser())
+                filtered = HiddenInstanceFilter().filter(calendar)
+                filtered = PrivateEventFilter(resource.accessMode, isowner).filter(filtered)
+                filtered = CalendarDataFilter(property, timezone).filter(filtered)
+                propvalue = CalendarData.fromCalendar(filtered, format=property.content_type)
+                properties_by_status[responsecode.OK].append(propvalue)
+            else:
+                properties_by_status[responsecode.FORBIDDEN].append(propertyName(qname))
             continue
 
         if isinstance(property, carddavxml.AddressData):
-            if vcard is None:
-                vcard = (yield resource.vCard())
-            filtered = AddressDataFilter(property).filter(vcard)
-            propvalue = AddressData.fromAddress(filtered, format=property.content_type)
-            properties_by_status[responsecode.OK].append(propvalue)
+            if dataAllowed:
+                if vcard is None:
+                    vcard = (yield resource.vCard())
+                filtered = AddressDataFilter(property).filter(vcard)
+                propvalue = AddressData.fromAddress(filtered, format=property.content_type)
+                properties_by_status[responsecode.OK].append(propvalue)
+            else:
+                properties_by_status[responsecode.FORBIDDEN].append(propertyName(qname))
             continue
 
-        if isinstance(property, element.WebDAVElement):
-            qname = property.qname()
-        else:
-            qname = property
-
         has = (yield resource.hasProperty(property, request))
 
         if has:
@@ -400,7 +415,7 @@
                 f = Failure()
                 status = statusForFailure(f, "getting property: %s" % (qname,))
                 if status not in properties_by_status:
-                        properties_by_status[status] = []
+                    properties_by_status[status] = []
                 if not returnMinimal or status != responsecode.NOT_FOUND:
                     properties_by_status[status].append(propertyName(qname))
         elif not returnMinimal:

Modified: CalendarServer/trunk/twistedcaldav/method/report_sync_collection.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/report_sync_collection.py	2014-08-19 01:13:55 UTC (rev 13891)
+++ CalendarServer/trunk/twistedcaldav/method/report_sync_collection.py	2014-08-19 01:15:34 UTC (rev 13892)
@@ -20,23 +20,23 @@
 
 __all__ = ["report_DAV__sync_collection"]
 
+from twext.python.log import Logger
+
 from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.python.failure import Failure
 
-from twext.python.log import Logger
+from twistedcaldav.config import config
+from twistedcaldav.method.report_common import _namedPropertiesForResource
+
+from txdav.common.icommondatastore import ConcurrentModification
 from txdav.xml import element
-from txweb2.dav.http import ErrorResponse
+
 from txweb2 import responsecode
-from txweb2.dav.http import MultiStatusResponse, statusForFailure
+from txweb2.dav.http import ErrorResponse
+from txweb2.dav.http import MultiStatusResponse
 from txweb2.dav.method.prop_common import responseForHref
-from txweb2.dav.method.propfind import propertyName
 from txweb2.dav.util import joinURL
 from txweb2.http import HTTPError, StatusResponse
 
-from twistedcaldav.config import config
-
-from txdav.common.icommondatastore import ConcurrentModification
-
 import functools
 
 log = Logger()
@@ -83,47 +83,6 @@
 
     propertyreq = sync_collection.property.children if sync_collection.property else None
 
-    @inlineCallbacks
-    def _namedPropertiesForResource(request, props, resource, forbidden=False):
-        """
-        Return the specified properties on the specified resource.
-        @param request: the L{IRequest} for the current request.
-        @param props: a list of property elements or qname tuples for the properties of interest.
-        @param resource: the L{DAVResource} for the targeted resource.
-        @return: a map of OK and NOT FOUND property values.
-        """
-        properties_by_status = {
-            responsecode.OK        : [],
-            responsecode.FORBIDDEN : [],
-            responsecode.NOT_FOUND : [],
-        }
-
-        for property in props:
-            if isinstance(property, element.WebDAVElement):
-                qname = property.qname()
-            else:
-                qname = property
-
-            if forbidden:
-                properties_by_status[responsecode.FORBIDDEN].append(propertyName(qname))
-            else:
-                props = (yield resource.listProperties(request))
-                if qname in props:
-                    try:
-                        prop = (yield resource.readProperty(qname, request))
-                        properties_by_status[responsecode.OK].append(prop)
-                    except:
-                        f = Failure()
-                        log.error("Error reading property %r for resource %s: %s" % (qname, request.uri, f.value))
-                        status = statusForFailure(f, "getting property: %s" % (qname,))
-                        if status not in properties_by_status:
-                            properties_by_status[status] = []
-                        properties_by_status[status].append(propertyName(qname))
-                else:
-                    properties_by_status[responsecode.NOT_FOUND].append(propertyName(qname))
-
-        returnValue(properties_by_status)
-
     # Do some optimization of access control calculation by determining any inherited ACLs outside of
     # the child resource loop and supply those to the checkPrivileges on each child.
     filteredaces = (yield self.inheritedACEsforChildren(request))
@@ -154,7 +113,7 @@
                 responses,
                 href,
                 child,
-                functools.partial(_namedPropertiesForResource, forbidden=False) if propertyreq else None,
+                functools.partial(_namedPropertiesForResource, dataAllowed=False, forbidden=False) if propertyreq else None,
                 propertyreq)
         except ConcurrentModification:
             # This can happen because of a race-condition between the
@@ -172,7 +131,7 @@
                 responses,
                 href,
                 child,
-                functools.partial(_namedPropertiesForResource, forbidden=True) if propertyreq else None,
+                functools.partial(_namedPropertiesForResource, dataAllowed=False, forbidden=True) if propertyreq else None,
                 propertyreq)
         except ConcurrentModification:
             # This can happen because of a race-condition between the
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140818/ce19d4f1/attachment-0001.html>


More information about the calendarserver-changes mailing list