<!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>[12042] 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/12042">12042</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2013-12-06 21:24:08 -0800 (Fri, 06 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>checkpoint</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagengroupcachertwextwhogroupspy">CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py</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>
<li><a href="#CalendarServerbranchesuserssagengroupcachertxdavcaldavdatastoreutilpy">CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/util.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 (12041 => 12042)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py        2013-12-06 21:43:35 UTC (rev 12041)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py        2013-12-07 05:24:08 UTC (rev 12042)
</span><span class="lines">@@ -25,7 +25,7 @@
</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 twistedcaldav.ical import ignoredComponents
</del><ins>+from txdav.caldav.datastore.util import normalizationLookup
</ins><span class="cx"> from txdav.common.datastore.sql_tables import schema
</span><span class="cx"> import datetime
</span><span class="cx"> import hashlib
</span><span class="lines">@@ -133,15 +133,6 @@
</span><span class="cx">             )
</span><span class="cx">         ).on(self.transaction)
</span><span class="cx"> 
</span><del>-        # get group individual UIDs
-        groupMemember = schema.GROUP_MEMBERSHIP
-        rows = yield Select(
-                [groupMemember.MEMBER_GUID, ],
-                From=groupMemember,
-                Where=groupMemember.GROUP_ID == self.groupID,
-        ).on(self.transaction)
-        individualGUIDs = [row[0] for row in rows]
-
</del><span class="cx">         # get calendar Object
</span><span class="cx">         calObject = schema.CALENDAR_OBJECT
</span><span class="cx">         rows = yield Select(
</span><span class="lines">@@ -150,7 +141,7 @@
</span><span class="cx">                 Where=calObject.RESOURCE_ID == self.eventID,
</span><span class="cx">         ).on(self.transaction)
</span><span class="cx"> 
</span><del>-        calendarID = row[0][0]
</del><ins>+        calendarID = rows[0][0]
</ins><span class="cx">         calendarHome = (yield self.Calendar._ownerHomeWithResourceID.on(
</span><span class="cx">             self.transaction, resourceID=calendarID)
</span><span class="cx">         )[0][0]
</span><span class="lines">@@ -159,43 +150,20 @@
</span><span class="cx">         calendarObject = yield calendar.objectResourceWithID(self.eventID)
</span><span class="cx">         changed = False
</span><span class="cx"> 
</span><del>-        individualUUIDs = set([&quot;urn:uuid:&quot; + individualGUID for individualGUID in individualGUIDs])
-        groupUUID = &quot;urn:uuid:&quot; + self.groupGUID()
-        vcalendar = yield calendarObject.component()
-        for component in vcalendar.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        # get group individual UIDs
+        groupMemember = schema.GROUP_MEMBERSHIP
+        rows = yield Select(
+                [groupMemember.MEMBER_GUID, ],
+                From=groupMemember,
+                Where=groupMemember.GROUP_ID == self.groupID,
+        ).on(self.transaction)
+        individualGUIDs = [row[0] for row in rows]
</ins><span class="cx"> 
</span><del>-            oldAttendeeProps = component.getAttendees()
-            oldAttendeeUUIDs = set([attendeeProp.value() for attendeeProp in oldAttendeeProps])
</del><ins>+        component = yield calendarObject.component()
+        changed = component.expandGroupAttendee(self.groupGUID, individualGUIDs, normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
</ins><span class="cx"> 
</span><del>-            # add new member attendees
-            for individualUUID in individualUUIDs - oldAttendeeUUIDs:
-                individualGUID = individualUUID[len(&quot;urn:uuid:&quot;):]
-                directoryRecord = self.transaction.directoryService().recordWithUID(individualGUID)
-                newAttendeeProp = directoryRecord.attendee(params={&quot;MEMBER&quot;: groupUUID})
-                component.addProperty(newAttendeeProp)
-                changed = True
-
-            # remove attendee or update MEMBER attribute for non-primary attendees in this group,
-            for attendeeProp in oldAttendeeProps:
-                if attendeeProp.hasParameter(&quot;MEMBER&quot;):
-                    parameterValues = attendeeProp.parameterValues(&quot;MEMBER&quot;)
-                    if groupUUID in parameterValues:
-                        if attendeeProp.value() not in individualUUIDs:
-                            attendeeProp.removeParameterValue(&quot;MEMBER&quot;, groupUUID)
-                            if not attendeeProp.parameterValues(&quot;MEMBER&quot;):
-                                component.removeProperty(attendeeProp)
-                            changed = True
-                    else:
-                        if attendeeProp.value() in individualUUIDs:
-                            attendeeProp.setParameter(&quot;MEMBER&quot;, parameterValues + [groupUUID, ])
-                            changed = True
-
-        # replace old with new
</del><span class="cx">         if changed:
</span><del>-            # TODO:  call calendarObject._setComponentInternal( vcalendar, mode ) instead?
-            yield calendarObject.setComponent(vcalendar)
</del><ins>+            yield calendarObject.setComponent(component)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</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 (12041 => 12042)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py        2013-12-06 21:43:35 UTC (rev 12041)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py        2013-12-07 05:24:08 UTC (rev 12042)
</span><span class="lines">@@ -343,7 +343,7 @@
</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;EMAIL=group01@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:group01
</del><ins>+ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:group01
</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></pre></div>
<a id="CalendarServerbranchesuserssagengroupcachertwistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py (12041 => 12042)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py        2013-12-06 21:43:35 UTC (rev 12041)
+++ CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py        2013-12-07 05:24:08 UTC (rev 12042)
</span><span class="lines">@@ -3251,7 +3251,7 @@
</span><span class="cx">                 # Check that we can lookup this calendar user address - if not
</span><span class="cx">                 # we cannot do anything with it
</span><span class="cx">                 cuaddr = normalizeCUAddr(prop.value())
</span><del>-                name, guid, cuaddrs = lookupFunction(cuaddr, principalFunction, config)
</del><ins>+                name, guid, cutype, cuaddrs = lookupFunction(cuaddr, principalFunction, config)
</ins><span class="cx">                 if guid is None:
</span><span class="cx">                     continue
</span><span class="cx"> 
</span><span class="lines">@@ -3263,8 +3263,6 @@
</span><span class="cx">                 # Get any CN parameter
</span><span class="cx">                 oldCN = prop.parameterValue(&quot;CN&quot;)
</span><span class="cx"> 
</span><del>-                cutype = prop.parameterValue(&quot;CUTYPE&quot;)
-
</del><span class="cx">                 if toUUID:
</span><span class="cx">                     # Always re-write value to urn:uuid
</span><span class="cx">                     prop.setValue(&quot;urn:uuid:%s&quot; % (guid,))
</span><span class="lines">@@ -3343,11 +3341,56 @@
</span><span class="cx">                     else:
</span><span class="cx">                         prop.removeParameter(&quot;EMAIL&quot;)
</span><span class="cx"> 
</span><ins>+                if cutype == &quot;INDIVIDUAL&quot;:
+                    cutype = None
+
+                if cutype != prop.parameterValue(&quot;CUTYPE&quot;):
+                    if cutype:
+                        prop.setParameter(&quot;CUTYPE&quot;, cutype)
+                    else:
+                        prop.removeParameter(&quot;CUTYPE&quot;)
+
</ins><span class="cx">             # For VPOLL also do immediate children
</span><span class="cx">             if component.name() == &quot;VPOLL&quot;:
</span><span class="cx">                 component.normalizeCalendarUserAddresses(lookupFunction, principalFunction, toUUID)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def expandGroupAttendee(self, groupGUID, individualGUIDs, lookupFunction, principalFunction):
+
+        individualUUIDs = set([&quot;urn:uuid:&quot; + individualGUID for individualGUID in individualGUIDs])
+        groupUUID = &quot;urn:uuid:&quot; + groupGUID
+        changed = False
+        for component in self.subcomponents():
+            if component.name() in ignoredComponents:
+                continue
+
+            oldAttendeeProps = component.properties(&quot;ATTENDEE&quot;)
+            oldAttendeeUUIDs = set([attendeeProp.value() for attendeeProp in oldAttendeeProps])
+
+            # add new member attendees
+            for individualUUID in individualUUIDs - oldAttendeeUUIDs:
+                directoryRecord = lookupFunction(individualUUID, principalFunction, config)
+                newAttendeeProp = directoryRecord.attendee(params={&quot;MEMBER&quot;: groupUUID})
+                component.addProperty(newAttendeeProp)
+                changed = True
+
+            # remove attendee or update MEMBER attribute for non-primary attendees in this group,
+            for attendeeProp in oldAttendeeProps:
+                if attendeeProp.hasParameter(&quot;MEMBER&quot;):
+                    parameterValues = attendeeProp.parameterValues(&quot;MEMBER&quot;)
+                    if groupUUID in parameterValues:
+                        if attendeeProp.value() not in individualUUIDs:
+                            attendeeProp.removeParameterValue(&quot;MEMBER&quot;, groupUUID)
+                            if not attendeeProp.parameterValues(&quot;MEMBER&quot;):
+                                component.removeProperty(attendeeProp)
+                            changed = True
+                    else:
+                        if attendeeProp.value() in individualUUIDs:
+                            attendeeProp.setParameter(&quot;MEMBER&quot;, parameterValues + [groupUUID, ])
+                            changed = True
+        return changed
+
+
</ins><span class="cx">     def allPerUserUIDs(self):
</span><span class="cx"> 
</span><span class="cx">         results = set()
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagengroupcachertxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py (12041 => 12042)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py        2013-12-06 21:43:35 UTC (rev 12041)
+++ CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py        2013-12-07 05:24:08 UTC (rev 12042)
</span><span class="lines">@@ -1582,13 +1582,16 @@
</span><span class="cx">             if not self.calendar().isSupportedComponent(component.mainType()):
</span><span class="cx">                 raise InvalidComponentTypeError(&quot;Invalid component type %s for calendar: %s&quot; % (component.mainType(), self.calendar(),))
</span><span class="cx"> 
</span><del>-            # Valid attendee list size check
-            yield self.validAttendeeListSizeCheck(component, inserting)
-
</del><span class="cx">             # Normalize the calendar user addresses once we know we have valid
</span><span class="cx">             # calendar data
</span><span class="cx">             component.normalizeCalendarUserAddresses(normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
</span><span class="cx"> 
</span><ins>+            # Expand groups
+            yield self.expandGroupAttendees(component)
+
+            # Valid attendee list size check
+            yield self.validAttendeeListSizeCheck(component, inserting)
+
</ins><span class="cx">         # Possible timezone stripping
</span><span class="cx">         if config.EnableTimezonesByReference:
</span><span class="cx">             component.stripKnownTimezones()
</span><span class="lines">@@ -1601,8 +1604,40 @@
</span><span class="cx">             self.validAccess(component, inserting, internal_state)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def validCalendarDataCheck(self, component, inserting):
</del><ins>+    @inlineCallbacks
+    def expandGroupAttendees(self, component):
</ins><span class="cx">         &quot;&quot;&quot;
</span><ins>+        Expand group attendees
+        &quot;&quot;&quot;
+
+        if not config.Scheduling.Options.AllowGroupAsAttendee:
+            return
+
+        attendeeProps = component.getAllAttendeeProperties()
+        groupGUIDs = [
+            attendeeProp.value()[len(&quot;urn:uuid:&quot;):] for attendeeProp in attendeeProps
+            if attendeeProp.parameterValue(&quot;CUTYPE&quot;) == &quot;GROUP&quot;
+        ]
+
+        # FIXME: need to add event to Group resource ID here
+        #        need get get members here because they may not be cached yet
+
+        for groupGUID in groupGUIDs:
+            groupID, name, membershipHash = yield self._txn.groupByGUID(groupGUID)
+
+            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]
+
+            component.expandGroupAttendee(groupGUID, individualGUIDs, normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
+
+
+    def validCalendarDataCheck(self, component, inserting): #@UnusedVariable
+        &quot;&quot;&quot;
</ins><span class="cx">         Check that the calendar data is valid iCalendar.
</span><span class="cx">         @return:         tuple: (True/False if the calendar data is valid,
</span><span class="cx">                                  log message string).
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagengroupcachertxdavcaldavdatastoreutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/util.py (12041 => 12042)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/util.py        2013-12-06 21:43:35 UTC (rev 12041)
+++ CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/util.py        2013-12-07 05:24:08 UTC (rev 12042)
</span><span class="lines">@@ -103,7 +103,7 @@
</span><span class="cx"> def normalizationLookup(cuaddr, recordFunction, config):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Lookup function to be passed to ical.normalizeCalendarUserAddresses.
</span><del>-    Returns a tuple of (Full name, guid, and calendar user address list)
</del><ins>+    Returns a tuple of (Full name, guid, cutype and calendar user address list)
</ins><span class="cx">     for the given cuaddr.  The recordFunction is called to retrieve the
</span><span class="cx">     record for the cuaddr.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -114,7 +114,7 @@
</span><span class="cx">         record = None
</span><span class="cx"> 
</span><span class="cx">     if record is None:
</span><del>-        return (None, None, None)
</del><ins>+        return (None, None, None, None)
</ins><span class="cx">     else:
</span><span class="cx">         # RFC5545 syntax does not allow backslash escaping in
</span><span class="cx">         # parameter values. A double-quote is thus not allowed
</span><span class="lines">@@ -124,6 +124,7 @@
</span><span class="cx">         return (
</span><span class="cx">             record.fullName.replace('&quot;', &quot;'&quot;),
</span><span class="cx">             record.uid,
</span><ins>+            record.getCUType(),
</ins><span class="cx">             record.calendarUserAddresses,
</span><span class="cx">         )
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>