<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[13892] CalendarServer/trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/13892">13892</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-08-18 18:15:34 -0700 (Mon, 18 Aug 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make sync REPORT use the same property handling code as other REPORTs so that properties and Prefer are handled properly.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkrequirementsdevtxt">CalendarServer/trunk/requirements-dev.txt</a></li>
<li><a href="#CalendarServertrunktwistedcaldavmethodreport_commonpy">CalendarServer/trunk/twistedcaldav/method/report_common.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavmethodreport_sync_collectionpy">CalendarServer/trunk/twistedcaldav/method/report_sync_collection.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkrequirementsdevtxt"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/requirements-dev.txt (13891 => 13892)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -7,4 +7,4 @@
</span><span class="cx"> mockldap
</span><span class="cx"> q
</span><span class="cx"> --editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVClientLibrary/trunk@13420#egg=CalDAVClientLibrary
</span><del>---editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@13887#egg=CalDAVTester
</del><ins>+--editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@13891#egg=CalDAVTester
</ins></span></pre></div>
<a id="CalendarServertrunktwistedcaldavmethodreport_commonpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/method/report_common.py (13891 => 13892)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -334,7 +334,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> @inlineCallbacks
</span><del>-def _namedPropertiesForResource(request, props, resource, calendar=None, timezone=None, vcard=None, isowner=True):
</del><ins>+def _namedPropertiesForResource(request, props, resource, calendar=None, timezone=None, vcard=None, isowner=True, dataAllowed=True, forbidden=False):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Return the specified properties on the specified resource.
</span><span class="cx">     @param request: the L{IRequest} for the current request.
</span><span class="lines">@@ -349,10 +349,15 @@
</span><span class="cx">         will be used to get the vcard if needed.
</span><span class="cx">     @param isowner: C{True} if the authorized principal making the request is the DAV:owner,
</span><span class="cx">         C{False} otherwise.
</span><ins>+    @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.
</ins><span class="cx">     @return: a map of OK and NOT FOUND property values.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     properties_by_status = {
</span><span class="cx">         responsecode.OK        : [],
</span><ins>+        responsecode.FORBIDDEN : [],
</ins><span class="cx">         responsecode.NOT_FOUND : [],
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -363,30 +368,40 @@
</span><span class="cx">         returnMinimal = request.headers.getHeader(&quot;brief&quot;, False)
</span><span class="cx"> 
</span><span class="cx">     for property in props:
</span><ins>+        if isinstance(property, element.WebDAVElement):
+            qname = property.qname()
+        else:
+            qname = property
+
+        if forbidden:
+            properties_by_status[responsecode.FORBIDDEN].append(propertyName(qname))
+            continue
+
</ins><span class="cx">         if isinstance(property, caldavxml.CalendarData):
</span><del>-            # 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)
</del><ins>+            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))
</ins><span class="cx">             continue
</span><span class="cx"> 
</span><span class="cx">         if isinstance(property, carddavxml.AddressData):
</span><del>-            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)
</del><ins>+            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))
</ins><span class="cx">             continue
</span><span class="cx"> 
</span><del>-        if isinstance(property, element.WebDAVElement):
-            qname = property.qname()
-        else:
-            qname = property
-
</del><span class="cx">         has = (yield resource.hasProperty(property, request))
</span><span class="cx"> 
</span><span class="cx">         if has:
</span><span class="lines">@@ -400,7 +415,7 @@
</span><span class="cx">                 f = Failure()
</span><span class="cx">                 status = statusForFailure(f, &quot;getting property: %s&quot; % (qname,))
</span><span class="cx">                 if status not in properties_by_status:
</span><del>-                        properties_by_status[status] = []
</del><ins>+                    properties_by_status[status] = []
</ins><span class="cx">                 if not returnMinimal or status != responsecode.NOT_FOUND:
</span><span class="cx">                     properties_by_status[status].append(propertyName(qname))
</span><span class="cx">         elif not returnMinimal:
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavmethodreport_sync_collectionpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/method/report_sync_collection.py (13891 => 13892)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -20,23 +20,23 @@
</span><span class="cx"> 
</span><span class="cx"> __all__ = [&quot;report_DAV__sync_collection&quot;]
</span><span class="cx"> 
</span><ins>+from twext.python.log import Logger
+
</ins><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><del>-from twisted.python.failure import Failure
</del><span class="cx"> 
</span><del>-from twext.python.log import Logger
</del><ins>+from twistedcaldav.config import config
+from twistedcaldav.method.report_common import _namedPropertiesForResource
+
+from txdav.common.icommondatastore import ConcurrentModification
</ins><span class="cx"> from txdav.xml import element
</span><del>-from txweb2.dav.http import ErrorResponse
</del><ins>+
</ins><span class="cx"> from txweb2 import responsecode
</span><del>-from txweb2.dav.http import MultiStatusResponse, statusForFailure
</del><ins>+from txweb2.dav.http import ErrorResponse
+from txweb2.dav.http import MultiStatusResponse
</ins><span class="cx"> from txweb2.dav.method.prop_common import responseForHref
</span><del>-from txweb2.dav.method.propfind import propertyName
</del><span class="cx"> from txweb2.dav.util import joinURL
</span><span class="cx"> from txweb2.http import HTTPError, StatusResponse
</span><span class="cx"> 
</span><del>-from twistedcaldav.config import config
-
-from txdav.common.icommondatastore import ConcurrentModification
-
</del><span class="cx"> import functools
</span><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="lines">@@ -83,47 +83,6 @@
</span><span class="cx"> 
</span><span class="cx">     propertyreq = sync_collection.property.children if sync_collection.property else None
</span><span class="cx"> 
</span><del>-    @inlineCallbacks
-    def _namedPropertiesForResource(request, props, resource, forbidden=False):
-        &quot;&quot;&quot;
-        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.
-        &quot;&quot;&quot;
-        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(&quot;Error reading property %r for resource %s: %s&quot; % (qname, request.uri, f.value))
-                        status = statusForFailure(f, &quot;getting property: %s&quot; % (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)
-
</del><span class="cx">     # Do some optimization of access control calculation by determining any inherited ACLs outside of
</span><span class="cx">     # the child resource loop and supply those to the checkPrivileges on each child.
</span><span class="cx">     filteredaces = (yield self.inheritedACEsforChildren(request))
</span><span class="lines">@@ -154,7 +113,7 @@
</span><span class="cx">                 responses,
</span><span class="cx">                 href,
</span><span class="cx">                 child,
</span><del>-                functools.partial(_namedPropertiesForResource, forbidden=False) if propertyreq else None,
</del><ins>+                functools.partial(_namedPropertiesForResource, dataAllowed=False, forbidden=False) if propertyreq else None,
</ins><span class="cx">                 propertyreq)
</span><span class="cx">         except ConcurrentModification:
</span><span class="cx">             # This can happen because of a race-condition between the
</span><span class="lines">@@ -172,7 +131,7 @@
</span><span class="cx">                 responses,
</span><span class="cx">                 href,
</span><span class="cx">                 child,
</span><del>-                functools.partial(_namedPropertiesForResource, forbidden=True) if propertyreq else None,
</del><ins>+                functools.partial(_namedPropertiesForResource, dataAllowed=False, forbidden=True) if propertyreq else None,
</ins><span class="cx">                 propertyreq)
</span><span class="cx">         except ConcurrentModification:
</span><span class="cx">             # This can happen because of a race-condition between the
</span></span></pre>
</div>
</div>

</body>
</html>