<!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>[13363] 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/13363">13363</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2014-04-23 14:45:44 -0700 (Wed, 23 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>handle group attendees when group is missing from or reappears in the directory</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavicalpy">CalendarServer/trunk/twistedcaldav/ical.py</a></li>
<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>
<li><a href="#CalendarServertrunktxdavwhoutilpy">CalendarServer/trunk/txdav/who/util.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 (13362 => 13363)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/ical.py        2014-04-23 16:47:07 UTC (rev 13362)
+++ CalendarServer/trunk/twistedcaldav/ical.py        2014-04-23 21:45:44 UTC (rev 13363)
</span><span class="lines">@@ -3765,12 +3765,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def normalize_iCalStr(icalstr, sort=False):
</del><ins>+def normalize_iCalStr(icalstr):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Normalize a string representation of ical data for easy test comparison.
</span><del>-
-    @param sort: Whether to sort the output
-    @type sort: L{boolean}
</del><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     icalstr = str(icalstr).replace(&quot;\r\n &quot;, &quot;&quot;)
</span><span class="lines">@@ -3780,8 +3777,6 @@
</span><span class="cx">         pos = line.find(&quot;;X-CALENDARSERVER-DTSTAMP=&quot;)
</span><span class="cx">         if pos != -1:
</span><span class="cx">             lines[ctr] = line[:pos] + line[pos + len(&quot;;X-CALENDARSERVER-DTSTAMP=&quot;) + 16:]
</span><del>-    if sort:
-        lines.sort()
</del><span class="cx">     icalstr = &quot;\r\n&quot;.join(lines)
</span><span class="cx">     return icalstr + &quot;\r\n&quot;
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (13362 => 13363)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-04-23 16:47:07 UTC (rev 13362)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-04-23 21:45:44 UTC (rev 13363)
</span><span class="lines">@@ -1950,9 +1950,11 @@
</span><span class="cx">             groupRecord = yield self.directoryService().recordWithCalendarUserAddress(groupCUA)
</span><span class="cx">             if groupRecord:
</span><span class="cx">                 members = yield groupRecord.expandedMembers()
</span><del>-                groupCUAToAttendeeMemberPropMap[groupRecord.canonicalCalendarUserAddress()] = set(
</del><ins>+                groupCUAToAttendeeMemberPropMap[groupRecord.canonicalCalendarUserAddress()] = frozenset(
</ins><span class="cx">                     [member.attendeeProperty(params={&quot;MEMBER&quot;: groupCUA}) for member in members]
</span><span class="cx">                 )
</span><ins>+            else:
+                groupCUAToAttendeeMemberPropMap[groupCUA] = frozenset()
</ins><span class="cx"> 
</span><span class="cx">         # sync group attendee members if inserting or group changed
</span><span class="cx">         changed = False
</span><span class="lines">@@ -1984,52 +1986,51 @@
</span><span class="cx">             From=ga,
</span><span class="cx">             Where=ga.RESOURCE_ID == self._resourceID,
</span><span class="cx">         ).on(self._txn)
</span><del>-        oldGAs = dict(rows)
</del><ins>+        groupIDToMembershipHashMap = dict(rows)
</ins><span class="cx"> 
</span><del>-        for groupCUA, memberAttendeeProps in groupCUAToAttendeeMemberPropMap.iteritems():
</del><ins>+        for groupCUA in groupCUAToAttendeeMemberPropMap:
</ins><span class="cx">             groupRecord = yield self.directoryService().recordWithCalendarUserAddress(groupCUA)
</span><del>-            if groupRecord:
-                members = set([(
-                        yield self.directoryService().recordWithCalendarUserAddress(
-                            memberAttendeeProp.value()
-                        )
-                    ) for memberAttendeeProp in memberAttendeeProps
-                ])
</del><ins>+            if groupRecord is not None:
+                groupUID = groupRecord.uid
+            else:
+                #FIXME:  here to avoid circular import
+                from txdav.who.util import uidFromCalendarUserAddress
+                groupUID = uidFromCalendarUserAddress(groupCUA)
+            groupID, _ignore_name, membershipHash, _ignore_modDate = yield self._txn.groupByUID(groupUID)
</ins><span class="cx"> 
</span><del>-                membershipHashContent = hashlib.md5()
-                for memberUID in sorted([member.uid for member in members]):
-                    membershipHashContent.update(memberUID)
-                membershipHash = membershipHashContent.hexdigest()
-
-                groupID, _ignore_name, _ignoreMembershipHash, _ignore_modDate = yield self._txn.groupByUID(groupRecord.uid)
-
-                if groupID in oldGAs:
-                    if oldGAs[groupID] != membershipHash:
-                        yield Update({
-                                ga.MEMBERSHIP_HASH: membershipHash,
-                            },
-                            Where=(ga.RESOURCE_ID == self._resourceID).And(
-                                ga.GROUP_ID == groupID
-                            )
-                        ).on(self._txn)
-                        changed = True
-                    del oldGAs[groupID]
-                else:
-                    yield Insert({
-                            ga.RESOURCE_ID: self._resourceID,
-                            ga.GROUP_ID: groupID,
</del><ins>+            if groupID in groupIDToMembershipHashMap:
+                if groupIDToMembershipHashMap[groupID] != membershipHash:
+                    yield Update({
</ins><span class="cx">                             ga.MEMBERSHIP_HASH: membershipHash,
</span><del>-                        }
</del><ins>+                        },
+                        Where=(ga.RESOURCE_ID == self._resourceID).And(
+                            ga.GROUP_ID == groupID
+                        )
</ins><span class="cx">                     ).on(self._txn)
</span><span class="cx">                     changed = True
</span><ins>+                del groupIDToMembershipHashMap[groupID]
+            else:
+                yield Insert({
+                        ga.RESOURCE_ID: self._resourceID,
+                        ga.GROUP_ID: groupID,
+                        ga.MEMBERSHIP_HASH: membershipHash,
+                    }
+                ).on(self._txn)
+                changed = True
</ins><span class="cx"> 
</span><del>-        for groupID in oldGAs:
</del><ins>+        if groupIDToMembershipHashMap:
+            groupIDsToRemove = groupIDToMembershipHashMap.keys()
</ins><span class="cx">             yield Delete(
</span><span class="cx">                 From=ga,
</span><span class="cx">                 Where=(ga.RESOURCE_ID == self._resourceID).And(
</span><del>-                    ga.GROUP_ID == groupID
</del><ins>+                    ga.GROUP_ID.In(
+                        Parameter(
+                            &quot;groupIDsToRemove&quot;,
+                            len(groupIDsToRemove)
+                        )
+                    )
</ins><span class="cx">                 )
</span><del>-            ).on(self._txn)
</del><ins>+            ).on(self._txn, groupIDsToRemove=groupIDsToRemove)
</ins><span class="cx">             changed = True
</span><span class="cx"> 
</span><span class="cx">         returnValue(changed)
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhogroupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/groups.py (13362 => 13363)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/groups.py        2014-04-23 16:47:07 UTC (rev 13362)
+++ CalendarServer/trunk/txdav/who/groups.py        2014-04-23 21:45:44 UTC (rev 13363)
</span><span class="lines">@@ -308,57 +308,56 @@
</span><span class="cx">         self.log.debug(&quot;Faulting in group: {g}&quot;, g=groupUID)
</span><span class="cx">         record = (yield self.directory.recordWithUID(groupUID))
</span><span class="cx">         if record is None:
</span><del>-            # the group has disappeared from the directory - OK
-            # FIXME: If group reappears, it will not be used in existing events
-            self.log.info(&quot;Group has disappeared: {g}&quot;, g=groupUID)
</del><ins>+            # the group has disappeared from the directory
+            self.log.info(&quot;Group is missing: {g}&quot;, g=groupUID)
</ins><span class="cx">         else:
</span><span class="cx">             self.log.debug(&quot;Got group record: {u}&quot;, u=record.uid)
</span><span class="cx"> 
</span><del>-        groupID, _ignore_cachedName, cachedMembershipHash, _ignore_modified = (
</del><ins>+        groupID, cachedName, cachedMembershipHash, _ignore_modified = (
</ins><span class="cx">             yield txn.groupByUID(
</span><span class="cx">                 groupUID,
</span><span class="cx">                 create=(record is not None)
</span><span class="cx">             )
</span><span class="cx">         )
</span><del>-        wp = None
</del><ins>+        wps = tuple()
</ins><span class="cx">         if groupID:
</span><span class="cx">             if record is not None:
</span><del>-                membershipHashContent = hashlib.md5()
</del><span class="cx">                 members = yield record.expandedMembers()
</span><del>-                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()
</del><ins>+                name = record.fullNames[0]
+            else:
+                members = frozenset()
+                name = cachedName
</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>+            membershipHashContent = hashlib.md5()
+            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>-                yield txn.updateGroup(groupUID, record.fullNames[0], membershipHash)
-
-                if membershipChanged:
-                    newMemberUIDs = set()
-                    for member in members:
-                        newMemberUIDs.add(member.uid)
-                    yield self.synchronizeMembers(txn, groupID, newMemberUIDs)
-
-            else:
-                # FIXME: Use schema's delete cascade
-                yield self.synchronizeMembers(txn, groupID, set())
-                yield txn.deleteGroup(groupID)
</del><ins>+            if cachedMembershipHash != membershipHash:
</ins><span class="cx">                 membershipChanged = True
</span><ins>+                self.log.debug(
+                    &quot;Group '{group}' changed&quot;, group=name
+                )
+            else:
+                membershipChanged = False
</ins><span class="cx"> 
</span><ins>+            if membershipChanged or record is not None:
+                # also updates group mod date
+                yield txn.updateGroup(groupUID, name, membershipHash)
+
</ins><span class="cx">             if membershipChanged:
</span><del>-                wp = yield self.scheduleEventReconciliations(txn, groupID)
</del><ins>+                newMemberUIDs = set()
+                for member in members:
+                    newMemberUIDs.add(member.uid)
+                yield self.synchronizeMembers(txn, groupID, newMemberUIDs)
</ins><span class="cx"> 
</span><del>-        returnValue(wp)
</del><ins>+                wps = yield self.scheduleEventReconciliations(txn, groupID)
</ins><span class="cx"> 
</span><ins>+        returnValue(wps)
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def synchronizeMembers(self, txn, groupID, newMemberUIDs):
</span><span class="cx">         numRemoved = numAdded = 0
</span><span class="lines">@@ -412,9 +411,8 @@
</span><span class="cx">             Where=ga.GROUP_ID == groupID,
</span><span class="cx">         ).on(txn)
</span><span class="cx"> 
</span><del>-        wp = None
-        if rows:
-            eventID = rows[0][0]
</del><ins>+        wps = []
+        for [eventID] in rows:
</ins><span class="cx"> 
</span><span class="cx">             notBefore = (
</span><span class="cx">                 datetime.datetime.utcnow() +
</span><span class="lines">@@ -434,8 +432,9 @@
</span><span class="cx">                 groupID=groupID,
</span><span class="cx">                 notBefore=notBefore
</span><span class="cx">             )
</span><ins>+            wps.append(wp)
</ins><span class="cx"> 
</span><del>-        returnValue(wp)
</del><ins>+        returnValue(tuple(wps))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhotesttest_group_attendeespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/test/test_group_attendees.py (13362 => 13363)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-04-23 16:47:07 UTC (rev 13362)
+++ CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-04-23 21:45:44 UTC (rev 13363)
</span><span class="lines">@@ -23,7 +23,7 @@
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> from twisted.trial import unittest
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from twistedcaldav.ical import Component, normalize_iCalStr
</del><ins>+from twistedcaldav.ical import Component, normalize_iCalStr, ignoredComponents
</ins><span class="cx"> from txdav.caldav.datastore.test.util import buildCalendarStore, populateCalendarsFrom, CommonCommonTests
</span><span class="cx"> from txdav.who.directory import CalendarDirectoryRecordMixin
</span><span class="cx"> from txdav.who.groups import GroupCacher
</span><span class="lines">@@ -93,13 +93,41 @@
</span><span class="cx">         self.assertEqual(count, expected_count)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    # better error output
</del><span class="cx">     def _assertICalStrEqual(self, iCalStr1, iCalStr2):
</span><del>-        if normalize_iCalStr(iCalStr1, sort=True) != normalize_iCalStr(iCalStr2, sort=True):
-            self.assertEqual(normalize_iCalStr(iCalStr1), normalize_iCalStr(iCalStr2))
-            self.assertTrue(False)
</del><span class="cx"> 
</span><ins>+        def orderMemberValues(event):
</ins><span class="cx"> 
</span><ins>+            for component in event.subcomponents():
+                if component.name() in ignoredComponents:
+                    continue
+
+                # remove all values and add them again
+                # this is sort of a hack, better pycalendar has ordering
+                for attendeeProp in tuple(component.properties(&quot;ATTENDEE&quot;)):
+                    if attendeeProp.hasParameter(&quot;MEMBER&quot;):
+                        parameterValues = tuple(attendeeProp.parameterValues(&quot;MEMBER&quot;))
+                        for paramterValue in parameterValues:
+                            attendeeProp.removeParameterValue(&quot;MEMBER&quot;, paramterValue)
+                        attendeeProp.setParameter(&quot;MEMBER&quot;, sorted(parameterValues))
+
+        self.assertEqual(
+            orderMemberValues(
+                Component.fromString(
+                    normalize_iCalStr(
+                        iCalStr1
+                    )
+                )
+            ),
+            orderMemberValues(
+                Component.fromString(
+                    normalize_iCalStr(
+                        iCalStr2
+                    )
+                )
+            )
+        )
+
+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_simplePUT(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -394,7 +422,6 @@
</span><span class="cx">         yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000009&quot;, 1)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    #TODO:  Change to multigroup case
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_groupChange(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -480,8 +507,8 @@
</span><span class="cx">         self.patch(CalendarDirectoryRecordMixin, &quot;expandedMembers&quot;, expandedMembers)
</span><span class="cx"> 
</span><span class="cx">         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
</span><del>-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
-        self.assertEqual(wp, None)
</del><ins>+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
+        self.assertEqual(len(wps), 0)
</ins><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="cx">         vcalendar1 = Component.fromString(data_put_1)
</span><span class="lines">@@ -498,9 +525,10 @@
</span><span class="cx">         self.patch(CalendarDirectoryRecordMixin, &quot;expandedMembers&quot;, unpatchedExpandedMembers)
</span><span class="cx"> 
</span><span class="cx">         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
</span><del>-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</del><ins>+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</ins><span class="cx">         yield self.commit()
</span><del>-        yield wp.whenExecuted()
</del><ins>+        self.assertEqual(len(wps), 1)
+        yield wps[0].whenExecuted()
</ins><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-000000000002&quot;)
</span><span class="cx">         vcalendar3 = yield cobj1.component()
</span><span class="lines">@@ -511,9 +539,10 @@
</span><span class="cx"> 
</span><span class="cx">         self.patch(CalendarDirectoryRecordMixin, &quot;expandedMembers&quot;, expandedMembers)
</span><span class="cx">         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
</span><del>-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</del><ins>+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</ins><span class="cx">         yield self.commit()
</span><del>-        yield wp.whenExecuted()
</del><ins>+        self.assertEqual(len(wps), 1)
+        yield wps[0].whenExecuted()
</ins><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-000000000002&quot;)
</span><span class="cx">         vcalendar3 = yield cobj1.component()
</span><span class="lines">@@ -527,6 +556,15 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><ins>+    def test_multieventGroupChange(self):
+        &quot;&quot;&quot;
+        Test that every event associated with a group chagnes when the group changes
+        &quot;&quot;&quot;
+
+        self.fail(&quot;FIXME: implement this test&quot;)
+
+
+    @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 class="lines">@@ -619,8 +657,8 @@
</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><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><del>-ATTENDEE;CN=User 07;EMAIL=user07@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;,&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
-ATTENDEE;CN=User 08;EMAIL=user08@example.com;MEMBER=&quot;urn:x-uid:20000000-0000-0000-0000-000000000003&quot;,&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
</del><ins>+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><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="lines">@@ -655,9 +693,10 @@
</span><span class="cx"> 
</span><span class="cx">         # cache group
</span><span class="cx">         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
</span><del>-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
</del><ins>+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
</ins><span class="cx">         yield self.commit()
</span><del>-        yield wp.whenExecuted()
</del><ins>+        self.assertEqual(len(wps), 1)
+        yield wps[0].whenExecuted()
</ins><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">         vcalendar3 = yield cobj1.component()
</span><span class="lines">@@ -667,9 +706,10 @@
</span><span class="cx">         self.patch(DirectoryService, &quot;recordWithUID&quot;, recordWithUID)
</span><span class="cx"> 
</span><span class="cx">         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
</span><del>-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
</del><ins>+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
</ins><span class="cx">         yield self.commit()
</span><del>-        yield wp.whenExecuted()
</del><ins>+        self.assertEqual(len(wps), 1)
+        yield wps[0].whenExecuted()
</ins><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">         vcalendar4 = yield cobj1.component()
</span><span class="lines">@@ -686,10 +726,10 @@
</span><span class="cx">         self.patch(DirectoryService, &quot;recordWithUID&quot;, unpatchedRecordWithUID)
</span><span class="cx"> 
</span><span class="cx">         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
</span><del>-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
-        self.assertNotEqual(wp, None)
</del><ins>+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
+        self.assertEqual(len(wps), 1)
</ins><span class="cx">         yield self.commit()
</span><del>-        yield wp.whenExecuted()
</del><ins>+        yield wps[0].whenExecuted()
</ins><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">         vcalendar5 = yield cobj1.component()
</span><span class="lines">@@ -811,12 +851,14 @@
</span><span class="cx"> 
</span><span class="cx">         # cache groups
</span><span class="cx">         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
</span><del>-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
</del><ins>+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
</ins><span class="cx">         yield self.commit()
</span><del>-        yield wp.whenExecuted()
-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000003&quot;)
</del><ins>+        self.assertEqual(len(wps), 1)
+        yield wps[0].whenExecuted()
+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000003&quot;)
</ins><span class="cx">         yield self.commit()
</span><del>-        yield wp.whenExecuted()
</del><ins>+        self.assertEqual(len(wps), 1)
+        yield wps[0].whenExecuted()
</ins><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">         vcalendar3 = yield cobj1.component()
</span><span class="lines">@@ -836,10 +878,10 @@
</span><span class="cx">         yield self._verifyObjectResourceCount(&quot;10000000-0000-0000-0000-000000000009&quot;, 1)
</span><span class="cx"> 
</span><span class="cx">         # groups did not change so no work proposals
</span><del>-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
-        self.assertEqual(wp, None)
-        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000003&quot;)
-        self.assertEqual(wp, None)
</del><ins>+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000002&quot;)
+        self.assertEqual(len(wps), 0)
+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000003&quot;)
+        self.assertEqual(len(wps), 0)
</ins><span class="cx"> 
</span><span class="cx">         cal1 = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=&quot;10000000-0000-0000-0000-000000000009&quot;)
</span><span class="cx">         cobjs = yield cal1.objectResources()
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhoutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/util.py (13362 => 13363)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/util.py        2014-04-23 16:47:07 UTC (rev 13362)
+++ CalendarServer/trunk/txdav/who/util.py        2014-04-23 21:45:44 UTC (rev 13363)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> from twisted.python.filepath import FilePath
</span><span class="cx"> from twisted.python.reflect import namedClass
</span><span class="cx"> from twistedcaldav.config import fullServerPath
</span><ins>+from txdav.caldav.datastore.scheduling.cuaddress import normalizeCUAddr
</ins><span class="cx"> from txdav.who.augment import AugmentedDirectoryService
</span><span class="cx"> from txdav.who.delegates import DirectoryService as DelegateDirectoryService
</span><span class="cx"> from txdav.who.idirectory import (
</span><span class="lines">@@ -42,6 +43,7 @@
</span><span class="cx"> )
</span><span class="cx"> from txdav.who.wiki import DirectoryService as WikiDirectoryService
</span><span class="cx"> from txdav.who.xml import DirectoryService as XMLDirectoryService
</span><ins>+from uuid import UUID
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="lines">@@ -240,3 +242,34 @@
</span><span class="cx">         raise
</span><span class="cx"> 
</span><span class="cx">     return augmented
</span><ins>+
+
+
+def uidFromCalendarUserAddress(address):
+    &quot;&quot;&quot;
+        Get a uid from a calendar user address
+        May return None
+    &quot;&quot;&quot;
+
+    address = normalizeCUAddr(address)
+
+    if address.startswith(&quot;urn:x-uid:&quot;):
+        return address[10:]
+
+    elif address.startswith(&quot;urn:uuid:&quot;):
+        try:
+            UUID(address[9:])
+        except ValueError:
+            log.info(&quot;Invalid GUID: {guid}&quot;, guid=address[9:])
+        else:
+            return address[9:]
+
+    elif address.startswith(&quot;mailto:&quot;):
+        return address[7:]
+
+    elif address.startswith(&quot;/principals/&quot;):
+        parts = address.split(&quot;/&quot;)
+        if len(parts) == 4:
+            return parts[3]
+
+    return None
</ins></span></pre>
</div>
</div>

</body>
</html>