<!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>[13947] 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/13947">13947</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-09-10 07:52:49 -0700 (Wed, 10 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Revamp group attendee expansion to properly handle removal of the group attendee/calendar object resource link when instance expansion is not done.
Also tweak the split timing parameter to apply the split (by default) one hour from now.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavstdconfigpy">CalendarServer/trunk/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoretesttest_sqlpy">CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py</a></li>
<li><a href="#CalendarServertrunktxdavwhogroupspy">CalendarServer/trunk/txdav/who/groups.py</a></li>
<li><a href="#CalendarServertrunktxdavwhotesttest_group_attendeespy">CalendarServer/trunk/txdav/who/test/test_group_attendees.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcaldavdatastoretestaccountsgroupAttendeeAccountsxml">CalendarServer/trunk/txdav/caldav/datastore/test/accounts/groupAttendeeAccounts.xml</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py (13946 => 13947)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/stdconfig.py        2014-09-08 17:45:12 UTC (rev 13946)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py        2014-09-10 14:52:49 UTC (rev 13947)
</span><span class="lines">@@ -974,7 +974,7 @@
</span><span class="cx">     &quot;GroupAttendees&quot; : {
</span><span class="cx">         &quot;Enabled&quot;: True,
</span><span class="cx">         &quot;ReconciliationDelaySeconds&quot; : 5,
</span><del>-        &quot;UpdateOldEventLimitSeconds&quot; : 1 * 24 * 60 * 60,   # 1 day
</del><ins>+        &quot;AutoUpdateSecondsFromNow&quot; : 60 * 60,   # 1 hour
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     &quot;AutomaticPurging&quot;: {
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (13946 => 13947)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-09-08 17:45:12 UTC (rev 13946)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-09-10 14:52:49 UTC (rev 13947)
</span><span class="lines">@@ -2349,6 +2349,23 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><ins>+    def groupEventLinks(self):
+        &quot;&quot;&quot;
+        Return the current group event links for this resource.
+
+        @return: a L{dict} with group ids as the key and membership hash as the value
+        @rtype: L{dict}
+        &quot;&quot;&quot;
+        ga = schema.GROUP_ATTENDEE
+        rows = yield Select(
+            [ga.GROUP_ID, ga.MEMBERSHIP_HASH],
+            From=ga,
+            Where=ga.RESOURCE_ID == self._resourceID,
+        ).on(self._txn)
+        returnValue(dict(rows))
+
+
+    @inlineCallbacks
</ins><span class="cx">     def updateEventGroupLink(self, groupCUAToAttendeeMemberPropMap=None):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         update schema.GROUP_ATTENDEE
</span><span class="lines">@@ -2360,13 +2377,7 @@
</span><span class="cx">                 returnValue(False)
</span><span class="cx"> 
</span><span class="cx">         changed = False
</span><del>-        ga = schema.GROUP_ATTENDEE
-        rows = yield Select(
-            [ga.GROUP_ID, ga.MEMBERSHIP_HASH],
-            From=ga,
-            Where=ga.RESOURCE_ID == self._resourceID,
-        ).on(self._txn)
-        groupIDToMembershipHashMap = dict(rows)
</del><ins>+        groupIDToMembershipHashMap = (yield self.groupEventLinks())
</ins><span class="cx"> 
</span><span class="cx">         for groupCUA in groupCUAToAttendeeMemberPropMap:
</span><span class="cx">             groupRecord = yield self.directoryService().recordWithCalendarUserAddress(groupCUA)
</span><span class="lines">@@ -2379,6 +2390,7 @@
</span><span class="cx">                 _ignore_extant
</span><span class="cx">             ) = yield self._txn.groupByUID(groupUID)
</span><span class="cx"> 
</span><ins>+            ga = schema.GROUP_ATTENDEE
</ins><span class="cx">             if groupID in groupIDToMembershipHashMap:
</span><span class="cx">                 if groupIDToMembershipHashMap[groupID] != membershipHash:
</span><span class="cx">                     yield Update(
</span><span class="lines">@@ -2416,38 +2428,52 @@
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def removeOldEventGroupLink(self, component, instances, inserting, txn):
</span><ins>+        &quot;&quot;&quot;
+        Check to see if the calendar event has any instances ongoing into the future (past
+        a cut-off value in the future - default 1 hour). If there are no ongoing instances,
+        then &quot;decouple&quot; this resource from the automatic group reconciliation process as
+        past events should only show the group membership as it existed at the time.
</ins><span class="cx"> 
</span><ins>+        @param component: the iCalendar data to process
+        @type component: L{Component}
+        @param instances: list of instances
+        @type instances: L{InstanceList} or L{None}
+        @param inserting: whether or not the resource is being created
+        @type inserting: L{bool}
+        @param txn: transaction to use
+        @type txn: L{Transaction}
+        &quot;&quot;&quot;
+
</ins><span class="cx">         isOldEventWithGroupAttendees = False
</span><span class="cx"> 
</span><span class="cx">         # If this event is old, break possible tie to group update
</span><span class="cx">         if hasattr(self, &quot;_groupCUAToAttendeeMemberPropMap&quot;):
</span><span class="cx"> 
</span><del>-            if (component.masterComponent() is None or not component.isRecurring()):
-                cutoffDate_datatime = (
-                    datetime.datetime.utcnow() +
-                    datetime.timedelta(seconds=config.GroupAttendees.UpdateOldEventLimitSeconds)
</del><ins>+            # If we were not provided with any instances, then expand the component to check
+            if instances is None:
+                # Do an expansion out to the cut-off and then check to see if there
+                # are still instances beyond that
+                expand = (DateTime.getNowUTC() +
+                          Duration(seconds=config.GroupAttendees.AutoUpdateSecondsFromNow))
+
+                instances = component.expandTimeRanges(
+                    expand,
+                    lowerLimit=None,
+                    ignoreInvalidInstances=True
</ins><span class="cx">                 )
</span><del>-                tr = schema.TIME_RANGE
-                rows = yield Select(
-                    [Count(tr.CALENDAR_OBJECT_RESOURCE_ID)],
-                    From=tr,
-                    Where=(
-                        tr.CALENDAR_OBJECT_RESOURCE_ID == self._resourceID).And(
-                        tr.END_DATE &gt; cutoffDate_datatime
-                    ),
-                ).on(txn)
-                isOldEventWithGroupAttendees = rows[0][0] == 0
</del><span class="cx"> 
</span><ins>+                isOldEventWithGroupAttendees = instances.limit is None
+
+            elif len(instances.instances):
+                cutoffDate_DateTime = (
+                    DateTime.getNowUTC() +
+                    Duration(seconds=config.GroupAttendees.AutoUpdateSecondsFromNow)
+                )
+                maxInstanceKey = sorted(instance for instance in instances)[-1]
+                isOldEventWithGroupAttendees = instances[maxInstanceKey].start &lt; cutoffDate_DateTime and instances.limit is None
+
</ins><span class="cx">             else:
</span><del>-                if instances and len(instances.instances):
-                    cutoffDate_DateTime = (
-                        DateTime.getNowUTC() +
-                        Duration(seconds=config.GroupAttendees.UpdateOldEventLimitSeconds)
-                    )
-                    maxInstanceKey = sorted(instance for instance in instances)[-1]
-                    isOldEventWithGroupAttendees = cutoffDate_DateTime &gt; instances[maxInstanceKey].end
-                else:
-                    isOldEventWithGroupAttendees = True
</del><ins>+                isOldEventWithGroupAttendees = instances.limit is None
</ins><span class="cx"> 
</span><span class="cx">             if isOldEventWithGroupAttendees:
</span><span class="cx">                 if inserting:
</span><span class="lines">@@ -2464,6 +2490,65 @@
</span><span class="cx">         returnValue(isOldEventWithGroupAttendees)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def groupAttendeeChanged(self, groupID):
+        &quot;&quot;&quot;
+        One or more group attendee membership lists have changed, so sync up with those
+        changes. This might involve splitting the event if there are past instances of
+        a recurring event, since we don't want the attendee list in the past instances
+        to change.
+        &quot;&quot;&quot;
+        component = yield self.componentForUser()
+
+        # Change a copy of the original, as we need the original cached on the resource
+        # so we can do a diff to test implicit scheduling changes
+        component = component.duplicate()
+
+        # sync group attendees
+        if (yield self.reconcileGroupAttendees(component)):
+
+            # Group attendees in the event have changed
+
+            # Do not reconcile events entirely in the past
+            if (
+                yield self.removeOldEventGroupLink(
+                    component,
+                    instances=None,
+                    inserting=False,
+                    txn=self._txn
+                )
+            ):
+                returnValue(None)
+
+            # For recurring events we split the event so past instances are not reconciled
+            if component.masterComponent() is not None and component.isRecurring():
+                splitter = iCalSplitter(0, 0)
+                break_point = DateTime.getToday() + Duration(seconds=config.GroupAttendees.AutoUpdateSecondsFromNow)
+                rid = splitter.whereSplit(component, break_point=break_point)
+                if rid is not None:
+                    yield self.split(onlyThis=True, rid=rid)
+
+                    # remove group link to ensure update (update to unknown hash would work too)
+                    # FIXME: its possible that more than one group id gets updated during this single work item, so we
+                    # need to make sure that ALL the group_id's are removed by this query.
+                    ga = schema.GROUP_ATTENDEE
+                    yield Delete(
+                        From=ga,
+                        Where=(ga.RESOURCE_ID == self._resourceID).And(
+                            ga.GROUP_ID == groupID
+                        )
+                    ).on(self._txn)
+
+                    # update group attendee in remaining component
+                    component = yield self.componentForUser()
+                    component = component.duplicate()
+                    yield self.reconcileGroupAttendees(component)
+                    yield self._setComponentInternal(component, inserting=False, internal_state=ComponentUpdateState.SPLIT_OWNER)
+                    returnValue(None)
+
+            yield self.setComponent(component)
+
+
</ins><span class="cx">     def validCalendarDataCheck(self, component, inserting):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Check that the calendar data is valid iCalendar.
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoretestaccountsgroupAttendeeAccountsxml"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/caldav/datastore/test/accounts/groupAttendeeAccounts.xml (0 => 13947)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/test/accounts/groupAttendeeAccounts.xml                                (rev 0)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/accounts/groupAttendeeAccounts.xml        2014-09-10 14:52:49 UTC (rev 13947)
</span><span class="lines">@@ -0,0 +1,139 @@
</span><ins>+&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
+
+&lt;!--
+Copyright (c) 2006-2014 Apple Inc. All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ --&gt;
+
+&lt;!DOCTYPE accounts SYSTEM &quot;accounts.dtd&quot;&gt;
+
+&lt;directory realm=&quot;Test Realm&quot;&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user01&lt;/short-name&gt;
+            &lt;uid&gt;user01&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000001&lt;/guid&gt;
+            &lt;password&gt;user01&lt;/password&gt;
+            &lt;full-name&gt;User 01&lt;/full-name&gt;
+            &lt;email&gt;user01@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user02&lt;/short-name&gt;
+            &lt;uid&gt;user02&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000002&lt;/guid&gt;
+            &lt;password&gt;user02&lt;/password&gt;
+            &lt;full-name&gt;User 02&lt;/full-name&gt;
+            &lt;email&gt;user02@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user03&lt;/short-name&gt;
+            &lt;uid&gt;user03&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000003&lt;/guid&gt;
+            &lt;password&gt;user03&lt;/password&gt;
+            &lt;full-name&gt;User 03&lt;/full-name&gt;
+            &lt;email&gt;user03@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user04&lt;/short-name&gt;
+            &lt;uid&gt;user04&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000004&lt;/guid&gt;
+            &lt;password&gt;user04&lt;/password&gt;
+            &lt;full-name&gt;User 04&lt;/full-name&gt;
+            &lt;email&gt;user04@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user05&lt;/short-name&gt;
+            &lt;uid&gt;user05&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000005&lt;/guid&gt;
+            &lt;password&gt;user05&lt;/password&gt;
+            &lt;full-name&gt;User 05&lt;/full-name&gt;
+            &lt;email&gt;user05@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user06&lt;/short-name&gt;
+            &lt;uid&gt;user06&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000006&lt;/guid&gt;
+            &lt;password&gt;user06&lt;/password&gt;
+            &lt;full-name&gt;User 06&lt;/full-name&gt;
+            &lt;email&gt;user06@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user07&lt;/short-name&gt;
+            &lt;uid&gt;user07&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000007&lt;/guid&gt;
+            &lt;password&gt;user07&lt;/password&gt;
+            &lt;full-name&gt;User 07&lt;/full-name&gt;
+            &lt;email&gt;user07@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user08&lt;/short-name&gt;
+            &lt;uid&gt;user08&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000008&lt;/guid&gt;
+            &lt;password&gt;user08&lt;/password&gt;
+            &lt;full-name&gt;User 08&lt;/full-name&gt;
+            &lt;email&gt;user08@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user09&lt;/short-name&gt;
+            &lt;uid&gt;user09&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000009&lt;/guid&gt;
+            &lt;password&gt;user09&lt;/password&gt;
+            &lt;full-name&gt;User 09&lt;/full-name&gt;
+            &lt;email&gt;user09@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;user&quot;&gt;
+            &lt;short-name&gt;user10&lt;/short-name&gt;
+            &lt;uid&gt;user10&lt;/uid&gt;
+            &lt;guid&gt;10000000-0000-0000-0000-000000000010&lt;/guid&gt;
+            &lt;password&gt;user10&lt;/password&gt;
+            &lt;full-name&gt;User 10&lt;/full-name&gt;
+            &lt;email&gt;user10@example.com&lt;/email&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;group&quot;&gt;
+            &lt;short-name&gt;group01&lt;/short-name&gt;
+            &lt;uid&gt;group01&lt;/uid&gt;
+            &lt;guid&gt;20000000-0000-0000-0000-000000000001&lt;/guid&gt;
+            &lt;full-name&gt;Group 01&lt;/full-name&gt;
+            &lt;email&gt;group01@example.com&lt;/email&gt;
+            &lt;member-uid&gt;user02&lt;/member-uid&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;group&quot;&gt;
+            &lt;short-name&gt;group02&lt;/short-name&gt;
+            &lt;uid&gt;group02&lt;/uid&gt;
+            &lt;guid&gt;20000000-0000-0000-0000-000000000002&lt;/guid&gt;
+            &lt;full-name&gt;Group 02&lt;/full-name&gt;
+            &lt;email&gt;group02@example.com&lt;/email&gt;
+            &lt;member-uid&gt;user06&lt;/member-uid&gt;
+            &lt;member-uid&gt;user07&lt;/member-uid&gt;
+            &lt;member-uid&gt;user08&lt;/member-uid&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;group&quot;&gt;
+            &lt;short-name&gt;group03&lt;/short-name&gt;
+            &lt;uid&gt;group03&lt;/uid&gt;
+            &lt;guid&gt;20000000-0000-0000-0000-000000000003&lt;/guid&gt;
+            &lt;full-name&gt;Group 03&lt;/full-name&gt;
+            &lt;email&gt;group03@example.com&lt;/email&gt;
+            &lt;member-uid&gt;user07&lt;/member-uid&gt;
+            &lt;member-uid&gt;user08&lt;/member-uid&gt;
+            &lt;member-uid&gt;user09&lt;/member-uid&gt;
+        &lt;/record&gt;
+        &lt;record type=&quot;group&quot;&gt;
+            &lt;short-name&gt;group04&lt;/short-name&gt;
+            &lt;uid&gt;group04&lt;/uid&gt;
+            &lt;guid&gt;20000000-0000-0000-0000-000000000004&lt;/guid&gt;
+            &lt;full-name&gt;Group 04&lt;/full-name&gt;
+            &lt;member-uid&gt;group02&lt;/member-uid&gt;
+            &lt;member-uid&gt;group03&lt;/member-uid&gt;
+            &lt;member-uid&gt;user10&lt;/member-uid&gt;
+        &lt;/record&gt;
+&lt;/directory&gt;
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoretesttest_sqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py (13946 => 13947)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py        2014-09-08 17:45:12 UTC (rev 13946)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py        2014-09-10 14:52:49 UTC (rev 13947)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> from txweb2.http_headers import MimeType
</span><span class="cx"> from txweb2.stream import MemoryStream
</span><span class="cx"> 
</span><ins>+from twisted.python.filepath import FilePath
</ins><span class="cx"> from twisted.internet import reactor
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, DeferredList, \
</span><span class="cx">     succeed
</span><span class="lines">@@ -74,6 +75,7 @@
</span><span class="cx"> from twext.enterprise.jobqueue import JobItem
</span><span class="cx"> 
</span><span class="cx"> import datetime
</span><ins>+import os
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class CalendarSQLStorageTests(CalendarCommonTests, unittest.TestCase):
</span><span class="lines">@@ -7756,3 +7758,932 @@
</span><span class="cx">         yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
</span><span class="cx"> 
</span><span class="cx">         self.assertEqual(self.trcount, 6)
</span><ins>+
+
+
+class GroupExpand(CommonCommonTests, unittest.TestCase):
+    &quot;&quot;&quot;
+    CalendarObject group attendee expansion.
+    &quot;&quot;&quot;
+
+    @inlineCallbacks
+    def setUp(self):
+        yield super(GroupExpand, self).setUp()
+
+        accountsFilePath = FilePath(
+            os.path.join(os.path.dirname(__file__), &quot;accounts&quot;)
+        )
+        yield self.buildStoreAndDirectory(
+            accounts=accountsFilePath.child(&quot;groupAttendeeAccounts.xml&quot;),
+        )
+
+        yield self.populate()
+
+        now = DateTime.getNowUTC()
+        now.setDateOnly(True)
+        past1 = now.duplicate()
+        past1.offsetDay(-1)
+        past2 = now.duplicate()
+        past2.offsetDay(-2)
+        past400 = now.duplicate()
+        past400.offsetDay(-400)
+        now1 = now.duplicate()
+        now1.offsetDay(1)
+        now2 = now.duplicate()
+        now2.offsetDay(2)
+        self.subs = {
+            &quot;now&quot;: now,
+            &quot;past1&quot;: past1,
+            &quot;past2&quot;: past2,
+            &quot;past400&quot;: past400,
+            &quot;now1&quot;: now1,
+            &quot;now2&quot;: now2,
+        }
+
+
+    @inlineCallbacks
+    def populate(self):
+        yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
+        self.notifierFactory.reset()
+
+
+    @property
+    def requirements(self):
+        return {
+            &quot;user01&quot;: {
+                &quot;calendar&quot;: {},
+                &quot;inbox&quot;: {},
+            },
+            &quot;user02&quot;: {
+                &quot;calendar&quot;: {},
+                &quot;inbox&quot;: {},
+            },
+            &quot;user03&quot;: {
+                &quot;calendar&quot;: {},
+                &quot;inbox&quot;: {},
+            },
+        }
+
+
+    @inlineCallbacks
+    def test_expand_insert(self):
+        &quot;&quot;&quot;
+        Test that creating an event with a group attendee triggers expansion.
+        &quot;&quot;&quot;
+
+        event = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SUMMARY:New Event
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT causes expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+
+
+    @inlineCallbacks
+    def test_expand_update_new(self):
+        &quot;&quot;&quot;
+        Test that updating an event with a new group attendee triggers expansion, both with
+        and without a time range change.
+        &quot;&quot;&quot;
+        event1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        event2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SEQUENCE:1
+SUMMARY:New Event
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT does not cause expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event1))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 0)
+        yield self.commit()
+
+        # PUT causes expansion
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        yield calobj.setComponent(Component.fromString(event2))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+
+
+    @inlineCallbacks
+    def test_expand_update_existing(self):
+        &quot;&quot;&quot;
+        Test that updating an event with an existing group attendee leaves expansion in place,
+        both with and without a time range change.
+        &quot;&quot;&quot;
+        event1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        event2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SEQUENCE:1
+SUMMARY:New Event #2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        event3 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T130000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SEQUENCE:1
+SUMMARY:New Event #2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T130000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SEQUENCE:2
+SUMMARY:New Event #2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT causes expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event1))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+        yield self.commit()
+
+        # PUT expansion done - no time-range change
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        yield calobj.setComponent(Component.fromString(event2))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+
+        # PUT expansion done - time-range change
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        yield calobj.setComponent(Component.fromString(event3))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+
+
+    @inlineCallbacks
+    def test_expand_insert_recurring(self):
+        &quot;&quot;&quot;
+        Test that creating an event with a group attendee triggers expansion.
+        &quot;&quot;&quot;
+
+        event = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+RRULE:FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+RRULE:FREQ=DAILY
+SUMMARY:New Event
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT causes expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+
+
+    @inlineCallbacks
+    def test_expand_update_new_recurring(self):
+        &quot;&quot;&quot;
+        Test that updating an event with a new group attendee triggers expansion, both with
+        and without a time range change.
+        &quot;&quot;&quot;
+        event1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+RRULE:FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        event2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+RRULE:FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:New Event
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT does not cause expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event1))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 0)
+        yield self.commit()
+
+        # PUT causes expansion
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        yield calobj.setComponent(Component.fromString(event2))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+
+
+    @inlineCallbacks
+    def test_expand_update_existing_recurring(self):
+        &quot;&quot;&quot;
+        Test that updating an event with an existing group attendee leaves expansion in place,
+        both with and without a time range change.
+        &quot;&quot;&quot;
+        event1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+RRULE:FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        event2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:New Event #2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        event3 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T130000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:New Event #2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{now1}T130000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+RRULE:FREQ=DAILY
+SEQUENCE:2
+SUMMARY:New Event #2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT causes expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event1))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+        yield self.commit()
+
+        # PUT expansion done - no time-range change
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        yield calobj.setComponent(Component.fromString(event2))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+
+        # PUT expansion done - time-range change
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        yield calobj.setComponent(Component.fromString(event3))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+
+
+    @inlineCallbacks
+    def test_expand_insert_past(self):
+        &quot;&quot;&quot;
+        Test that creating an event with a group attendee triggers expansion.
+        &quot;&quot;&quot;
+
+        event = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{past1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{past1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SUMMARY:New Event
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT causes expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 0)
+
+
+    @inlineCallbacks
+    def test_expand_update_new_past(self):
+        &quot;&quot;&quot;
+        Test that updating an event with a new group attendee triggers expansion, both with
+        and without a time range change.
+        &quot;&quot;&quot;
+        event1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{past1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        event2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{past1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{past1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SEQUENCE:1
+SUMMARY:New Event
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT does not cause expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event1))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 0)
+        yield self.commit()
+
+        # PUT causes expansion
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        yield calobj.setComponent(Component.fromString(event2))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 0)
+
+
+    @inlineCallbacks
+    def test_expand_update_existing_past(self):
+        &quot;&quot;&quot;
+        Test that updating an event with an existing group attendee leaves expansion in place,
+        both with and without a time range change.
+        &quot;&quot;&quot;
+        event1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{past1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        event2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{past1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SEQUENCE:1
+SUMMARY:New Event #2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        event3 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{past1}T130000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SEQUENCE:1
+SUMMARY:New Event #2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{past1}T130000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+SEQUENCE:2
+SUMMARY:New Event #2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT causes expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event1))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 0)
+        yield self.commit()
+
+        # PUT expansion done - no time-range change
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        yield calobj.setComponent(Component.fromString(event2))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 0)
+
+        # PUT expansion done - time-range change
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        yield calobj.setComponent(Component.fromString(event3))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 0)
+
+
+    @inlineCallbacks
+    def test_expand_insert_recurrence_big_future_step(self):
+        &quot;&quot;&quot;
+        Test that creating an event with a recurrence with one instance in the past and one in the distant
+        future is properly linked.
+        &quot;&quot;&quot;
+
+        event = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{past1}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+RRULE:FREQ=YEARLY;INTERVAL=2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{past1}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+RRULE:FREQ=YEARLY;INTERVAL=2
+SUMMARY:New Event
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT causes expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
+
+
+    @inlineCallbacks
+    def test_expand_insert_recurrence_big_past_step(self):
+        &quot;&quot;&quot;
+        Test that creating an event with a recurrence with one instance in the distant past and one in the distant
+        future is properly linked.
+        &quot;&quot;&quot;
+
+        event = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:{past400}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:urn:x-uid:group01
+RRULE:FREQ=YEARLY;INTERVAL=4
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTAMP:20100203T013909Z
+DTSTART:{past400}T120000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;SCHEDULE-STATUS=2.7:urn:x-uid:group01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;MEMBER=&quot;urn:x-uid:group01&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:user02
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+RRULE:FREQ=YEARLY;INTERVAL=4
+SUMMARY:New Event
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.format(**self.subs)
+
+        # PUT causes expansion
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(event))
+        yield self.commit()
+
+        calobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield calobj.componentForUser()
+        self.assertEqual(normalize_iCalStr(comp), normalize_iCalStr(result), msg=diff_iCalStrs(comp, result))
+
+        links = yield calobj.groupEventLinks()
+        self.assertEqual(len(links), 1)
</ins></span></pre></div>
<a id="CalendarServertrunktxdavwhogroupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/groups.py (13946 => 13947)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/groups.py        2014-09-08 17:45:12 UTC (rev 13946)
+++ CalendarServer/trunk/txdav/who/groups.py        2014-09-10 14:52:49 UTC (rev 13947)
</span><span class="lines">@@ -19,16 +19,13 @@
</span><span class="cx"> Group membership caching
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-from pycalendar.datetime import DateTime
-from pycalendar.duration import Duration
</del><span class="cx"> from twext.enterprise.dal.record import fromTable
</span><span class="cx"> from twext.enterprise.dal.syntax import Delete, Select, Parameter
</span><span class="cx"> from twext.enterprise.jobqueue import WorkItem, RegeneratingWorkItem
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from txdav.caldav.datastore.scheduling.icalsplitter import iCalSplitter
-from txdav.caldav.datastore.sql import CalendarStoreFeatures, ComponentUpdateState
</del><ins>+from txdav.caldav.datastore.sql import CalendarStoreFeatures
</ins><span class="cx"> from txdav.common.datastore.sql_tables import schema, _BIND_MODE_OWN
</span><span class="cx"> import datetime
</span><span class="cx"> import time
</span><span class="lines">@@ -173,84 +170,10 @@
</span><span class="cx">         ).calendarObjectWithID(
</span><span class="cx">             self.transaction, self.resourceID
</span><span class="cx">         )
</span><del>-        component = yield calendarObject.componentForUser()
</del><ins>+        yield calendarObject.groupAttendeeChanged(self.groupID)
</ins><span class="cx"> 
</span><del>-        # Change a copy of the original, as we need the original cached on the resource
-        # so we can do a diff to test implicit scheduling changes
-        component = component.duplicate()
</del><span class="cx"> 
</span><del>-        # sync group attendees
-        if (yield calendarObject.reconcileGroupAttendees(component)):
</del><span class="cx"> 
</span><del>-            # group attendees in event have changed
-            if (component.masterComponent() is None or not component.isRecurring()):
-
-                # skip non-recurring old events, no instances
-                if (
-                    yield calendarObject.removeOldEventGroupLink(
-                        component,
-                        instances=None,
-                        inserting=False,
-                        txn=self.transaction
-                    )
-                ):
-                    returnValue(None)
-            else:
-                # skip recurring old events
-                expand = (DateTime.getToday() +
-                          Duration(days=config.FreeBusyIndexExpandAheadDays))
-
-                if config.FreeBusyIndexLowerLimitDays:
-                    truncateLowerLimit = DateTime.getToday()
-                    truncateLowerLimit.offsetDay(-config.FreeBusyIndexLowerLimitDays)
-                else:
-                    truncateLowerLimit = None
-
-                instances = component.expandTimeRanges(
-                    expand,
-                    lowerLimit=truncateLowerLimit,
-                    ignoreInvalidInstances=True
-                )
-                if (
-                    yield calendarObject.removeOldEventGroupLink(
-                        component,
-                        instances=instances,
-                        inserting=False,
-                        txn=self.transaction
-                    )
-                ):
-                    returnValue(None)
-
-                # split spanning events and only update present-future split result
-                splitter = iCalSplitter(0, 1)
-                break_point = DateTime.getToday() - Duration(seconds=config.GroupAttendees.UpdateOldEventLimitSeconds)
-                rid = splitter.whereSplit(component, break_point=break_point)
-                if rid is not None:
-                    yield calendarObject.split(onlyThis=True, rid=rid)
-
-                    # remove group link to ensure update (update to unknown hash would work too)
-                    # FIXME: its possible that more than one group id gets updated during this single work item, so we
-                    # need to make sure that ALL the group_id's are removed by this query.
-                    ga = schema.GROUP_ATTENDEE
-                    yield Delete(
-                        From=ga,
-                        Where=(ga.RESOURCE_ID == self.resourceID).And(
-                            ga.GROUP_ID == self.groupID
-                        )
-                    ).on(self.transaction)
-
-                    # update group attendee in remaining component
-                    component = yield calendarObject.componentForUser()
-                    component = component.duplicate()
-                    change = yield calendarObject.reconcileGroupAttendees(component)
-                    assert change
-                    yield calendarObject._setComponentInternal(component, False, ComponentUpdateState.SPLIT_OWNER)
-                    returnValue(None)
-
-            yield calendarObject.setComponent(component)
-
-
-
</del><span class="cx"> class GroupShareeReconciliationWork(
</span><span class="cx">     WorkItem, fromTable(schema.GROUP_SHAREE_RECONCILE_WORK)
</span><span class="cx"> ):
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhotesttest_group_attendeespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/test/test_group_attendees.py (13946 => 13947)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-09-08 17:45:12 UTC (rev 13946)
+++ CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-09-10 14:52:49 UTC (rev 13947)
</span><span class="lines">@@ -58,7 +58,7 @@
</span><span class="cx">         super(GroupAttendeeTestBase, self).configure()
</span><span class="cx">         config.GroupAttendees.Enabled = True
</span><span class="cx">         config.GroupAttendees.ReconciliationDelaySeconds = 0
</span><del>-        config.GroupAttendees.UpdateOldEventLimitSeconds = 0
</del><ins>+        config.GroupAttendees.AutoUpdateSecondsFromNow = 0
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre>
</div>
</div>

</body>
</html>