<!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>[14166] 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/14166">14166</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-11-13 12:05:54 -0800 (Thu, 13 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Use iTip reply processing to restore events for which the imported is an ATTENDEE</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsimporterpy">CalendarServer/trunk/calendarserver/tools/importer.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolstesttest_importerpy">CalendarServer/trunk/calendarserver/tools/test/test_importer.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingitippy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/itip.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingprocessingpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsimporterpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/importer.py (14165 => 14166)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/importer.py        2014-11-13 19:57:52 UTC (rev 14165)
+++ CalendarServer/trunk/calendarserver/tools/importer.py        2014-11-13 20:05:54 UTC (rev 14166)
</span><span class="lines">@@ -40,10 +40,13 @@
</span><span class="cx"> from twistedcaldav.stdconfig import DEFAULT_CONFIG_FILE
</span><span class="cx"> from twistedcaldav.timezones import TimezoneCache
</span><span class="cx"> from txdav.base.propertystore.base import PropertyName
</span><ins>+from txdav.caldav.datastore.scheduling.cuaddress import LocalCalendarUser
+from txdav.caldav.datastore.scheduling.itip import iTipGenerator
+from txdav.caldav.datastore.scheduling.processing import ImplicitProcessor
+from txdav.caldav.icalendarstore import ComponentUpdateState
</ins><span class="cx"> from txdav.common.icommondatastore import UIDExistsError
</span><span class="cx"> from txdav.xml import element as davxml
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -187,6 +190,7 @@
</span><span class="cx">     home = yield txn.calendarHomeWithUID(ownerUID, create=True)
</span><span class="cx">     collection = yield home.childWithName(collectionResourceName)
</span><span class="cx">     if not collection:
</span><ins>+        print(&quot;Creating calendar: {}&quot;.format(collectionResourceName))
</ins><span class="cx">         collection = yield home.createChildWithName(collectionResourceName)
</span><span class="cx">     for propertyName, element in (
</span><span class="cx">         (&quot;NAME&quot;, davxml.DisplayName),
</span><span class="lines">@@ -195,6 +199,9 @@
</span><span class="cx">         value = component.propertyValue(propertyName)
</span><span class="cx">         if value is not None:
</span><span class="cx">             setCollectionPropertyValue(collection, element, value)
</span><ins>+            print(
+                &quot;Setting {name} to {value}&quot;.format(name=propertyName, value=value)
+            )
</ins><span class="cx">     yield txn.commit()
</span><span class="cx"> 
</span><span class="cx">     # Populate the collection; NB we use a txn for each object, and we might
</span><span class="lines">@@ -205,11 +212,12 @@
</span><span class="cx">         try:
</span><span class="cx">             uid = list(groupedComponent.subcomponents())[0].propertyValue(&quot;UID&quot;)
</span><span class="cx">         except:
</span><del>-            uid = &quot;unknown&quot;
</del><ins>+            continue
</ins><span class="cx"> 
</span><span class="cx">         # If event is unscheduled or the organizer matches homeUID, store the
</span><span class="cx">         # component
</span><span class="cx"> 
</span><ins>+        print(&quot;Event UID: {}&quot;.format(uid))
</ins><span class="cx">         storeDirectly = True
</span><span class="cx">         organizer = groupedComponent.getOrganizer()
</span><span class="cx">         if organizer is not None:
</span><span class="lines">@@ -226,7 +234,8 @@
</span><span class="cx">             resourceName = &quot;{}.ics&quot;.format(str(uuid.uuid4()))
</span><span class="cx">             try:
</span><span class="cx">                 yield storeComponentInHomeAndCalendar(
</span><del>-                    store, groupedComponent, ownerUID, collectionResourceName, resourceName
</del><ins>+                    store, groupedComponent, ownerUID, collectionResourceName,
+                    resourceName
</ins><span class="cx">                 )
</span><span class="cx">                 print(&quot;Imported: {}&quot;.format(uid))
</span><span class="cx">             except UIDExistsError:
</span><span class="lines">@@ -242,15 +251,45 @@
</span><span class="cx">                 )
</span><span class="cx"> 
</span><span class="cx">         else:
</span><del>-            # Owner is not the organizer
-            ownerCUA = ownerRecord.canonicalCalendarUserAddress()
-            yield reInviteAttendee(store, organizerRecord.uid, uid, ownerCUA)
</del><ins>+            # Owner is an attendee, not the organizer
+            # Apply the PARTSTATs from the import and from the possibly
+            # existing event (existing event takes precedence) to the
+            # organizer's copy.
</ins><span class="cx"> 
</span><ins>+            # Put the attendee copy into the right calendar now otherwise it
+            # could end up on the default calendar when the change to the
+            # organizer's copy causes an attendee update
+            resourceName = &quot;{}.ics&quot;.format(str(uuid.uuid4()))
+            try:
+                yield storeComponentInHomeAndCalendar(
+                    store, groupedComponent, ownerUID, collectionResourceName,
+                    resourceName, asAttendee=True
+                )
+                print(&quot;Imported: {}&quot;.format(uid))
+            except UIDExistsError:
+                # No need since the event is already in the home
+                pass
</ins><span class="cx"> 
</span><ins>+            # Now use the iTip reply processing to update the organizer's copy
+            # with the PARTSTATs from the component we're restoring.
+            attendeeCUA = ownerRecord.canonicalCalendarUserAddress()
+            organizerCUA = organizerRecord.canonicalCalendarUserAddress()
+            processor = ImplicitProcessor()
+            newComponent = iTipGenerator.generateAttendeeReply(groupedComponent, attendeeCUA, method=&quot;X-RESTORE&quot;)
+            txn = store.newTransaction()
+            yield processor.doImplicitProcessing(
+                txn,
+                newComponent,
+                LocalCalendarUser(attendeeCUA, ownerRecord),
+                LocalCalendarUser(organizerCUA, organizerRecord)
+            )
+            yield txn.commit()
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> @inlineCallbacks
</span><span class="cx"> def storeComponentInHomeAndCalendar(
</span><del>-    store, component, homeUID, collectionResourceName, objectResourceName
</del><ins>+    store, component, homeUID, collectionResourceName, objectResourceName,
+    asAttendee=False
</ins><span class="cx"> ):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Add a component to the store as an objectResource
</span><span class="lines">@@ -276,50 +315,18 @@
</span><span class="cx">     if not collection:
</span><span class="cx">         collection = yield home.createChildWithName(collectionResourceName)
</span><span class="cx"> 
</span><del>-    yield collection.createObjectResourceWithName(objectResourceName, component)
</del><ins>+    yield collection._createCalendarObjectWithNameInternal(
+        objectResourceName, component,
+        (
+            ComponentUpdateState.ATTENDEE_ITIP_UPDATE
+            if asAttendee else
+            ComponentUpdateState.NORMAL
+        )
+    )
</ins><span class="cx">     yield txn.commit()
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-@inlineCallbacks
-def reInviteAttendee(
-    store, organizerUID, objectUID, attendeeCUA
-):
-    &quot;&quot;&quot;
-    Force a re-invite of an attendee
</del><span class="cx"> 
</span><del>-    Find the event with the given objectUID within the calendar home for
-    organizerUID, and update it so the attendeeCUA's PARTSTAT is set to
-    NEEDS-ACTION.
-
-    @param store: The db store to add the component to
-    @type store: L{IDataStore}
-    @param organizerUID: uid of the organizer
-    @type organizerUID: C{str}
-    @param objectUID: uid of the event
-    @type objectUID: C{str}
-    @param attendeeCUA: CUA of the attendee to re-invite
-    @type attendeeCUA: C{str}
-    &quot;&quot;&quot;
-
-    txn = store.newTransaction()
-    organizerHome = yield txn.calendarHomeWithUID(organizerUID)
-    if organizerHome is not None:
-        for object in (yield organizerHome.getCalendarResourcesForUID(objectUID)):
-            component = yield object.componentForUser()
-
-            # duplicate() so implicit actions will trigger -- otherwise
-            # the data objects will be the same when you call setComponent
-            component = component.duplicate()
-
-            for attendeeProp in (yield component.getAttendeeProperties((attendeeCUA,))):
-                if attendeeProp is not None:
-                    attendeeProp.setParameter(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;)
-                    yield object.setComponent(component)
-                    print(&quot;Reinviting to: {}&quot;.format(objectUID))
-
-    yield txn.commit()
-
-
</del><span class="cx"> class ImporterService(WorkerService, object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Service which runs, imports the data, then stops the reactor.
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolstesttest_importerpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/test/test_importer.py (14165 => 14166)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/test/test_importer.py        2014-11-13 19:57:52 UTC (rev 14165)
+++ CalendarServer/trunk/calendarserver/tools/test/test_importer.py        2014-11-13 20:05:54 UTC (rev 14166)
</span><span class="lines">@@ -153,8 +153,9 @@
</span><span class="cx"> PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
</span><span class="cx"> BEGIN:VEVENT
</span><span class="cx"> UID:6DB84FB1-C943-4144-BE65-9B0DD9A9E2C7
</span><del>-DTSTART;TZID=America/Los_Angeles:20151008T053000
-DTEND;TZID=America/Los_Angeles:20151008T070000
</del><ins>+DTSTART;TZID=America/Los_Angeles:20141115T074500
+DTEND;TZID=America/Los_Angeles:20141115T091500
+RRULE:FREQ=DAILY;COUNT=20
</ins><span class="cx"> ATTENDEE;CN=User 01;CUTYPE=INDIVIDUAL:urn:x-uid:user01
</span><span class="cx"> ATTENDEE;CN=User 02;CUTYPE=INDIVIDUAL;ROLE=CHAIR:urn:x-uid:user02
</span><span class="cx"> ATTENDEE;CN=User 03;CUTYPE=INDIVIDUAL:urn:x-uid:user03
</span><span class="lines">@@ -167,9 +168,71 @@
</span><span class="cx"> SUMMARY:Other organizer
</span><span class="cx"> TRANSP:OPAQUE
</span><span class="cx"> END:VEVENT
</span><ins>+BEGIN:VEVENT
+UID:6DB84FB1-C943-4144-BE65-9B0DD9A9E2C7
+RECURRENCE-ID;TZID=America/Los_Angeles:20141117T074500
+DTSTART;TZID=America/Los_Angeles:20141117T093000
+DTEND;TZID=America/Los_Angeles:20141117T110000
+ATTENDEE;CN=User 01;CUTYPE=INDIVIDUAL:urn:x-uid:user01
+ATTENDEE;CN=User 02;CUTYPE=INDIVIDUAL;ROLE=CHAIR:urn:x-uid:user02
+ATTENDEE;CN=User 03;CUTYPE=INDIVIDUAL:urn:x-uid:user03
+ATTENDEE;CN=Mercury Seven;CUTYPE=ROOM:urn:x-uid:mercury
+CREATED:20141107T172645Z
+DTSTAMP:20141107T172645Z
+LOCATION:Mercury
+ORGANIZER;CN=User 02:urn:x-uid:user02
+SEQUENCE:0
+SUMMARY:Other organizer
+TRANSP:OPAQUE
+END:VEVENT
+BEGIN:VEVENT
+UID:6DB84FB1-C943-4144-BE65-9B0DD9A9E2C7
+RECURRENCE-ID;TZID=America/Los_Angeles:20141119T074500
+DTSTART;TZID=America/Los_Angeles:20141119T103000
+DTEND;TZID=America/Los_Angeles:20141119T120000
+ATTENDEE;CN=User 01;CUTYPE=INDIVIDUAL:urn:x-uid:user01
+ATTENDEE;CN=User 02;CUTYPE=INDIVIDUAL;ROLE=CHAIR:urn:x-uid:user02
+ATTENDEE;CN=User 03;CUTYPE=INDIVIDUAL:urn:x-uid:user03
+ATTENDEE;CN=Mercury Seven;CUTYPE=ROOM:urn:x-uid:mercury
+CREATED:20141107T172645Z
+DTSTAMP:20141107T172645Z
+LOCATION:Mercury
+ORGANIZER;CN=User 02:urn:x-uid:user02
+SEQUENCE:0
+SUMMARY:Other organizer
+TRANSP:OPAQUE
+END:VEVENT
</ins><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+# DATA_USER02_INVITES_USER01_ATTENDEE_COPY = &quot;&quot;&quot;BEGIN:VCALENDAR
+# VERSION:2.0
+# NAME:I'm an attendee
+# COLOR:#0000FFFF
+# SOURCE;VALUE=URI:http://example.com/calendars/__uids__/user01/calendar/
+# PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+# BEGIN:VEVENT
+# UID:6DB84FB1-C943-4144-BE65-9B0DD9A9E2C7
+# DTSTART;TZID=America/Los_Angeles:20151008T053000
+# DTEND;TZID=America/Los_Angeles:20151008T070000
+# ATTENDEE;CN=User 01;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:urn:x-uid:user01
+# ATTENDEE;CN=User 02;CUTYPE=INDIVIDUAL;ROLE=CHAIR:urn:x-uid:user02
+# ATTENDEE;CN=User 03;CUTYPE=INDIVIDUAL:urn:x-uid:user03
+# ATTENDEE;CN=Mercury Seven;CUTYPE=ROOM:urn:x-uid:mercury
+# CREATED:20141107T172645Z
+# DTSTAMP:20141107T172645Z
+# LOCATION:Mercury
+# ORGANIZER;CN=User 02:urn:x-uid:user02
+# SEQUENCE:0
+# SUMMARY:Other organizer
+# TRANSP:OPAQUE
+# END:VEVENT
+# END:VCALENDAR
+# &quot;&quot;&quot;
+
+# FIXME: add overrides on both attendee and organizer that aren't in the other
+
+
</ins><span class="cx"> DATA_USER02_INVITES_USER01_ATTENDEE_COPY = &quot;&quot;&quot;BEGIN:VCALENDAR
</span><span class="cx"> VERSION:2.0
</span><span class="cx"> NAME:I'm an attendee
</span><span class="lines">@@ -178,9 +241,10 @@
</span><span class="cx"> PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
</span><span class="cx"> BEGIN:VEVENT
</span><span class="cx"> UID:6DB84FB1-C943-4144-BE65-9B0DD9A9E2C7
</span><del>-DTSTART;TZID=America/Los_Angeles:20151008T053000
-DTEND;TZID=America/Los_Angeles:20151008T070000
-ATTENDEE;CN=User 01;CUTYPE=INDIVIDUAL:urn:x-uid:user01
</del><ins>+DTSTART;TZID=America/Los_Angeles:20141115T074500
+DTEND;TZID=America/Los_Angeles:20141115T091500
+RRULE:FREQ=DAILY;COUNT=20
+ATTENDEE;CN=User 01;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:urn:x-uid:user01
</ins><span class="cx"> ATTENDEE;CN=User 02;CUTYPE=INDIVIDUAL;ROLE=CHAIR:urn:x-uid:user02
</span><span class="cx"> ATTENDEE;CN=User 03;CUTYPE=INDIVIDUAL:urn:x-uid:user03
</span><span class="cx"> ATTENDEE;CN=Mercury Seven;CUTYPE=ROOM:urn:x-uid:mercury
</span><span class="lines">@@ -192,10 +256,87 @@
</span><span class="cx"> SUMMARY:Other organizer
</span><span class="cx"> TRANSP:OPAQUE
</span><span class="cx"> END:VEVENT
</span><ins>+BEGIN:VEVENT
+UID:6DB84FB1-C943-4144-BE65-9B0DD9A9E2C7
+RECURRENCE-ID;TZID=America/Los_Angeles:20141117T074500
+DTSTART;TZID=America/Los_Angeles:20141117T093000
+DTEND;TZID=America/Los_Angeles:20141117T110000
+ATTENDEE;CN=User 01;CUTYPE=INDIVIDUAL;PARTSTAT=TENTATIVE:urn:x-uid:user01
+ATTENDEE;CN=User 02;CUTYPE=INDIVIDUAL;ROLE=CHAIR:urn:x-uid:user02
+ATTENDEE;CN=User 03;CUTYPE=INDIVIDUAL:urn:x-uid:user03
+ATTENDEE;CN=Mercury Seven;CUTYPE=ROOM:urn:x-uid:mercury
+CREATED:20141107T172645Z
+DTSTAMP:20141107T172645Z
+LOCATION:Mercury
+ORGANIZER;CN=User 02:urn:x-uid:user02
+SEQUENCE:0
+SUMMARY:Other organizer
+TRANSP:OPAQUE
+END:VEVENT
+BEGIN:VEVENT
+UID:6DB84FB1-C943-4144-BE65-9B0DD9A9E2C7
+RECURRENCE-ID;TZID=America/Los_Angeles:20141121T074500
+DTSTART;TZID=America/Los_Angeles:20141121T101500
+DTEND;TZID=America/Los_Angeles:20141121T114500
+ATTENDEE;CN=User 01;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;CUTYPE=INDIVIDUAL;ROLE=CHAIR:urn:x-uid:user02
+ATTENDEE;CN=User 03;CUTYPE=INDIVIDUAL:urn:x-uid:user03
+ATTENDEE;CN=Mercury Seven;CUTYPE=ROOM:urn:x-uid:mercury
+CREATED:20141107T172645Z
+DTSTAMP:20141107T172645Z
+LOCATION:Mercury
+ORGANIZER;CN=User 02:urn:x-uid:user02
+SEQUENCE:0
+SUMMARY:Other organizer
+TRANSP:OPAQUE
+END:VEVENT
</ins><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# &quot;&quot;&quot;BEGIN:VCALENDAR
+# VERSION:2.0
+# PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+# X-WR-CALNAME:calendar
+# BEGIN:VEVENT
+# UID:431C4ADB-4EB3-47F6-A18B-29441E329948
+# DTSTART;TZID=America/Los_Angeles:20141115T074500
+# DTEND;TZID=America/Los_Angeles:20141115T091500
+# ATTENDEE;CN=Cyrus Daboo;CUTYPE=INDIVIDUAL;EMAIL=cdaboo@apple.com;RSVP=TRUE
+#  ;SCHEDULE-STATUS=1.2:urn:x-uid:1D8B3915-4CA4-487E-B3CC-4822D80DFC97
+# ATTENDEE;CN=Morgen Sagen;CUTYPE=INDIVIDUAL;EMAIL=sagen@apple.com;PARTSTAT=
+#  ACCEPTED;ROLE=CHAIR:urn:x-uid:D0B38B00-4166-11DD-B22C-A07C87F02F6A
+# CREATED:20141112T215051Z
+# DTSTAMP:20141112T215143Z
+# ORGANIZER;CN=Morgen Sagen;EMAIL=sagen@apple.com:urn:x-uid:D0B38B00-4166-11
+#  DD-B22C-A07C87F02F6A
+# RRULE:FREQ=DAILY;COUNT=20
+# SEQUENCE:1
+# SUMMARY:Repeating
+# TRANSP:OPAQUE
+# END:VEVENT
+# BEGIN:VEVENT
+# UID:431C4ADB-4EB3-47F6-A18B-29441E329948
+# RECURRENCE-ID;TZID=America/Los_Angeles:20141117T074500
+# DTSTART;TZID=America/Los_Angeles:20141117T093000
+# DTEND;TZID=America/Los_Angeles:20141117T110000
+# ATTENDEE;CN=Cyrus Daboo;CUTYPE=INDIVIDUAL;EMAIL=cdaboo@apple.com;PARTSTAT=
+#  NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:1D8B3915-4CA4-487E-B
+#  3CC-4822D80DFC97
+# ATTENDEE;CN=Morgen Sagen;CUTYPE=INDIVIDUAL;EMAIL=sagen@apple.com;PARTSTAT=
+#  ACCEPTED;ROLE=CHAIR:urn:x-uid:D0B38B00-4166-11DD-B22C-A07C87F02F6A
+# CREATED:20141112T215051Z
+# DTSTAMP:20141112T215143Z
+# ORGANIZER;CN=Morgen Sagen;EMAIL=sagen@apple.com:urn:x-uid:D0B38B00-4166-11
+#  DD-B22C-A07C87F02F6A
+# SEQUENCE:1
+# SUMMARY:Repeating
+# TRANSP:OPAQUE
+# END:VEVENT
+# END:VCALENDAR
+# &quot;&quot;&quot;
+
+
</ins><span class="cx"> class ImportTests(StoreTestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for importing data to a live store.
</span><span class="lines">@@ -376,23 +517,64 @@
</span><span class="cx">         )
</span><span class="cx">         yield txn.commit()
</span><span class="cx"> 
</span><del>-        # When importing the event again, instead trigger a re-invite
-        # from the organizer
</del><ins>+        # When importing the event again, update through the organizer's copy
+        # of the event as if it were an iTIP reply
</ins><span class="cx">         component = Component.allFromString(DATA_USER02_INVITES_USER01_ATTENDEE_COPY)
</span><span class="cx">         yield importCollectionComponent(self.store, component)
</span><span class="cx"> 
</span><span class="cx">         yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
</span><span class="cx"> 
</span><del>-        # Make sure attendee now has a new invite
</del><ins>+        # Make sure organizer now sees the right partstats
</ins><span class="cx">         txn = self.store.newTransaction()
</span><ins>+        home = yield txn.calendarHomeWithUID(&quot;user02&quot;)
+        collection = yield home.childWithName(&quot;calendar&quot;)
+        objects = yield collection.objectResources()
+        self.assertEquals(len(objects), 1)
+        component = yield objects[0].component()
+        # print(str(component))
+        props = component.getAttendeeProperties((&quot;urn:x-uid:user01&quot;,))
+        # The master is ACCEPTED
+        self.assertEquals(
+            props[0].parameterValue(&quot;PARTSTAT&quot;),
+            &quot;ACCEPTED&quot;
+        )
+        # 2nd instance is TENTATIVE
+        self.assertEquals(
+            props[1].parameterValue(&quot;PARTSTAT&quot;),
+            &quot;TENTATIVE&quot;
+        )
+        # 3rd instance is not in the attendee's copy, so remains DECLILNED
+        self.assertEquals(
+            props[2].parameterValue(&quot;PARTSTAT&quot;),
+            &quot;DECLINED&quot;
+        )
+        yield txn.commit()
+
+        # Make sure attendee now sees the right partstats
+        txn = self.store.newTransaction()
</ins><span class="cx">         home = yield txn.calendarHomeWithUID(&quot;user01&quot;)
</span><span class="cx">         collection = yield home.childWithName(&quot;calendar&quot;)
</span><span class="cx">         objects = yield collection.objectResources()
</span><span class="cx">         self.assertEquals(len(objects), 1)
</span><span class="cx">         component = yield objects[0].component()
</span><del>-        prop = component.getAttendeeProperty((&quot;urn:x-uid:user01&quot;,))
</del><ins>+        # print(str(component))
+        props = component.getAttendeeProperties((&quot;urn:x-uid:user01&quot;,))
+        # The master is ACCEPTED
</ins><span class="cx">         self.assertEquals(
</span><del>-            prop.parameterValue(&quot;PARTSTAT&quot;),
-            &quot;NEEDS-ACTION&quot;
</del><ins>+            props[0].parameterValue(&quot;PARTSTAT&quot;),
+            &quot;ACCEPTED&quot;
</ins><span class="cx">         )
</span><ins>+        # 2nd instance is TENTATIVE
+        self.assertEquals(
+            props[1].parameterValue(&quot;PARTSTAT&quot;),
+            &quot;TENTATIVE&quot;
+        )
+        # 3rd instance is not in the organizer's copy, so should inherit
+        # the value from the master, which is ACCEPTED
+        self.assertEquals(
+            props[2].parameterValue(&quot;PARTSTAT&quot;),
+            &quot;ACCEPTED&quot;
+        )
</ins><span class="cx">         yield txn.commit()
</span><ins>+
+    test_ImportComponentAttendee.todo = &quot;Need to fix iTip reply processing&quot;
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingitippy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/itip.py (14165 => 14166)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/itip.py        2014-11-13 19:57:52 UTC (rev 14165)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/itip.py        2014-11-13 20:05:54 UTC (rev 14166)
</span><span class="lines">@@ -342,7 +342,7 @@
</span><span class="cx">             C{tuple} of change info
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        assert itip_message.propertyValue(&quot;METHOD&quot;) == &quot;REPLY&quot;, &quot;iTIP message must have METHOD:REPLY&quot;
</del><ins>+        assert itip_message.propertyValue(&quot;METHOD&quot;) in (&quot;REPLY&quot;, &quot;X-RESTORE&quot;), &quot;iTIP message must have METHOD:REPLY&quot;
</ins><span class="cx">         assert itip_message.resourceUID() == calendar.resourceUID(), &quot;UIDs must be the same to process iTIP message&quot;
</span><span class="cx"> 
</span><span class="cx">         # Take each component in the reply and update the corresponding component
</span><span class="lines">@@ -986,12 +986,12 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @staticmethod
</span><del>-    def generateAttendeeReply(original, attendee, changedRids=None, force_decline=False):
</del><ins>+    def generateAttendeeReply(original, attendee, changedRids=None, force_decline=False, method=&quot;REPLY&quot;):
</ins><span class="cx"> 
</span><span class="cx">         # Start with a copy of the original as we may have to modify bits of it
</span><span class="cx">         itip = original.duplicate()
</span><span class="cx">         itip.replaceProperty(Property(&quot;PRODID&quot;, iCalendarProductID))
</span><del>-        itip.addProperty(Property(&quot;METHOD&quot;, &quot;REPLY&quot;))
</del><ins>+        itip.addProperty(Property(&quot;METHOD&quot;, method))
</ins><span class="cx"> 
</span><span class="cx">         # Now filter out components except the ones specified
</span><span class="cx">         itip.filterComponents(changedRids)
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingprocessingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py (14165 => 14166)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py        2014-11-13 19:57:52 UTC (rev 14165)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py        2014-11-13 20:05:54 UTC (rev 14166)
</span><span class="lines">@@ -147,7 +147,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def isOrganizerReceivingMessage(self):
</span><del>-        return self.method in (&quot;REPLY&quot;, &quot;REFRESH&quot;)
</del><ins>+        return self.method in (&quot;REPLY&quot;, &quot;REFRESH&quot;, &quot;X-RESTORE&quot;)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def isAttendeeReceivingMessage(self):
</span><span class="lines">@@ -181,7 +181,7 @@
</span><span class="cx">             returnValue((True, True, False, None,))
</span><span class="cx"> 
</span><span class="cx">         # Handle new items differently than existing ones.
</span><del>-        if self.method == &quot;REPLY&quot;:
</del><ins>+        if self.method in (&quot;REPLY&quot;, &quot;X-RESTORE&quot;):
</ins><span class="cx">             result = (yield self.doImplicitOrganizerUpdate())
</span><span class="cx">         elif self.method == &quot;REFRESH&quot;:
</span><span class="cx">             # With implicit we ignore refreshes.
</span><span class="lines">@@ -213,33 +213,40 @@
</span><span class="cx"> 
</span><span class="cx">             organizer = self.recipient_calendar.getOrganizer()
</span><span class="cx"> 
</span><del>-            # Build the schedule-changes XML element
</del><span class="cx">             attendeeReplying, rids = processed
</span><del>-            partstatChanged = False
-            reply_details = (customxml.Attendee.fromString(attendeeReplying),)
</del><span class="cx"> 
</span><del>-            for rid, partstatChanged, privateCommentChanged in sorted(rids):
-                recurrence = []
-                if rid == &quot;&quot;:
-                    recurrence.append(customxml.Master())
-                else:
-                    recurrence.append(customxml.RecurrenceID.fromString(rid))
-                changes = []
-                if partstatChanged:
-                    changes.append(customxml.ChangedProperty(customxml.ChangedParameter(name=&quot;PARTSTAT&quot;), name=&quot;ATTENDEE&quot;))
-                    partstatChanged = True
-                if privateCommentChanged:
-                    changes.append(customxml.ChangedProperty(name=&quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;))
-                recurrence.append(customxml.Changes(*changes))
-                reply_details += (customxml.Recurrence(*recurrence),)
</del><ins>+            if self.method == &quot;X-RESTORE&quot;:
+                changes = None
+                partstatChanged = True
+                yield self._doRefresh(self.organizer_calendar_resource, only_attendees=(attendeeReplying,))
</ins><span class="cx"> 
</span><del>-            changes = customxml.ScheduleChanges(
-                customxml.DTStamp(),
-                customxml.Action(
-                    customxml.Reply(*reply_details),
-                ),
-            )
</del><ins>+            else:
+                # Build the schedule-changes XML element
+                partstatChanged = False
+                reply_details = (customxml.Attendee.fromString(attendeeReplying),)
</ins><span class="cx"> 
</span><ins>+                for rid, partstatChanged, privateCommentChanged in sorted(rids):
+                    recurrence = []
+                    if rid == &quot;&quot;:
+                        recurrence.append(customxml.Master())
+                    else:
+                        recurrence.append(customxml.RecurrenceID.fromString(rid))
+                    changes = []
+                    if partstatChanged:
+                        changes.append(customxml.ChangedProperty(customxml.ChangedParameter(name=&quot;PARTSTAT&quot;), name=&quot;ATTENDEE&quot;))
+                        partstatChanged = True
+                    if privateCommentChanged:
+                        changes.append(customxml.ChangedProperty(name=&quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;))
+                    recurrence.append(customxml.Changes(*changes))
+                    reply_details += (customxml.Recurrence(*recurrence),)
+
+                changes = customxml.ScheduleChanges(
+                    customxml.DTStamp(),
+                    customxml.Action(
+                        customxml.Reply(*reply_details),
+                    ),
+                )
+
</ins><span class="cx">             # Only update other attendees when the partstat was changed by the reply,
</span><span class="cx">             # and only if the request does not indicate we should skip attendee refresh
</span><span class="cx">             # (e.g. inbox item processing during migration from non-implicit server)
</span></span></pre>
</div>
</div>

</body>
</html>