<!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>[13417] CalendarServer/trunk/txdav/caldav/datastore</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/13417">13417</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-05-02 18:49:59 -0700 (Fri, 02 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix issue where duplicate private comments could prevent scheduling updates.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingcaldavdeliverypy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/delivery.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoretesttest_implicitpy">CalendarServer/trunk/txdav/caldav/datastore/test/test_implicit.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingcaldavdeliverypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/delivery.py (13416 => 13417)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/delivery.py        2014-05-03 01:25:05 UTC (rev 13416)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/delivery.py        2014-05-03 01:49:59 UTC (rev 13417)
</span><span class="lines">@@ -149,6 +149,21 @@
</span><span class="cx">             ))
</span><span class="cx">             responses.add(recipient.cuaddr, Failure(exc_value=err), reqstatus=e.msg)
</span><span class="cx">             returnValue(False)
</span><ins>+        except Exception as e:
+            log.failure(
+                &quot;Could not process iTIP message&quot;,
+                level=LogLevel.debug
+            )
+            log.error(
+                &quot;Could not process iTIP message&quot;,
+            )
+            err = HTTPError(ErrorResponse(
+                responsecode.FORBIDDEN,
+                (caldav_namespace, &quot;recipient-permissions&quot;),
+                &quot;Could not process iTIP message&quot;,
+            ))
+            responses.add(recipient.cuaddr, Failure(exc_value=err), reqstatus=iTIPRequestStatus.BAD_REQUEST)
+            returnValue(False)
</ins><span class="cx"> 
</span><span class="cx">         if store_inbox:
</span><span class="cx">             # Copy calendar to inbox
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (13416 => 13417)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-05-03 01:25:05 UTC (rev 13416)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-05-03 01:49:59 UTC (rev 13417)
</span><span class="lines">@@ -2174,7 +2174,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def preservePrivateComments(self, component, inserting):
</del><ins>+    def preservePrivateComments(self, component, inserting, internal_state):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Check for private comments on the old resource and the new resource and re-insert
</span><span class="cx">         ones that are lost.
</span><span class="lines">@@ -2207,7 +2207,7 @@
</span><span class="cx">             # to raise an error to prevent that so the client bugs can be tracked down.
</span><span class="cx"> 
</span><span class="cx">             # Look for properties with duplicate &quot;X-CALENDARSERVER-ATTENDEE-REF&quot; values in the same component
</span><del>-            if component.hasDuplicatePrivateComments(doFix=config.RemoveDuplicatePrivateComments):
</del><ins>+            if component.hasDuplicatePrivateComments(doFix=config.RemoveDuplicatePrivateComments) and internal_state == ComponentUpdateState.NORMAL:
</ins><span class="cx">                 raise DuplicatePrivateCommentsError(&quot;Duplicate X-CALENDARSERVER-ATTENDEE-COMMENT properties present.&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -2636,7 +2636,7 @@
</span><span class="cx">                 self.validAccess(component, inserting, internal_state)
</span><span class="cx"> 
</span><span class="cx">             # Preserve private comments
</span><del>-            yield self.preservePrivateComments(component, inserting)
</del><ins>+            yield self.preservePrivateComments(component, inserting, internal_state)
</ins><span class="cx"> 
</span><span class="cx">             managed_copied, managed_removed = (yield self.resourceCheckAttachments(component, inserting))
</span><span class="cx"> 
</span><span class="lines">@@ -2655,7 +2655,7 @@
</span><span class="cx">             yield self._lockUID(component, inserting, internal_state)
</span><span class="cx"> 
</span><span class="cx">             # Preserve private comments
</span><del>-            yield self.preservePrivateComments(component, inserting)
</del><ins>+            yield self.preservePrivateComments(component, inserting, internal_state)
</ins><span class="cx"> 
</span><span class="cx">             # Fix broken VTODOs
</span><span class="cx">             yield self.replaceMissingToDoProperties(component, inserting, internal_state)
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoretesttest_implicitpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_implicit.py (13416 => 13417)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/test/test_implicit.py        2014-05-03 01:25:05 UTC (rev 13416)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_implicit.py        2014-05-03 01:49:59 UTC (rev 13417)
</span><span class="lines">@@ -17,7 +17,7 @@
</span><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="cx"> 
</span><del>-from twistedcaldav.ical import Component
</del><ins>+from twistedcaldav.ical import Component, normalize_iCalStr
</ins><span class="cx"> 
</span><span class="cx"> from txdav.common.datastore.test.util import CommonCommonTests, populateCalendarsFrom
</span><span class="cx"> from twisted.trial.unittest import TestCase
</span><span class="lines">@@ -27,9 +27,11 @@
</span><span class="cx">     InvalidObjectResourceError, InvalidComponentForStoreError, InvalidUIDError, \
</span><span class="cx">     UIDExistsError, UIDExistsElsewhereError
</span><span class="cx"> from txdav.caldav.icalendarstore import InvalidComponentTypeError, \
</span><del>-    TooManyAttendeesError, InvalidCalendarAccessError, ComponentUpdateState
</del><ins>+    TooManyAttendeesError, InvalidCalendarAccessError, ComponentUpdateState, \
+    DuplicatePrivateCommentsError
</ins><span class="cx"> from txdav.common.datastore.sql_tables import _BIND_MODE_WRITE
</span><span class="cx"> from txdav.caldav.datastore.test.util import buildCalendarStore
</span><ins>+from txdav.caldav.datastore.sql import CalendarObject
</ins><span class="cx"> 
</span><span class="cx"> class ImplicitRequests (CommonCommonTests, TestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -1096,3 +1098,179 @@
</span><span class="cx">         yield calendar_resource._setComponentInternal(calendar, internal_state=ComponentUpdateState.ORGANIZER_ITIP_UPDATE)
</span><span class="cx">         self.assertEqual(calendar_resource.scheduleTag, schedule_tag)
</span><span class="cx">         yield self.commit()
</span><ins>+
+
+    @inlineCallbacks
+    def test_validation_duplicatePrivateCommentsOKWIthiTIP(self):
+        &quot;&quot;&quot;
+        Test that an iTIP update to an organizer event with duplicate private comments
+        does not fail.
+        &quot;&quot;&quot;
+
+        data1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTAMP:20080601T120000Z
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTAMP:20080601T120000Z
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+X-CALENDARSERVER-ATTENDEE-COMMENT;X-CALENDARSERVER-ATTENDEE-REF=&quot;urn:uuid:
+ user02&quot;;X-CALENDARSERVER-DTSTAMP=20140224T181133Z:Comment
+X-CALENDARSERVER-ATTENDEE-COMMENT;X-CALENDARSERVER-ATTENDEE-REF=&quot;urn:uuid:
+ user02&quot;;X-CALENDARSERVER-DTSTAMP=20140224T181133Z:Comment
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data3 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTAMP:20080601T120000Z
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+X-CALENDARSERVER-ATTENDEE-COMMENT;X-CALENDARSERVER-ATTENDEE-REF=&quot;urn:uuid:
+ user02&quot;;X-CALENDARSERVER-DTSTAMP=20140224T181133Z:Comment
+X-CALENDARSERVER-ATTENDEE-COMMENT;X-CALENDARSERVER-ATTENDEE-REF=&quot;urn:uuid:
+ user02&quot;;X-CALENDARSERVER-DTSTAMP=20140224T181133Z:Comment
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        calendar_collection = (yield self.calendarUnderTest(home=&quot;user01&quot;))
+        calendar = Component.fromString(data1)
+        yield calendar_collection.createCalendarObjectWithName(&quot;test.ics&quot;, calendar)
+        yield self.commit()
+
+        calendar_resource = (yield self.calendarObjectUnderTest(name=&quot;test.ics&quot;, home=&quot;user01&quot;,))
+        calendar = Component.fromString(data2)
+        yield calendar_resource._setComponentInternal(calendar, internal_state=ComponentUpdateState.RAW)
+        yield self.commit()
+
+        calendar_resource = (yield self.calendarObjectUnderTest(name=&quot;test.ics&quot;, home=&quot;user01&quot;,))
+        calendar = Component.fromString(data3)
+        yield calendar_resource._setComponentInternal(calendar, internal_state=ComponentUpdateState.ORGANIZER_ITIP_UPDATE)
+        yield self.commit()
+
+        calendar_resource = (yield self.calendarObjectUnderTest(name=&quot;test.ics&quot;, home=&quot;user01&quot;,))
+        calendar = Component.fromString(data3)
+        yield self.failUnlessFailure(calendar_resource.setComponent(calendar), DuplicatePrivateCommentsError)
+        yield self.commit()
+
+
+    @inlineCallbacks
+    def test_validation_deleteWithDuplicatePrivateComments(self):
+        &quot;&quot;&quot;
+        Test that attendee private comments are no longer restored.
+        &quot;&quot;&quot;
+
+        data1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTAMP:20080601T120000Z
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTAMP:20080601T120000Z
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+X-CALENDARSERVER-ATTENDEE-COMMENT;X-CALENDARSERVER-ATTENDEE-REF=&quot;urn:uuid:
+ user02&quot;;X-CALENDARSERVER-DTSTAMP=20140224T181133Z:Comment
+X-CALENDARSERVER-ATTENDEE-COMMENT;X-CALENDARSERVER-ATTENDEE-REF=&quot;urn:uuid:
+ user02&quot;;X-CALENDARSERVER-DTSTAMP=20140224T181133Z:Comment
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data3 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTAMP:20080601T120000Z
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        calendar_collection = (yield self.calendarUnderTest(home=&quot;user01&quot;))
+        calendar = Component.fromString(data1)
+        yield calendar_collection.createCalendarObjectWithName(&quot;test.ics&quot;, calendar)
+        yield self.commit()
+
+        calendar_resource = (yield self.calendarObjectUnderTest(name=&quot;test.ics&quot;, home=&quot;user01&quot;,))
+        calendar = Component.fromString(data2)
+        yield calendar_resource._setComponentInternal(calendar, internal_state=ComponentUpdateState.RAW)
+        yield self.commit()
+
+        def raiseHere(otherself, component, inserting, internal_state):
+            if component.hasDuplicatePrivateComments(doFix=False):
+                raise ValueError
+
+        self.patch(CalendarObject, &quot;preservePrivateComments&quot;, raiseHere)
+
+        calendar2 = (yield self.calendarUnderTest(name=&quot;calendar_1&quot;, home=&quot;user02&quot;))
+        cobjs = (yield calendar2.calendarObjects())
+        self.assertTrue(len(cobjs) == 1)
+        yield cobjs[0].setComponent(Component.fromString(data3))
+        yield self.commit()
+
+        calendar2 = (yield self.calendarUnderTest(name=&quot;calendar_1&quot;, home=&quot;user02&quot;))
+        cobjs = (yield calendar2.calendarObjects())
+        calendar = yield cobjs[0].component()
+        self.assertTrue('SCHEDULE-STATUS=5.0' in normalize_iCalStr(calendar))
+        yield self.commit()
+
+        calendar2 = (yield self.calendarUnderTest(name=&quot;calendar_1&quot;, home=&quot;user02&quot;))
+        cobjs = (yield calendar2.calendarObjects())
+        self.assertTrue(len(cobjs) == 1)
+        yield cobjs[0].remove()
+        yield self.commit()
+
+        calendar2 = (yield self.calendarUnderTest(name=&quot;calendar_1&quot;, home=&quot;user02&quot;))
+        cobjs = (yield calendar2.calendarObjects())
+        self.assertTrue(len(cobjs) == 0)
+        yield self.commit()
</ins></span></pre>
</div>
</div>

</body>
</html>