<!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>[13341] 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/13341">13341</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2014-04-20 22:11:50 -0700 (Sun, 20 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix multi-group group attendees. Mostly fix group attendees when group disappears from directory. Fix tests.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavicalpy">CalendarServer/trunk/twistedcaldav/ical.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresqlpy">CalendarServer/trunk/txdav/common/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavwhogroupspy">CalendarServer/trunk/txdav/who/groups.py</a></li>
<li><a href="#CalendarServertrunktxdavwhotestaccountsgroupAttendeeAccountsxml">CalendarServer/trunk/txdav/who/test/accounts/groupAttendeeAccounts.xml</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="CalendarServertrunktwistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/ical.py (13340 => 13341)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/ical.py        2014-04-20 23:23:23 UTC (rev 13340)
+++ CalendarServer/trunk/twistedcaldav/ical.py        2014-04-21 05:11:50 UTC (rev 13341)
</span><span class="lines">@@ -3425,7 +3425,7 @@
</span><span class="cx">                             attendeeProp.removeParameterValue(&quot;MEMBER&quot;, groupCUA)
</span><span class="cx">                             if not attendeeProp.parameterValues(&quot;MEMBER&quot;):
</span><span class="cx">                                 component.removeProperty(attendeeProp)
</span><del>-                                changed = True
</del><ins>+                            changed = True
</ins><span class="cx">                     else:
</span><span class="cx">                         if attendeeProp.value() in memberCUAs:
</span><span class="cx">                             attendeeProp.setParameter(&quot;MEMBER&quot;, parameterValues + (groupCUA,))
</span><span class="lines">@@ -3438,20 +3438,32 @@
</span><span class="cx"> 
</span><span class="cx">         changed = False
</span><span class="cx">         allMemberCUAs = set()
</span><ins>+        nonemptyGroupCUAs = set()
</ins><span class="cx">         for groupCUA, memberAttendeeProps in groupCUAToAttendeeMemberPropMap.iteritems():
</span><span class="cx">             changed |= self._reconcileGroupAttendee(groupCUA, memberAttendeeProps)
</span><span class="cx">             allMemberCUAs |= set([memberAttendeeProp.value() for memberAttendeeProp in memberAttendeeProps])
</span><ins>+            if memberAttendeeProps:
+                nonemptyGroupCUAs.add(groupCUA)
</ins><span class="cx"> 
</span><span class="cx">         # remove orphans
</span><span class="cx">         for component in self.subcomponents():
</span><span class="cx">             if component.name() in ignoredComponents:
</span><span class="cx">                 continue
</span><span class="cx"> 
</span><del>-            for attendeeMemberProp in component.properties(&quot;ATTENDEE&quot;):
-                if attendeeMemberProp.hasParameter(&quot;MEMBER&quot;):
-                    attendeeCUA = attendeeMemberProp.value()
-                    if attendeeCUA not in allMemberCUAs:
-                        component.removeProperty(attendeeMemberProp)
</del><ins>+            for attendeeProp in tuple(component.properties(&quot;ATTENDEE&quot;)):
+                if attendeeProp.hasParameter(&quot;MEMBER&quot;):
+                    attendeeCUA = attendeeProp.value()
+                    if attendeeCUA in allMemberCUAs:
+                        # remove orphan member values
+                        parameterValues = tuple(attendeeProp.parameterValues(&quot;MEMBER&quot;))
+                        for orphanGroupCUA in set(parameterValues) - nonemptyGroupCUAs:
+                            attendeeProp.removeParameterValue(&quot;MEMBER&quot;, orphanGroupCUA)
+                            if not attendeeProp.parameterValues(&quot;MEMBER&quot;):
+                                component.removeProperty(attendeeProp)
+                            changed = True
+                    else:
+                        # remove orphaned member property
+                        component.removeProperty(attendeeProp)
</ins><span class="cx">                         changed = True
</span><span class="cx"> 
</span><span class="cx">         return changed
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql.py (13340 => 13341)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql.py        2014-04-20 23:23:23 UTC (rev 13340)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py        2014-04-21 05:11:50 UTC (rev 13341)
</span><span class="lines">@@ -1054,7 +1054,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def groupByUID(self, groupUID):
</del><ins>+    def groupByUID(self, groupUID, create=True):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Return or create a record for the group UID.
</span><span class="cx"> 
</span><span class="lines">@@ -1075,7 +1075,7 @@
</span><span class="cx">                 results[0][2],  # membership hash
</span><span class="cx">                 results[0][3],  # modified timestamp
</span><span class="cx">             ))
</span><del>-        else:
</del><ins>+        elif create:
</ins><span class="cx">             savepoint = SavepointAction(&quot;groupByUID&quot;)
</span><span class="cx">             yield savepoint.acquire(self)
</span><span class="cx">             try:
</span><span class="lines">@@ -1112,6 +1112,8 @@
</span><span class="cx">                     ))
</span><span class="cx">                 else:
</span><span class="cx">                     raise
</span><ins>+        else:
+            returnValue((None, None, None, None))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhogroupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/groups.py (13340 => 13341)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/groups.py        2014-04-20 23:23:23 UTC (rev 13340)
+++ CalendarServer/trunk/txdav/who/groups.py        2014-04-21 05:11:50 UTC (rev 13341)
</span><span class="lines">@@ -306,41 +306,52 @@
</span><span class="cx">             WorkProposal is returned for tests
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self.log.debug(&quot;Faulting in group: {g}&quot;, g=groupUID)
</span><del>-        wp = None
</del><span class="cx">         record = (yield self.directory.recordWithUID(groupUID))
</span><span class="cx">         if record is None:
</span><del>-            # FIXME: the group has disappeared from the directory.
-            # How do we want to handle this?
</del><ins>+            # the group has disappeared from the directory - OK
+            # FIXME: If group reappears, it will not be used in existing events
</ins><span class="cx">             self.log.info(&quot;Group has disappeared: {g}&quot;, g=groupUID)
</span><span class="cx">         else:
</span><span class="cx">             self.log.debug(&quot;Got group record: {u}&quot;, u=record.uid)
</span><del>-            membershipHashContent = hashlib.md5()
-            members = yield record.expandedMembers()
-            members = list(members)
-            members.sort(cmp=lambda x, y: cmp(x.uid, y.uid))
-            for member in members:
-                membershipHashContent.update(str(member.uid))
-            membershipHash = membershipHashContent.hexdigest()
-            groupID, _ignore_cachedName, cachedMembershipHash, _ignore_modified = (
-                yield txn.groupByUID(groupUID)
</del><ins>+
+        groupID, _ignore_cachedName, cachedMembershipHash, _ignore_modified = (
+            yield txn.groupByUID(
+                groupUID,
+                create=(record is not None)
</ins><span class="cx">             )
</span><ins>+        )
+        wp = None
+        if groupID:
+            if record is not None:
+                membershipHashContent = hashlib.md5()
+                members = yield record.expandedMembers()
+                members = list(members)
+                members.sort(cmp=lambda x, y: cmp(x.uid, y.uid))
+                for member in members:
+                    membershipHashContent.update(str(member.uid))
+                membershipHash = membershipHashContent.hexdigest()
</ins><span class="cx"> 
</span><del>-            if cachedMembershipHash != membershipHash:
-                membershipChanged = True
-                self.log.debug(
-                    &quot;Group '{group}' changed&quot;, group=record.fullNames[0]
-                )
-            else:
-                membershipChanged = False
</del><ins>+                if cachedMembershipHash != membershipHash:
+                    membershipChanged = True
+                    self.log.debug(
+                        &quot;Group '{group}' changed&quot;, group=record.fullNames[0]
+                    )
+                else:
+                    membershipChanged = False
</ins><span class="cx"> 
</span><del>-            yield txn.updateGroup(groupUID, record.fullNames[0], membershipHash)
</del><ins>+                yield txn.updateGroup(groupUID, record.fullNames[0], membershipHash)
</ins><span class="cx"> 
</span><del>-            if membershipChanged:
-                newMemberUIDs = set()
-                for member in members:
-                    newMemberUIDs.add(member.uid)
-                yield self.synchronizeMembers(txn, groupID, newMemberUIDs)
</del><ins>+                if membershipChanged:
+                    newMemberUIDs = set()
+                    for member in members:
+                        newMemberUIDs.add(member.uid)
+                    yield self.synchronizeMembers(txn, groupID, newMemberUIDs)
</ins><span class="cx"> 
</span><ins>+            else:
+                # FIXME: Use schema's delete cascade
+                yield self.synchronizeMembers(txn, groupID, set())
+                yield txn.deleteGroup(groupID)
+
</ins><span class="cx">             wp = yield self.scheduleEventReconciliations(txn, groupID)
</span><span class="cx"> 
</span><span class="cx">         returnValue(wp)
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhotestaccountsgroupAttendeeAccountsxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/test/accounts/groupAttendeeAccounts.xml (13340 => 13341)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/accounts/groupAttendeeAccounts.xml        2014-04-20 23:23:23 UTC (rev 13340)
+++ CalendarServer/trunk/txdav/who/test/accounts/groupAttendeeAccounts.xml        2014-04-21 05:11:50 UTC (rev 13341)
</span><span class="lines">@@ -115,6 +115,7 @@
</span><span class="cx">             &lt;email&gt;group02@example.com&lt;/email&gt;
</span><span class="cx">             &lt;member-uid&gt;10000000-0000-0000-0000-000000000006&lt;/member-uid&gt;
</span><span class="cx">             &lt;member-uid&gt;10000000-0000-0000-0000-000000000007&lt;/member-uid&gt;
</span><ins>+            &lt;member-uid&gt;10000000-0000-0000-0000-000000000008&lt;/member-uid&gt;
</ins><span class="cx">         &lt;/record&gt;
</span><span class="cx">         &lt;record type=&quot;group&quot;&gt;
</span><span class="cx">             &lt;short-name&gt;group03&lt;/short-name&gt;
</span><span class="lines">@@ -122,6 +123,7 @@
</span><span class="cx">             &lt;guid&gt;20000000-0000-0000-0000-000000000003&lt;/guid&gt;
</span><span class="cx">             &lt;full-name&gt;Group 03&lt;/full-name&gt;
</span><span class="cx">             &lt;email&gt;group03@example.com&lt;/email&gt;
</span><ins>+            &lt;member-uid&gt;10000000-0000-0000-0000-000000000007&lt;/member-uid&gt;
</ins><span class="cx">             &lt;member-uid&gt;10000000-0000-0000-0000-000000000008&lt;/member-uid&gt;
</span><span class="cx">             &lt;member-uid&gt;10000000-0000-0000-0000-000000000009&lt;/member-uid&gt;
</span><span class="cx">         &lt;/record&gt;
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhotesttest_group_attendeespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/test/test_group_attendees.py (13340 => 13341)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-04-20 23:23:23 UTC (rev 13340)
+++ CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-04-21 05:11:50 UTC (rev 13341)
</span><span class="lines">@@ -18,6 +18,7 @@
</span><span class="cx">     group attendee tests
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+from twext.who.directory import DirectoryService
</ins><span class="cx"> from twext.who.test.test_xml import xmlService
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> from twisted.trial import unittest
</span><span class="lines">@@ -92,6 +93,13 @@
</span><span class="cx">         self.assertEqual(count, expected_count)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    # better error output
+    def _assertICalStrEqual(self, iCalStr1, iCalStr2):
+        if normalize_iCalStr(iCalStr1, sort=True) != normalize_iCalStr(iCalStr2, sort=True):
+            self.assertEqual(normalize_iCalStr(iCalStr1), normalize_iCalStr(iCalStr2))
+            self.assertTrue(False)
+
+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_simplePUT(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -128,6 +136,7 @@
</span><span class="cx"> ATTENDEE;CN=Group 02;CUTYPE=GROUP;EMAIL=group02@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000002
</span><span class="cx"> ATTENDEE;CN=User 06;EMAIL=user06@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000006
</span><span class="cx"> ATTENDEE;CN=User 07;EMAIL=user07@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000007
</span><ins>+ATTENDEE;CN=User 08;EMAIL=user08@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000008
</ins><span class="cx"> CREATED:20060101T150000Z
</span><span class="cx"> ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:10000000-0000-0000-0000-000000000001
</span><span class="cx"> SUMMARY:event 1
</span><span class="lines">@@ -144,7 +153,7 @@
</span><span class="cx"> 
</span><span class="cx">         cobj1 = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000001&quot;)
</span><span class="cx">         vcalendar2 = yield cobj1.component()
</span><del>-        self.assertEqual(normalize_iCalStr(vcalendar2, sort=True), normalize_iCalStr(data_get_1, sort=True))
</del><ins>+        self._assertICalStrEqual(vcalendar2, data_get_1)
</ins><span class="cx"> 
</span><span class="cx">         yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000006&quot;, 1)
</span><span class="cx">         yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000007&quot;, 1)
</span><span class="lines">@@ -309,7 +318,7 @@
</span><span class="cx"> 
</span><span class="cx">         cobj1 = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000001&quot;)
</span><span class="cx">         vcalendar2 = yield cobj1.component()
</span><del>-        self.assertEqual(normalize_iCalStr(vcalendar2, sort=True), normalize_iCalStr(data_get_1, sort=True))
</del><ins>+        self._assertICalStrEqual(vcalendar2, data_get_1)
</ins><span class="cx"> 
</span><span class="cx">         yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000006&quot;, 1)
</span><span class="cx">         yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000007&quot;, 1)
</span><span class="lines">@@ -361,16 +370,15 @@
</span><span class="cx"> ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000001
</span><span class="cx"> ATTENDEE;CN=Group 02;CUTYPE=GROUP;EMAIL=group02@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000002
</span><span class="cx"> ATTENDEE;CN=Group 03;CUTYPE=GROUP;EMAIL=group03@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000003
</span><del>-ATTENDEE;CN=User 08;EMAIL=user08@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000008
</del><ins>+ATTENDEE;CN=User 06;EMAIL=user06@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000006
+ATTENDEE;CN=User 07;EMAIL=user07@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;,&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000007
+ATTENDEE;CN=User 08;EMAIL=user08@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;,&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000008
</ins><span class="cx"> ATTENDEE;CN=User 09;EMAIL=user09@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000009
</span><del>-ATTENDEE;CN=User 06;EMAIL=user06@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000006
-ATTENDEE;CN=User 07;EMAIL=user07@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000007
</del><span class="cx"> CREATED:20060101T150000Z
</span><span class="cx"> ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:10000000-0000-0000-0000-000000000001
</span><span class="cx"> SUMMARY:event 1
</span><span class="cx"> END:VEVENT
</span><del>-END:VCALENDAR
-&quot;&quot;&quot;
</del><ins>+END:VCALENDAR&quot;&quot;&quot;
</ins><span class="cx"> 
</span><span class="cx">         vcalendar1 = Component.fromString(data_put_1)
</span><span class="cx">         yield calendar.createCalendarObjectWithName(&quot;data1.ics&quot;, vcalendar1)
</span><span class="lines">@@ -378,7 +386,7 @@
</span><span class="cx"> 
</span><span class="cx">         cobj1 = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000001&quot;)
</span><span class="cx">         vcalendar2 = yield cobj1.component()
</span><del>-        self.assertEqual(normalize_iCalStr(vcalendar2, sort=True), normalize_iCalStr(data_get_1, sort=True))
</del><ins>+        self._assertICalStrEqual(vcalendar2, data_get_1)
</ins><span class="cx"> 
</span><span class="cx">         yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000006&quot;, 1)
</span><span class="cx">         yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000007&quot;, 1)
</span><span class="lines">@@ -386,6 +394,7 @@
</span><span class="cx">         yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000009&quot;, 1)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    #TODO:  Change to multigroup case
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_groupChange(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -524,4 +533,139 @@
</span><span class="cx">         that an attendee in two groups is NOT removed if only one of those groups is removed
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        self.fail(&quot;FIXME: implement this test&quot;)
</del><ins>+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000006&quot;, 0)
+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000007&quot;, 0)
+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000008&quot;, 0)
+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000009&quot;, 0)
+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000010&quot;, 0)
+
+        calendar = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000001&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;TZID=US/Eastern:20140101T100000
+DURATION:PT1H
+SUMMARY:event 1
+UID:event1@ninevah.local
+ORGANIZER:MAILTO:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:MAILTO:group01@example.com
+ATTENDEE:MAILTO:group02@example.com
+ATTENDEE:MAILTO:group03@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;TZID=US/Eastern:20140101T100000
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;RSVP=TRUE:urn:x-uid:10000000-0000-0000-0000-000000000001
+ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000001
+ATTENDEE;CN=Group 02;CUTYPE=GROUP;EMAIL=group02@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000002
+ATTENDEE;CN=Group 03;CUTYPE=GROUP;EMAIL=group03@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000003
+ATTENDEE;CN=User 06;EMAIL=user06@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000006
+ATTENDEE;CN=User 07;EMAIL=user07@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;,&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000007
+ATTENDEE;CN=User 08;EMAIL=user08@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000002&quot;,&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000008
+ATTENDEE;CN=User 09;EMAIL=user09@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000009
+CREATED:20060101T150000Z
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:10000000-0000-0000-0000-000000000001
+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
+DTSTART;TZID=US/Eastern:20140101T100000
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;RSVP=TRUE:urn:x-uid:10000000-0000-0000-0000-000000000001
+ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000001
+ATTENDEE;CN=Group 02;CUTYPE=GROUP;EMAIL=group02@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000002
+ATTENDEE;CN=Group 03;CUTYPE=GROUP;EMAIL=group03@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000003
+ATTENDEE;CN=User 07;EMAIL=user07@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000007
+ATTENDEE;CN=User 08;EMAIL=user08@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000008
+ATTENDEE;CN=User 09;EMAIL=user09@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000009
+CREATED:20060101T150000Z
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:10000000-0000-0000-0000-000000000001
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        unpatchedRecordWithUID = DirectoryService.recordWithUID
+
+        @inlineCallbacks
+        def recordWithUID(self, uid):
+
+            if uid == &quot;20000000-0000-0000-0000-000000000002&quot;:
+                result = None
+            else:
+                result = yield unpatchedRecordWithUID(self, uid)
+            returnValue(result)
+
+        vcalendar1 = Component.fromString(data_put_1)
+        yield calendar.createCalendarObjectWithName(&quot;data1.ics&quot;, vcalendar1)
+        yield self.commit()
+
+        cobj1 = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000001&quot;)
+        vcalendar2 = yield cobj1.component()
+        self._assertICalStrEqual(vcalendar2, data_get_1)
+
+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000006&quot;, 1)
+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000007&quot;, 1)
+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000008&quot;, 1)
+        yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000009&quot;, 1)
+
+        # cache group
+        groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
+        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
+        yield self.commit()
+        yield wp.whenExecuted()
+
+        cobj1 = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000001&quot;)
+        vcalendar3 = yield cobj1.component()
+        self._assertICalStrEqual(vcalendar3, data_get_1)
+
+        # remove group  run cacher again
+        self.patch(DirectoryService, &quot;recordWithUID&quot;, recordWithUID)
+
+        groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
+        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
+        yield self.commit()
+        yield wp.whenExecuted()
+
+        cobj1 = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000001&quot;)
+        vcalendar4 = yield cobj1.component()
+        self._assertICalStrEqual(vcalendar4, data_get_2)
+
+        cal1 = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000006&quot;)
+        cobjs = yield cal1.objectResources()
+        #FIXME: Need schema change to handle case where group comes back
+        self.assertEqual(len(cobjs), 1)
+        comp1 = yield cobjs[0].componentForUser()
+        self.assertTrue(&quot;STATUS:CANCELLED&quot; in str(comp1))
+
+        # add group back, run cacher
+        self.patch(DirectoryService, &quot;recordWithUID&quot;, unpatchedRecordWithUID)
+
+        groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
+        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
+        self.assertNotEqual(wp, None)
+        yield self.commit()
+        yield wp.whenExecuted()
+
+        cobj1 = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000001&quot;)
+        vcalendar5 = yield cobj1.component()
+        self._assertICalStrEqual(vcalendar5, data_get_1)
</ins></span></pre>
</div>
</div>

</body>
</html>