<!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>[12045] CalendarServer/branches/users/sagen/groupcacher</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/12045">12045</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2013-12-09 15:19:58 -0800 (Mon, 09 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>first working twext.who.test.test_groups.GroupAttendeeReconciliation.test_groupAttendeeReconciliation</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagengroupcachertwextwhogroupspy">CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py</a></li>
<li><a href="#CalendarServerbranchesuserssagengroupcachertwextwhotestaccountsaccountsxml">CalendarServer/branches/users/sagen/groupcacher/twext/who/test/accounts/accounts.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagengroupcachertwextwhotesttest_groupspy">CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py</a></li>
<li><a href="#CalendarServerbranchesuserssagengroupcachertwistedcaldavicalpy">CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py</a></li>
<li><a href="#CalendarServerbranchesuserssagengroupcachertxdavcaldavdatastoresqlpy">CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagengroupcachertwextwhogroupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py (12044 => 12045)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py        2013-12-09 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py        2013-12-09 23:19:58 UTC (rev 12045)
</span><span class="lines">@@ -25,7 +25,6 @@
</span><span class="cx"> from twext.who.delegates import allGroupDelegates
</span><span class="cx"> from twext.who.idirectory import RecordType
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><del>-from txdav.caldav.datastore.util import normalizationLookup
</del><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">@@ -160,7 +159,7 @@
</span><span class="cx">         individualGUIDs = [row[0] for row in rows]
</span><span class="cx"> 
</span><span class="cx">         component = yield calendarObject.component()
</span><del>-        changed = component.expandGroupAttendee(self.groupGUID, individualGUIDs, normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
</del><ins>+        changed = component.expandGroupAttendee(self.groupGUID, individualGUIDs, self.directoryService().recordWithCalendarUserAddress)
</ins><span class="cx"> 
</span><span class="cx">         if changed:
</span><span class="cx">             yield calendarObject.setComponent(component)
</span><span class="lines">@@ -168,7 +167,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> @inlineCallbacks
</span><del>-def _expandedMembers(record, members=None, records=None):
</del><ins>+def expandedMembers(record, members=None, records=None):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Return the expanded set of member records.  Intermediate groups are not returned
</span><span class="cx">     in the results, but their members are.
</span><span class="lines">@@ -184,7 +183,7 @@
</span><span class="cx">             if member not in records:
</span><span class="cx">                 if member.recordType != RecordType.group:
</span><span class="cx">                     members.add(member)
</span><del>-                yield _expandedMembers(member, members, records)
</del><ins>+                yield expandedMembers(member, members, records)
</ins><span class="cx"> 
</span><span class="cx">     returnValue(members)
</span><span class="cx"> 
</span><span class="lines">@@ -227,7 +226,7 @@
</span><span class="cx">         # and updates the GROUP_MEMBERSHIP table
</span><span class="cx">         record = (yield self.directory.recordWithGUID(groupGUID))
</span><span class="cx">         membershipHashContent = hashlib.md5()
</span><del>-        members = (yield _expandedMembers(record))
</del><ins>+        members = (yield expandedMembers(record))
</ins><span class="cx">         members = list(members)
</span><span class="cx">         members.sort(cmp=lambda x, y: cmp(x.guid, y.guid))
</span><span class="cx">         for member in members:
</span><span class="lines">@@ -282,7 +281,7 @@
</span><span class="cx">         returnValue(members)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    # @inlineCallbacks
</del><ins>+    @inlineCallbacks
</ins><span class="cx">     def scheduleEventReconciliations(self, txn, groupID, groupGUID):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Find all events who have this groupID as an attendee and create
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagengroupcachertwextwhotestaccountsaccountsxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/test/accounts/accounts.xml (12044 => 12045)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/twext/who/test/accounts/accounts.xml        2013-12-09 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/test/accounts/accounts.xml        2013-12-09 23:19:58 UTC (rev 12045)
</span><span class="lines">@@ -122,6 +122,7 @@
</span><span class="cx">     &lt;guid&gt;group02&lt;/guid&gt;
</span><span class="cx">     &lt;password&gt;group02&lt;/password&gt;
</span><span class="cx">     &lt;name&gt;Group 02&lt;/name&gt;
</span><ins>+    &lt;email-address&gt;group02@example.com&lt;/email-address&gt;
</ins><span class="cx">     &lt;members&gt;
</span><span class="cx">       &lt;member type=&quot;users&quot;&gt;user06&lt;/member&gt;
</span><span class="cx">       &lt;member type=&quot;users&quot;&gt;user07&lt;/member&gt;
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagengroupcachertwextwhotesttest_groupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py (12044 => 12045)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py        2013-12-09 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py        2013-12-09 23:19:58 UTC (rev 12045)
</span><span class="lines">@@ -18,7 +18,7 @@
</span><span class="cx"> Group membership caching implementation tests
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-from twext.who.groups import GroupCacher, _expandedMembers
</del><ins>+from twext.who.groups import GroupCacher, expandedMembers
</ins><span class="cx"> from twext.who.idirectory import RecordType
</span><span class="cx"> from twext.who.test.test_xml import xmlService
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="lines">@@ -43,20 +43,20 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_expandedMembers(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Verify _expandedMembers() returns a &quot;flattened&quot; set of records
</del><ins>+        Verify expandedMembers() returns a &quot;flattened&quot; set of records
</ins><span class="cx">         belonging to a group (and does not return sub-groups themselves,
</span><span class="cx">         only their members)
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         record = yield self.xmlService.recordWithUID(&quot;__top_group_1__&quot;)
</span><span class="cx">         memberUIDs = set()
</span><del>-        for member in (yield _expandedMembers(record)):
</del><ins>+        for member in (yield expandedMembers(record)):
</ins><span class="cx">             memberUIDs.add(member.uid)
</span><span class="cx">         self.assertEquals(memberUIDs, set([&quot;__cdaboo__&quot;,
</span><span class="cx">             &quot;__glyph__&quot;, &quot;__sagen__&quot;, &quot;__wsanchez__&quot;]))
</span><span class="cx"> 
</span><span class="cx">         # Non group records return an empty set() of members
</span><span class="cx">         record = yield self.xmlService.recordWithUID(&quot;__sagen__&quot;)
</span><del>-        members = yield _expandedMembers(record)
</del><ins>+        members = yield expandedMembers(record)
</ins><span class="cx">         self.assertEquals(0, len(list(members)))
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -301,24 +301,6 @@
</span><span class="cx"> CALSCALE:GREGORIAN
</span><span class="cx"> PRODID:-//Example Inc.//Example Calendar//EN
</span><span class="cx"> VERSION:2.0
</span><del>-BEGIN:VTIMEZONE
-LAST-MODIFIED:20040110T032845Z
-TZID:US/Eastern
-BEGIN:DAYLIGHT
-DTSTART:20000404T020000
-RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
-TZNAME:EDT
-TZOFFSETFROM:-0500
-TZOFFSETTO:-0400
-END:DAYLIGHT
-BEGIN:STANDARD
-DTSTART:20001026T020000
-RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
-TZNAME:EST
-TZOFFSETFROM:-0400
-TZOFFSETTO:-0500
-END:STANDARD
-END:VTIMEZONE
</del><span class="cx"> BEGIN:VEVENT
</span><span class="cx"> DTSTAMP:20051222T205953Z
</span><span class="cx"> CREATED:20060101T150000Z
</span><span class="lines">@@ -329,7 +311,7 @@
</span><span class="cx"> ORGANIZER:MAILTO:user01@example.com
</span><span class="cx"> ATTENDEE:mailto:user01@example.com
</span><span class="cx"> ATTENDEE:mailto:user02@example.com
</span><del>-ATTENDEE:MAILTO:group01@example.com
</del><ins>+ATTENDEE:MAILTO:group02@example.com
</ins><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR&quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -343,7 +325,9 @@
</span><span class="cx"> DURATION:PT1H
</span><span class="cx"> ATTENDEE;CN=User 01;EMAIL=user01@example.com;RSVP=TRUE:urn:uuid:user01
</span><span class="cx"> ATTENDEE;CN=User 02;EMAIL=user02@example.com;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user02
</span><del>-ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:group01
</del><ins>+ATTENDEE;CN=Group 02;CUTYPE=GROUP;EMAIL=group02@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:group02
+ATTENDEE;CN=User 06;EMAIL=user06@example.com;MEMBER=&quot;urn:uuid:group02&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user06
+ATTENDEE;CN=User 07;EMAIL=user07@example.com;MEMBER=&quot;urn:uuid:group02&quot;;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user07
</ins><span class="cx"> CREATED:20060101T150000Z
</span><span class="cx"> ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:uuid:user01
</span><span class="cx"> SUMMARY:event 1
</span><span class="lines">@@ -358,6 +342,4 @@
</span><span class="cx"> 
</span><span class="cx">         cobj = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;user01&quot;)
</span><span class="cx">         vcalendar = yield cobj.component()
</span><del>-        print(&quot;normalize_iCalStr(vcalendar)=%s&quot; % (normalize_iCalStr(vcalendar),))
-        print(&quot;normalize_iCalStr(data_get)=%s&quot; % (normalize_iCalStr(data_get),))
</del><span class="cx">         self.assertEqual(normalize_iCalStr(vcalendar), normalize_iCalStr(data_get))
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagengroupcachertwistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py (12044 => 12045)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py        2013-12-09 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py        2013-12-09 23:19:58 UTC (rev 12045)
</span><span class="lines">@@ -3355,7 +3355,7 @@
</span><span class="cx">                 component.normalizeCalendarUserAddresses(lookupFunction, principalFunction, toUUID)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def expandGroupAttendee(self, groupGUID, individualGUIDs, lookupFunction, principalFunction):
</del><ins>+    def expandGroupAttendee(self, groupGUID, individualGUIDs, principalFunction):
</ins><span class="cx"> 
</span><span class="cx">         individualUUIDs = set([&quot;urn:uuid:&quot; + individualGUID for individualGUID in individualGUIDs])
</span><span class="cx">         groupUUID = &quot;urn:uuid:&quot; + groupGUID
</span><span class="lines">@@ -3369,7 +3369,7 @@
</span><span class="cx"> 
</span><span class="cx">             # add new member attendees
</span><span class="cx">             for individualUUID in individualUUIDs - oldAttendeeUUIDs:
</span><del>-                directoryRecord = lookupFunction(individualUUID, principalFunction, config)
</del><ins>+                directoryRecord = principalFunction(individualUUID)
</ins><span class="cx">                 newAttendeeProp = directoryRecord.attendee(params={&quot;MEMBER&quot;: groupUUID})
</span><span class="cx">                 component.addProperty(newAttendeeProp)
</span><span class="cx">                 changed = True
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagengroupcachertxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py (12044 => 12045)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py        2013-12-09 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py        2013-12-09 23:19:58 UTC (rev 12045)
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx"> from twext.python.vcomponent import VComponent
</span><span class="cx"> from twext.web2.http_headers import MimeType, generateContentType
</span><span class="cx"> from twext.web2.stream import readStream
</span><ins>+from twext.who.groups import expandedMembers
</ins><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</span><span class="cx"> from twisted.python import hashlib
</span><span class="lines">@@ -87,7 +88,7 @@
</span><span class="cx">     InvalidObjectResourceError, ObjectResourceNameAlreadyExistsError, \
</span><span class="cx">     ObjectResourceNameNotAllowedError, TooManyObjectResourcesError, \
</span><span class="cx">     InvalidUIDError, UIDExistsError, UIDExistsElsewhereError, \
</span><del>-    InvalidResourceMove, InvalidComponentForStoreError
</del><ins>+    InvalidResourceMove, InvalidComponentForStoreError, AllRetriesFailed
</ins><span class="cx"> 
</span><span class="cx"> from txdav.idav import ChangeCategory
</span><span class="cx"> 
</span><span class="lines">@@ -1614,28 +1615,38 @@
</span><span class="cx">             return
</span><span class="cx"> 
</span><span class="cx">         attendeeProps = component.getAllAttendeeProperties()
</span><del>-        groupGUIDs = [
</del><ins>+        groupGUIDs = set([
</ins><span class="cx">             attendeeProp.value()[len(&quot;urn:uuid:&quot;):] for attendeeProp in attendeeProps
</span><span class="cx">             if attendeeProp.parameterValue(&quot;CUTYPE&quot;) == &quot;GROUP&quot;
</span><del>-        ]
</del><ins>+        ])
</ins><span class="cx"> 
</span><del>-        # FIXME: need to add event to Group resource ID here
-        #        need get get members here because they may not be cached yet
</del><ins>+        for groupGUID in groupGUIDs:
</ins><span class="cx"> 
</span><del>-        for groupGUID in groupGUIDs:
</del><ins>+            groupRecord = yield self.directoryService().recordWithGUID(groupGUID)
+            members = yield expandedMembers(groupRecord)
+            membershipHashContent = hashlib.md5()
+            members = yield expandedMembers(groupRecord)
+            individualGUIDs = sorted([member.guid for member in members])
+            for individualGUID in individualGUIDs:
+                membershipHashContent.update(str(individualGUID))
+            membershipHash = membershipHashContent.hexdigest()
+
+            # associate group ID with self
</ins><span class="cx">             groupID, name, membershipHash = yield self._txn.groupByGUID(groupGUID)
</span><ins>+            try:
+                groupAttendee = schema.GROUP_ATTENDEE
+                yield Insert({
+                    groupAttendee.RESOURCE_ID: self._resourceID,
+                    groupAttendee.GROUP_ID: groupID,
+                    groupAttendee.MEMBERSHIP_HASH: membershipHash,
+                })
+            except AllRetriesFailed:
+                pass
</ins><span class="cx"> 
</span><del>-            groupMemember = schema.GROUP_MEMBERSHIP
-            rows = yield Select(
-                    [groupMemember.MEMBER_GUID, ],
-                    From=groupMemember,
-                    Where=groupMemember.GROUP_ID == groupID,
-            ).on(self._txn)
-            individualGUIDs = [row[0] for row in rows]
</del><ins>+            # get members
+            component.expandGroupAttendee(groupGUID, individualGUIDs, self.directoryService().recordWithCalendarUserAddress)
</ins><span class="cx"> 
</span><del>-            component.expandGroupAttendee(groupGUID, individualGUIDs, normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     def validCalendarDataCheck(self, component, inserting): #@UnusedVariable
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Check that the calendar data is valid iCalendar.
</span></span></pre>
</div>
</div>

</body>
</html>