<!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>[13323] 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/13323">13323</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2014-04-18 11:05:54 -0700 (Fri, 18 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>fix group attendees</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="#CalendarServertrunktxdavwhodirectorypy">CalendarServer/trunk/txdav/who/directory.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="CalendarServertrunktwistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/ical.py (13322 => 13323)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/ical.py        2014-04-18 16:32:45 UTC (rev 13322)
+++ CalendarServer/trunk/twistedcaldav/ical.py        2014-04-18 18:05:54 UTC (rev 13323)
</span><span class="lines">@@ -3391,10 +3391,8 @@
</span><span class="cx">                 yield component.normalizeCalendarUserAddresses(lookupFunction, recordFunction, toUUID)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @inlineCallbacks
-    def expandGroupAttendee(self, groupCUA, memberCUAs, recordFunction):
</del><ins>+    def _reconcileGroupAttendee(self, groupCUA, memberAtttendeeProps):
</ins><span class="cx"> 
</span><del>-        changed = False
</del><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="lines">@@ -3403,11 +3401,12 @@
</span><span class="cx">             oldAttendeeCUAs = set([attendeeProp.value() for attendeeProp in oldAttendeeProps])
</span><span class="cx"> 
</span><span class="cx">             # add new member attendees
</span><del>-            for memberCUA in sorted(set(memberCUAs) - oldAttendeeCUAs):
-                directoryRecord = yield recordFunction(memberCUA)
-                newAttendeeProp = directoryRecord.attendee(params={&quot;MEMBER&quot;: groupCUA})
-                component.addProperty(newAttendeeProp)
-                changed = True
</del><ins>+            memberCUAs = set()
+            for newAttendeeProp in memberAtttendeeProps:
+                memberCUA = newAttendeeProp.value()
+                if newAttendeeProp.value() not in oldAttendeeCUAs:
+                    component.addProperty(newAttendeeProp)
+                memberCUAs.add(memberCUA)
</ins><span class="cx"> 
</span><span class="cx">             # remove attendee or update MEMBER attribute for non-primary attendees in this group,
</span><span class="cx">             for attendeeProp in oldAttendeeProps:
</span><span class="lines">@@ -3418,15 +3417,30 @@
</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><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><del>-                            changed = True
</del><span class="cx"> 
</span><del>-        returnValue(changed)
</del><span class="cx"> 
</span><ins>+    def reconcileGroupAttendees(self, groupCUAToAttendeeMemberPropMap):
</ins><span class="cx"> 
</span><ins>+        allMemberCUAs = set()
+        for groupCUA, memberAttendeeProps in groupCUAToAttendeeMemberPropMap.iteritems():
+            self._reconcileGroupAttendee(groupCUA, memberAttendeeProps)
+            allMemberCUAs |= set([memberAttendeeProp.value() for memberAttendeeProp in memberAttendeeProps])
+
+        # remove orphans
+        for component in self.subcomponents():
+            if component.name() in ignoredComponents:
+                continue
+
+            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)
+
+
</ins><span class="cx">     def allPerUserUIDs(self):
</span><span class="cx"> 
</span><span class="cx">         results = set()
</span><span class="lines">@@ -3723,7 +3737,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def normalize_iCalStr(icalstr):
</del><ins>+def normalize_iCalStr(icalstr, sort=False):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Normalize a string representation of ical data for easy test comparison.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -3735,6 +3749,8 @@
</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><ins>+    if sort:
+        lines.sort()
</ins><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 (13322 => 13323)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-04-18 16:32:45 UTC (rev 13322)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-04-18 18:05:54 UTC (rev 13323)
</span><span class="lines">@@ -92,7 +92,7 @@
</span><span class="cx">     ObjectResourceNameNotAllowedError, TooManyObjectResourcesError, \
</span><span class="cx">     InvalidUIDError, UIDExistsError, UIDExistsElsewhereError, \
</span><span class="cx">     InvalidResourceMove, InvalidComponentForStoreError, \
</span><del>-    NoSuchObjectResourceError, AllRetriesFailed
</del><ins>+    NoSuchObjectResourceError
</ins><span class="cx"> from txdav.xml import element
</span><span class="cx"> 
</span><span class="cx"> from txdav.idav import ChangeCategory
</span><span class="lines">@@ -1915,9 +1915,6 @@
</span><span class="cx">             # calendar data
</span><span class="cx">             yield component.normalizeCalendarUserAddresses(normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
</span><span class="cx"> 
</span><del>-            # Expand groups
-            yield self.expandGroupAttendees(component, inserting)
-
</del><span class="cx">             # Valid attendee list size check
</span><span class="cx">             yield self.validAttendeeListSizeCheck(component, inserting)
</span><span class="cx"> 
</span><span class="lines">@@ -1934,9 +1931,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def expandGroupAttendees(self, component, inserting):
</del><ins>+    def reconcileGroupAttendees(self, component):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        Expand group attendees
</del><ins>+        reconcile group attendees
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if not config.Scheduling.Options.AllowGroupAsAttendee:
</span><span class="cx">             returnValue(None)
</span><span class="lines">@@ -1946,41 +1943,84 @@
</span><span class="cx">             attendeeProp.value() for attendeeProp in attendeeProps
</span><span class="cx">             if attendeeProp.parameterValue(&quot;CUTYPE&quot;) == &quot;GROUP&quot;
</span><span class="cx">         ])
</span><ins>+
+        groupCUAToAttendeeMemberPropMap = {}
</ins><span class="cx">         for groupCUA in groupCUAs:
</span><span class="cx"> 
</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>-
-                # add group attendees
-                yield component.expandGroupAttendee(
-                    groupRecord.canonicalCalendarUserAddress(),
-                    set([member.canonicalCalendarUserAddress() for member in members]),
-                    self.directoryService().recordWithCalendarUserAddress
</del><ins>+                groupCUAToAttendeeMemberPropMap[groupRecord.canonicalCalendarUserAddress()] = set(
+                    [member.attendeeProperty(params={&quot;MEMBER&quot;: groupCUA}) for member in members]
</ins><span class="cx">                 )
</span><span class="cx"> 
</span><del>-                # tie event to group cacher
-                if not inserting:
-                    # calculate hash
-                    memberUIDs = sorted([member.uid for member in members])
-                    membershipHashContent = hashlib.md5()
-                    for memberUID in memberUIDs:
-                        membershipHashContent.update(memberUID)
-                    membershipHash = membershipHashContent.hexdigest()
</del><ins>+        # sync group attendees
+        component.reconcileGroupAttendees(groupCUAToAttendeeMemberPropMap)
</ins><span class="cx"> 
</span><del>-                    # associate group ID with self
-                    groupID, _ignore_name, membershipHash, _ignore_modDate = yield self._txn.groupByUID(groupRecord.uid)
-                    try:
-                        groupAttendee = schema.GROUP_ATTENDEE
-                        yield Insert({
-                            groupAttendee.RESOURCE_ID: self._resourceID,
-                            groupAttendee.GROUP_ID: groupID,
-                            groupAttendee.MEMBERSHIP_HASH: membershipHash,
-                            }).on(self._txn)
-                    except AllRetriesFailed:
-                        pass
</del><ins>+        # save for post processing
+        self._groupCUAToAttendeeMemberPropMap = groupCUAToAttendeeMemberPropMap
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def updateGROUP_ATTENDEE(self):
+        &quot;&quot;&quot;
+        update schema.GROUP_ATTENDEE
+        &quot;&quot;&quot;
+        if not hasattr(self, &quot;_groupCUAToAttendeeMemberPropMap&quot;):
+            returnValue(None)
+
+        ga = schema.GROUP_ATTENDEE
+        rows = yield Select(
+            [ga.GROUP_ID, ga.MEMBERSHIP_HASH],
+            From=ga,
+            Where=ga.RESOURCE_ID == self._resourceID,
+        ).on(self._txn)
+        oldGAs = dict(rows)
+
+        for groupCUA, memberAttendeeProps in self._groupCUAToAttendeeMemberPropMap.iteritems():
+            groupRecord = yield self.directoryService().recordWithCalendarUserAddress(groupCUA)
+            if groupRecord:
+                members = set([(
+                        yield self.directoryService().recordWithCalendarUserAddress(
+                            memberAttendeeProp.value()
+                        )
+                    ) for memberAttendeeProp in memberAttendeeProps
+                ])
+
+                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)
+                    del oldGAs[groupID]
+                else:
+                    yield Insert({
+                            ga.RESOURCE_ID: self._resourceID,
+                            ga.GROUP_ID: groupID,
+                            ga.MEMBERSHIP_HASH: membershipHash,
+                        }
+                    ).on(self._txn)
+
+        for groupID in oldGAs:
+            yield Delete(
+                From=ga,
+                Where=(ga.RESOURCE_ID == self._resourceID).And(
+                    ga.GROUP_ID == groupID
+                )
+            ).on(self._txn)
+
+
</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">@@ -2391,6 +2431,10 @@
</span><span class="cx">                 internal_request=is_internal,
</span><span class="cx">             ))
</span><span class="cx"> 
</span><ins>+            # group attendees
+            if scheduler.state == &quot;organizer&quot;:
+                yield self.reconcileGroupAttendees(component)
+
</ins><span class="cx">             # Set an attribute on this object to indicate that it is valid to check for an event split. We need to do this here so that if a timeout
</span><span class="cx">             # occurs whilst doing implicit processing (most likely because the event is too big) we are able to subsequently detect that it is OK
</span><span class="cx">             # to split and then try that.
</span><span class="lines">@@ -2635,9 +2679,8 @@
</span><span class="cx"> 
</span><span class="cx">         yield self.updateDatabase(component, inserting=inserting)
</span><span class="cx"> 
</span><del>-        # add GROUP_ATTENNDEE rows using just created _resourceID
-        if inserting:
-            yield self.expandGroupAttendees(component, False)
</del><ins>+        # update GROUP_ATTENNDEE rows using
+        yield self.updateGROUP_ATTENDEE()
</ins><span class="cx"> 
</span><span class="cx">         # Post process managed attachments
</span><span class="cx">         if internal_state in (
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhodirectorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/directory.py (13322 => 13323)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/directory.py        2014-04-18 16:32:45 UTC (rev 13322)
+++ CalendarServer/trunk/txdav/who/directory.py        2014-04-18 18:05:54 UTC (rev 13323)
</span><span class="lines">@@ -505,7 +505,7 @@
</span><span class="cx">                     returnValue(True)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def attendee(self, params={}):
</del><ins>+    def attendeeProperty(self, params={}):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Returns a pycalendar ATTENDEE property for this record.
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhogroupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/groups.py (13322 => 13323)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/groups.py        2014-04-18 16:32:45 UTC (rev 13322)
+++ CalendarServer/trunk/txdav/who/groups.py        2014-04-18 18:05:54 UTC (rev 13323)
</span><span class="lines">@@ -23,8 +23,9 @@
</span><span class="cx"> from twext.enterprise.dal.syntax import Delete, Select
</span><span class="cx"> from twext.enterprise.jobqueue import WorkItem, PeerConnectionPool
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><del>-from txdav.common.datastore.sql_tables import schema
</del><ins>+from twistedcaldav.ical import normalize_iCalStr
</ins><span class="cx"> from txdav.caldav.datastore.sql import CalendarStoreFeatures
</span><ins>+from txdav.common.datastore.sql_tables import schema
</ins><span class="cx"> import datetime
</span><span class="cx"> import hashlib
</span><span class="cx"> 
</span><span class="lines">@@ -177,28 +178,15 @@
</span><span class="cx"> 
</span><span class="cx">         # get db object
</span><span class="cx">         calendarObject = (yield CalendarStoreFeatures(self.transaction._store).calendarObjectWithID(self.transaction, self.resourceID))
</span><del>-        component = yield calendarObject.componentForUser()
</del><ins>+        oldComponent = yield calendarObject.componentForUser()
</ins><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="cx">         # so we can do a diff to test implicit scheduling changes
</span><del>-        component = component.duplicate()
</del><ins>+        component = oldComponent.duplicate()
</ins><span class="cx"> 
</span><del>-        # TODO: Check performance because:
-        #    1) if the component is changed then expandGroupAttendee() will be called again to validate
-        #    2) The group and members are in the group cache so could use them here
-
-        # get group record and members
-        groupUID, _ignore_name, _ignore_membershipHash = yield self.transaction.groupByID(self.groupID)
-        groupRecord = yield self.transaction.directoryService().recordWithUID(groupUID)
-        members = yield groupRecord.expandedMembers() if groupRecord else set()
-
-        # expand
-        changed = yield component.expandGroupAttendee(
-            groupRecord.canonicalCalendarUserAddress(),
-            set([member.canonicalCalendarUserAddress() for member in members]),
-            self.transaction.directoryService().recordWithCalendarUserAddress
-        )
-        if changed:
</del><ins>+        # sync group attendees
+        calendarObject.reconcileGroupAttendees(component)
+        if normalize_iCalStr(oldComponent, sort=True) != normalize_iCalStr(component, sort=True):
</ins><span class="cx">             yield calendarObject.setComponent(component)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -319,9 +307,10 @@
</span><span class="cx">             Does the work of a per-group refresh work item
</span><span class="cx">             Faults in the flattened membership of a group, as UIDs
</span><span class="cx">             and updates the GROUP_MEMBERSHIP table
</span><del>-            WorkProposals are returned for tests
</del><ins>+            WorkProposal is returned for tests
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self.log.debug(&quot;Faulting in group: {g}&quot;, g=groupUID)
</span><ins>+        wp = None
</ins><span class="cx">         record = (yield self.directory.recordWithUID(groupUID))
</span><span class="cx">         if record is None:
</span><span class="cx">             # FIXME: the group has disappeared from the directory.
</span><span class="lines">@@ -356,9 +345,9 @@
</span><span class="cx">                     newMemberUIDs.add(member.uid)
</span><span class="cx">                 yield self.synchronizeMembers(txn, groupID, newMemberUIDs)
</span><span class="cx"> 
</span><del>-            wps = yield self.scheduleEventReconciliations(txn, groupID)
</del><ins>+            wp = yield self.scheduleEventReconciliations(txn, groupID)
</ins><span class="cx"> 
</span><del>-        returnValue(wps)
</del><ins>+        returnValue(wp)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -405,18 +394,18 @@
</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 class="cx">         work items for them.
</span><del>-        returns: WorkProposal list
</del><ins>+        returns: WorkProposal
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        groupAttendee = schema.GROUP_ATTENDEE
</del><ins>+        ga = schema.GROUP_ATTENDEE
</ins><span class="cx">         rows = yield Select(
</span><del>-            [groupAttendee.RESOURCE_ID, ],
-            From=groupAttendee,
-            Where=groupAttendee.GROUP_ID == groupID,
</del><ins>+            [ga.RESOURCE_ID, ],
+            From=ga,
+            Where=ga.GROUP_ID == groupID,
</ins><span class="cx">         ).on(txn)
</span><del>-        eventIDs = [row[0] for row in rows]
</del><span class="cx"> 
</span><del>-        wps = []
-        for eventID in eventIDs:
</del><ins>+        wp = None
+        if rows:
+            eventID = rows[0][0]
</ins><span class="cx"> 
</span><span class="cx">             notBefore = (
</span><span class="cx">                 datetime.datetime.utcnow() +
</span><span class="lines">@@ -436,9 +425,8 @@
</span><span class="cx">                 groupID=groupID,
</span><span class="cx">                 notBefore=notBefore
</span><span class="cx">             )
</span><del>-            wps.append(wp)
</del><span class="cx"> 
</span><del>-        returnValue(tuple(wps))
</del><ins>+        returnValue(wp)
</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 (13322 => 13323)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-04-18 16:32:45 UTC (rev 13322)
+++ CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-04-18 18:05:54 UTC (rev 13323)
</span><span class="lines">@@ -138,7 +138,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), normalize_iCalStr(data_get_1))
</del><ins>+        self.assertEqual(normalize_iCalStr(vcalendar2, sort=True), normalize_iCalStr(data_get_1, sort=True))
</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">@@ -303,7 +303,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), normalize_iCalStr(data_get_1))
</del><ins>+        self.assertEqual(normalize_iCalStr(vcalendar2, sort=True), normalize_iCalStr(data_get_1, sort=True))
</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">@@ -372,7 +372,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), normalize_iCalStr(data_get_1))
</del><ins>+        self.assertEqual(normalize_iCalStr(vcalendar2, sort=True), normalize_iCalStr(data_get_1, sort=True))
</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">@@ -447,8 +447,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>-        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
-        self.assertEqual(set(wps), set())
</del><ins>+        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
+        self.assertEqual(wp, None)
</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">@@ -465,11 +465,9 @@
</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>-        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</del><ins>+        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</ins><span class="cx">         yield self.commit()
</span><del>-        self.assertEqual(len(wps), 1)
-        for wp in wps:
-            yield wp.whenExecuted()
</del><ins>+        yield wp.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">@@ -480,11 +478,9 @@
</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>-        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</del><ins>+        wp = yield groupCacher.refreshGroup(self.transactionUnderTest(), &quot;20000000-0000-0000-0000-000000000001&quot;)
</ins><span class="cx">         yield self.commit()
</span><del>-        self.assertEqual(len(wps), 1)
-        for wp in wps:
-            yield wp.whenExecuted()
</del><ins>+        yield wp.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></pre>
</div>
</div>

</body>
</html>