<!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>[13633] CalendarServer/trunk/txdav</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/13633">13633</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2014-06-12 03:06:36 -0700 (Thu, 12 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Do not update past instance of event that spans past to future</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/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>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (13632 => 13633)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-06-11 18:38:06 UTC (rev 13632)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-06-12 10:06:36 UTC (rev 13633)
</span><span class="lines">@@ -1961,7 +1961,7 @@
</span><span class="cx"> 
</span><span class="cx">         # sync group attendee members if inserting or group changed
</span><span class="cx">         changed = False
</span><del>-        if inserting or (yield self.updateGROUP_ATTENDEE(groupCUAToAttendeeMemberPropMap)):
</del><ins>+        if inserting or (yield self.updateEventGroupLink(groupCUAToAttendeeMemberPropMap)):
</ins><span class="cx">             changed = component.reconcileGroupAttendees(groupCUAToAttendeeMemberPropMap)
</span><span class="cx"> 
</span><span class="cx">         # save for post processing when self._resourceID is non-zero
</span><span class="lines">@@ -1971,7 +1971,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def updateGROUP_ATTENDEE(self, groupCUAToAttendeeMemberPropMap=None):
</del><ins>+    def updateEventGroupLink(self, groupCUAToAttendeeMemberPropMap=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         update schema.GROUP_ATTENDEE
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -2037,8 +2037,10 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def deleteOldGROUP_ATTENDEE(self, component, instances, inserting, txn):
</del><ins>+    def removeOldEventGroupLink(self, component, instances, inserting, txn):
</ins><span class="cx"> 
</span><ins>+        isOldEventWithGroupAttendees = False
+
</ins><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><span class="lines">@@ -2056,7 +2058,7 @@
</span><span class="cx">                         tr.END_DATE &gt; cutoffDate_datatime
</span><span class="cx">                     ),
</span><span class="cx">                 ).on(txn)
</span><del>-                isOld = rows[0][0] == 0
</del><ins>+                isOldEventWithGroupAttendees = rows[0][0] == 0
</ins><span class="cx"> 
</span><span class="cx">             else:
</span><span class="cx">                 if instances and len(instances.instances):
</span><span class="lines">@@ -2065,13 +2067,13 @@
</span><span class="cx">                         Duration(seconds=config.GroupAttendees.UpdateOldEventLimitSeconds)
</span><span class="cx">                     )
</span><span class="cx">                     maxInstanceKey = sorted(instance for instance in instances)[-1]
</span><del>-                    isOld = cutoffDate_DateTime &gt; instances[maxInstanceKey].end
</del><ins>+                    isOldEventWithGroupAttendees = cutoffDate_DateTime &gt; instances[maxInstanceKey].end
</ins><span class="cx">                 else:
</span><del>-                    isOld = True
</del><ins>+                    isOldEventWithGroupAttendees = True
</ins><span class="cx"> 
</span><del>-            if isOld:
</del><ins>+            if isOldEventWithGroupAttendees:
</ins><span class="cx">                 if inserting:
</span><del>-                    # don't create GROUP_ATTENDEE rows in updateGROUP_ATTENDEE()
</del><ins>+                    # don't create GROUP_ATTENDEE rows in updateEventGroupLink()
</ins><span class="cx">                     del self._groupCUAToAttendeeMemberPropMap
</span><span class="cx">                 else:
</span><span class="cx">                     # delete existing group rows
</span><span class="lines">@@ -2082,7 +2084,9 @@
</span><span class="cx">                         #Return=[ga.GROUP_ID]
</span><span class="cx">                     ).on(txn)
</span><span class="cx"> 
</span><ins>+        returnValue(isOldEventWithGroupAttendees)
</ins><span class="cx"> 
</span><ins>+
</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 class="lines">@@ -2777,7 +2781,7 @@
</span><span class="cx"> 
</span><span class="cx">         # update GROUP_ATTENDEE table rows
</span><span class="cx">         if inserting:
</span><del>-            yield self.updateGROUP_ATTENDEE()
</del><ins>+            yield self.updateEventGroupLink()
</ins><span class="cx"> 
</span><span class="cx">         # Post process managed attachments
</span><span class="cx">         if internal_state in (
</span><span class="lines">@@ -2915,7 +2919,7 @@
</span><span class="cx"> 
</span><span class="cx">             # Now coerce indexing to off if needed
</span><span class="cx">             if not doInstanceIndexing:
</span><del>-                #instances = None # used by deleteOldGROUP_ATTENDEE() call at end
</del><ins>+                #instances = None # used by removeOldEventGroupLink() call at end
</ins><span class="cx">                 recurrenceLowerLimit = None
</span><span class="cx">                 recurrenceLimit = DateTime(1900, 1, 1, 0, 0, 0, tzid=Timezone(utc=True))
</span><span class="cx"> 
</span><span class="lines">@@ -3025,7 +3029,7 @@
</span><span class="cx">         if instanceIndexingRequired and doInstanceIndexing:
</span><span class="cx">             yield self._addInstances(component, instances, truncateLowerLimit, isInboxItem, txn)
</span><span class="cx"> 
</span><del>-        yield self.deleteOldGROUP_ATTENDEE(component, instances, inserting, txn)
</del><ins>+        yield self.removeOldEventGroupLink(component, instances, inserting, txn)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -4048,7 +4052,7 @@
</span><span class="cx">             in L{CalendarObject.splitAt}).
</span><span class="cx">         @type rid: L{DateTime}
</span><span class="cx">         @param olderUID: sets the iCalendar UID to be used in the new resource created during the split.
</span><del>-            If set to L{None}, a UUID is generated and used.
</del><ins>+            If L{None} a UUID is generated and used.
</ins><span class="cx">         @type olderUID: L{str}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhogroupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/groups.py (13632 => 13633)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/groups.py        2014-06-11 18:38:06 UTC (rev 13632)
+++ CalendarServer/trunk/txdav/who/groups.py        2014-06-12 10:06:36 UTC (rev 13633)
</span><span class="lines">@@ -19,13 +19,16 @@
</span><span class="cx"> Group membership caching
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+from pycalendar.datetime import DateTime
+from pycalendar.duration import Duration
</ins><span class="cx"> from twext.enterprise.dal.record import fromTable
</span><span class="cx"> from twext.enterprise.dal.syntax import Delete, Select
</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.sql import CalendarStoreFeatures
</del><ins>+from txdav.caldav.datastore.scheduling.icalsplitter import iCalSplitter
+from txdav.caldav.datastore.sql import CalendarStoreFeatures, ComponentUpdateState
</ins><span class="cx"> from txdav.common.datastore.sql_tables import schema
</span><span class="cx"> import datetime
</span><span class="cx"> import hashlib
</span><span class="lines">@@ -135,7 +138,11 @@
</span><span class="cx">         ).on(self.transaction)
</span><span class="cx"> 
</span><span class="cx">         # get db object
</span><del>-        calendarObject = (yield CalendarStoreFeatures(self.transaction._store).calendarObjectWithID(self.transaction, self.resourceID))
</del><ins>+        calendarObject = yield CalendarStoreFeatures(
+            self.transaction._store
+        ).calendarObjectWithID(
+            self.transaction, self.resourceID
+        )
</ins><span class="cx">         component = yield calendarObject.componentForUser()
</span><span class="cx"> 
</span><span class="cx">         # Change a copy of the original, as we need the original cached on the resource
</span><span class="lines">@@ -144,6 +151,66 @@
</span><span class="cx"> 
</span><span class="cx">         # sync group attendees
</span><span class="cx">         if (yield calendarObject.reconcileGroupAttendees(component)):
</span><ins>+
+            # 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)
+                    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)
+
</ins><span class="cx">             yield calendarObject.setComponent(component)
</span><span class="cx"> 
</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 (13632 => 13633)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-06-11 18:38:06 UTC (rev 13632)
+++ CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-06-12 10:06:36 UTC (rev 13633)
</span><span class="lines">@@ -18,8 +18,7 @@
</span><span class="cx">     group attendee tests
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-import os
-
</del><ins>+from twext.enterprise.dal.syntax import Insert
</ins><span class="cx"> from twext.enterprise.jobqueue import JobItem
</span><span class="cx"> from twext.python.filepath import CachingFilePath as FilePath
</span><span class="cx"> from twext.who.directory import DirectoryService
</span><span class="lines">@@ -29,8 +28,10 @@
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.ical import Component, normalize_iCalStr, ignoredComponents
</span><span class="cx"> from txdav.caldav.datastore.test.util import populateCalendarsFrom, CommonCommonTests
</span><ins>+from txdav.common.datastore.sql_tables import schema
</ins><span class="cx"> from txdav.who.directory import CalendarDirectoryRecordMixin
</span><span class="cx"> from txdav.who.groups import GroupCacher
</span><ins>+import os
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class GroupAttendeeReconciliation(CommonCommonTests, unittest.TestCase):
</span><span class="lines">@@ -508,6 +509,7 @@
</span><span class="cx"> 
</span><span class="cx">         groupsToRefresh = yield groupCacher.groupsToRefresh(self.transactionUnderTest())
</span><span class="cx">         self.assertEqual(len(groupsToRefresh), 1)
</span><ins>+        self.assertEqual(list(groupsToRefresh)[0], &quot;20000000-0000-0000-0000-000000000001&quot;)
</ins><span class="cx"> 
</span><span class="cx">         wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</span><span class="cx">         yield self.commit()
</span><span class="lines">@@ -649,6 +651,7 @@
</span><span class="cx"> 
</span><span class="cx">         groupsToRefresh = yield groupCacher.groupsToRefresh(self.transactionUnderTest())
</span><span class="cx">         self.assertEqual(len(groupsToRefresh), 1)
</span><ins>+        self.assertEqual(list(groupsToRefresh)[0], &quot;20000000-0000-0000-0000-000000000001&quot;)
</ins><span class="cx"> 
</span><span class="cx">         wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</span><span class="cx">         yield self.commit()
</span><span class="lines">@@ -824,6 +827,7 @@
</span><span class="cx">             yield None
</span><span class="cx">             returnValue(set())
</span><span class="cx"> 
</span><ins>+        unpatchedExpandedMembers = CalendarDirectoryRecordMixin.expandedMembers
</ins><span class="cx">         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
</span><span class="cx"> 
</span><span class="cx">         calendar = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000002&quot;)
</span><span class="lines">@@ -833,6 +837,7 @@
</span><span class="cx"> 
</span><span class="cx">         groupsToRefresh = yield groupCacher.groupsToRefresh(self.transactionUnderTest())
</span><span class="cx">         self.assertEqual(len(groupsToRefresh), 1)
</span><ins>+        self.assertEqual(list(groupsToRefresh)[0], &quot;20000000-0000-0000-0000-000000000001&quot;)
</ins><span class="cx"> 
</span><span class="cx">         wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</span><span class="cx">         yield self.commit()
</span><span class="lines">@@ -856,12 +861,31 @@
</span><span class="cx">         self.assertEqual(normalize_iCalStr(vcalendar), normalize_iCalStr(data_get_2))
</span><span class="cx"> 
</span><span class="cx">         wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</span><del>-        if len(wps): # This is needed because the test currently fails and does actually create job items we have to wait for
-            yield self.commit()
-            yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
</del><span class="cx">         self.assertEqual(len(wps), 0)
</span><ins>+        yield self.commit()
+        yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
</ins><span class="cx"> 
</span><ins>+        #finally, simulate an event that has become old
+        self.patch(CalendarDirectoryRecordMixin, &quot;expandedMembers&quot;, unpatchedExpandedMembers)
</ins><span class="cx"> 
</span><ins>+        groupID, _ignore_name, _ignore_membershipHash, _ignore_modDate = yield self.transactionUnderTest().groupByUID(&quot;20000000-0000-0000-0000-000000000001&quot;)
+        ga = schema.GROUP_ATTENDEE
+        yield Insert({
+                ga.RESOURCE_ID: cobj._resourceID,
+                ga.GROUP_ID: groupID,
+                ga.MEMBERSHIP_HASH: (-1),
+            }
+        ).on(self.transactionUnderTest())
+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
+        self.assertEqual(len(wps), 1)
+        yield self.commit()
+        yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
+
+        cobj = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000002&quot;)
+        vcalendar = yield cobj.component()
+        self.assertEqual(normalize_iCalStr(vcalendar), normalize_iCalStr(data_get_2))
+
+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_groupChangeOldNoMasterEvent(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -957,6 +981,7 @@
</span><span class="cx">             yield None
</span><span class="cx">             returnValue(set())
</span><span class="cx"> 
</span><ins>+        unpatchedExpandedMembers = CalendarDirectoryRecordMixin.expandedMembers
</ins><span class="cx">         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
</span><span class="cx"> 
</span><span class="cx">         calendar = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000002&quot;)
</span><span class="lines">@@ -966,6 +991,7 @@
</span><span class="cx"> 
</span><span class="cx">         groupsToRefresh = yield groupCacher.groupsToRefresh(self.transactionUnderTest())
</span><span class="cx">         self.assertEqual(len(groupsToRefresh), 1)
</span><ins>+        self.assertEqual(list(groupsToRefresh)[0], &quot;20000000-0000-0000-0000-000000000001&quot;)
</ins><span class="cx"> 
</span><span class="cx">         wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</span><span class="cx">         yield self.commit()
</span><span class="lines">@@ -994,8 +1020,129 @@
</span><span class="cx">             yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
</span><span class="cx">         self.assertEqual(len(wps), 0)
</span><span class="cx"> 
</span><ins>+        #finally, simulate an event that has become old
+        self.patch(CalendarDirectoryRecordMixin, &quot;expandedMembers&quot;, unpatchedExpandedMembers)
</ins><span class="cx"> 
</span><ins>+        groupID, _ignore_name, _ignore_membershipHash, _ignore_modDate = yield self.transactionUnderTest().groupByUID(&quot;20000000-0000-0000-0000-000000000001&quot;)
+        ga = schema.GROUP_ATTENDEE
+        yield Insert({
+                ga.RESOURCE_ID: cobj._resourceID,
+                ga.GROUP_ID: groupID,
+                ga.MEMBERSHIP_HASH: (-1),
+            }
+        ).on(self.transactionUnderTest())
+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
+        self.assertEqual(len(wps), 1)
+        yield self.commit()
+        yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
+
+        cobj = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000002&quot;)
+        vcalendar = yield cobj.component()
+        self.assertEqual(normalize_iCalStr(vcalendar), normalize_iCalStr(data_get_2))
+
+
</ins><span class="cx">     @inlineCallbacks
</span><ins>+    def test_groupChangeSpanningEvent(self):
+        &quot;&quot;&quot;
+        Test that group attendee changes not applied to old recurring events
+        &quot;&quot;&quot;
+
+        data_put_1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTAMP:20051222T205953Z
+CREATED:20060101T150000Z
+DTSTART:20120101T100000Z
+DURATION:PT1H
+RRULE:FREQ=DAILY;UNTIL=20240101T100000
+SUMMARY:event 1
+UID:event1@ninevah.local
+ORGANIZER:MAILTO:user02@example.com
+ATTENDEE:mailto:user02@example.com
+ATTENDEE:MAILTO:group01@example.com
+END:VEVENT
+END:VCALENDAR&quot;&quot;&quot;
+
+        data_get_1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+BEGIN:VEVENT
+UID:event1@ninevah.local
+DTSTART:20120101T100000Z
+DURATION:PT1H
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;RSVP=TRUE:urn:x-uid:10000000-0000-0000-0000-000000000002
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;RSVP=TRUE:urn:x-uid:20000000-0000-0000-0000-000000000001
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000001&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000001
+CREATED:20060101T150000Z
+ORGANIZER;CN=User 02;EMAIL=user02@example.com:urn:x-uid:10000000-0000-0000-0000-000000000002
+RRULE:FREQ=DAILY;UNTIL=20240101T100000
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data_get_2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+BEGIN:VEVENT
+UID:event1@ninevah.local
+{start}DURATION:PT1H
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;RSVP=TRUE:urn:x-uid:10000000-0000-0000-0000-000000000002
+ATTENDEE;CN=Group 01;CUTYPE=X-SERVER-GROUP;EMAIL=group01@example.com;RSVP=TRUE:urn:x-uid:20000000-0000-0000-0000-000000000001
+CREATED:20060101T150000Z
+ORGANIZER;CN=User 02;EMAIL=user02@example.com:urn:x-uid:10000000-0000-0000-0000-000000000002
+{relatedTo}RRULE:FREQ=DAILY;UNTIL=20240101T100000
+SEQUENCE:2
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        @inlineCallbacks
+        def expandedMembers(self, records=None):
+            yield None
+            returnValue(set())
+
+        groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
+
+        calendar = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000002&quot;)
+        vcalendar = Component.fromString(data_put_1)
+        yield calendar.createCalendarObjectWithName(&quot;data1.ics&quot;, vcalendar)
+        yield self.commit()
+
+        cobj = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000002&quot;)
+        vcalendar = yield cobj.component()
+        self.assertEqual(normalize_iCalStr(vcalendar), normalize_iCalStr(data_get_1))
+
+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000001&quot;, 1)
+
+        self.patch(CalendarDirectoryRecordMixin, &quot;expandedMembers&quot;, expandedMembers)
+
+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
+        yield self.commit()
+        self.assertEqual(len(wps), 1)
+        yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
+
+        cobj = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000002&quot;)
+        vcalendar = yield cobj.component()
+
+        for component in vcalendar.subcomponents():
+            if component.name() in ignoredComponents:
+                continue
+            relatedTo = component.getProperty(&quot;RELATED-TO&quot;)
+            start = component.getProperty(&quot;DTSTART&quot;)
+            break
+
+        self.assertEqual(
+            normalize_iCalStr(vcalendar),
+            normalize_iCalStr(data_get_2.format(start=start, relatedTo=relatedTo)))
+
+
+    @inlineCallbacks
</ins><span class="cx">     def test_groupRemovalFromDirectory(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Test that removing a group from the directory also removes the expanded attendees.
</span></span></pre>
</div>
</div>

</body>
</html>