[CalendarServer-changes] [13901] CalendarServer/branches/release/CalendarServer-5.3-dev/ twistedcaldav/method

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 20 08:31:15 PDT 2014


Revision: 13901
          http://trac.calendarserver.org//changeset/13901
Author:   cdaboo at apple.com
Date:     2014-08-20 08:31:15 -0700 (Wed, 20 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/branches/release/CalendarServer-5.3-dev/twistedcaldav/method/report_common.py
    CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/method/report_sync_collection.py

Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/method/report_common.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/method/report_common.py	2014-08-20 15:28:09 UTC (rev 13900)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/method/report_common.py	2014-08-20 15:31:15 UTC (rev 13901)
@@ -335,7 +335,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.
@@ -350,10 +350,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 : [],
     }
 
@@ -364,30 +369,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(request))
-            filtered = HiddenInstanceFilter().filter(calendar)
-            filtered = PrivateEventFilter(resource.accessMode, isowner).filter(filtered)
-            filtered = CalendarDataFilter(property, timezone).filter(filtered)
-            propvalue = CalendarData().fromCalendar(filtered)
-            properties_by_status[responsecode.OK].append(propvalue)
+            if dataAllowed:
+                # Handle private events access restrictions
+                if calendar is None:
+                    calendar = (yield resource.iCalendarForUser(request))
+                filtered = HiddenInstanceFilter().filter(calendar)
+                filtered = PrivateEventFilter(resource.accessMode, isowner).filter(filtered)
+                filtered = CalendarDataFilter(property, timezone).filter(filtered)
+                propvalue = CalendarData().fromCalendar(filtered)
+                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)
-            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)
+                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:
@@ -401,7 +416,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/branches/release/CalendarServer-5.3-dev/twistedcaldav/method/report_sync_collection.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/method/report_sync_collection.py	2014-08-20 15:28:09 UTC (rev 13900)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/method/report_sync_collection.py	2014-08-20 15:31:15 UTC (rev 13901)
@@ -20,22 +20,21 @@
 
 __all__ = ["report_DAV__sync_collection"]
 
-from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.python.failure import Failure
-
 from twext.python.log import Logger
-from txdav.xml import element
-from twext.web2.dav.http import ErrorResponse
 from twext.web2 import responsecode
-from twext.web2.dav.http import MultiStatusResponse, statusForFailure
+from twext.web2.dav.http import ErrorResponse
+from twext.web2.dav.http import MultiStatusResponse
 from twext.web2.dav.method.prop_common import responseForHref
-from twext.web2.dav.method.propfind import propertyName
 from twext.web2.dav.util import joinURL
 from twext.web2.http import HTTPError, StatusResponse
 
+from twisted.internet.defer import inlineCallbacks, returnValue
+
 from twistedcaldav.config import config
+from twistedcaldav.method.report_common import _namedPropertiesForResource
 
 from txdav.common.icommondatastore import ConcurrentModification
+from txdav.xml import element
 
 import functools
 
@@ -83,47 +82,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 +112,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 +130,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/20140820/b37ae615/attachment-0001.html>


More information about the calendarserver-changes mailing list