<!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>[14093] 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/14093">14093</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-10-20 12:21:40 -0700 (Mon, 20 Oct 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Use store api to do proxy principal expansion rather than have group expansion logic in the app-layer.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavdirectorycalendaruserproxypy">CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresqlpy">CalendarServer/trunk/txdav/common/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavdpsclientpy">CalendarServer/trunk/txdav/dps/client.py</a></li>
<li><a href="#CalendarServertrunktxdavdpscommandspy">CalendarServer/trunk/txdav/dps/commands.py</a></li>
<li><a href="#CalendarServertrunktxdavdpsserverpy">CalendarServer/trunk/txdav/dps/server.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavdirectorycalendaruserproxypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py (14092 => 14093)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py        2014-10-17 23:41:13 UTC (rev 14092)
+++ CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py        2014-10-20 19:21:40 UTC (rev 14093)
</span><span class="lines">@@ -373,36 +373,6 @@
</span><span class="cx">         return self.parent.principalCollections()
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @inlineCallbacks
-    def _expandMemberPrincipals(self, uid=None, relatives=None, uids=None, infinity=False):
-        if uid is None:
-            uid = self.principalUID()
-        if relatives is None:
-            relatives = set()
-        if uids is None:
-            uids = set()
-
-        if uid not in uids:
-            from twistedcaldav.directory.principal import DirectoryPrincipalResource
-            uids.add(uid)
-            principal = yield self.pcollection.principalForUID(uid)
-            if isinstance(principal, CalendarUserProxyPrincipalResource):
-                members = yield self._directGroupMembers()
-                for member in members:
-                    if member.principalUID() not in uids:
-                        relatives.add(member)
-                        if infinity:
-                            yield self._expandMemberPrincipals(member.principalUID(), relatives, uids, infinity=infinity)
-            elif isinstance(principal, DirectoryPrincipalResource):
-                if infinity:
-                    members = yield principal.expandedGroupMembers()
-                else:
-                    members = yield principal.groupMembers()
-                relatives.update(members)
-
-        returnValue(relatives)
-
-
</del><span class="cx">     def _recordTypeFromProxyType(self):
</span><span class="cx">         return {
</span><span class="cx">             &quot;calendar-proxy-read&quot;: DelegateRecordType.readDelegateGroup,
</span><span class="lines">@@ -413,7 +383,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def _directGroupMembers(self):
</del><ins>+    def _directGroupMembers(self, expanded=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Fault in the record representing the sub principal for this proxy type
</span><span class="cx">         (either read-only or read-write), then fault in the direct members of
</span><span class="lines">@@ -425,32 +395,28 @@
</span><span class="cx">             self.parent.principalUID()
</span><span class="cx">         )
</span><span class="cx">         if record is not None:
</span><del>-            memberRecords = yield record.members()
</del><ins>+            if expanded:
+                memberRecords = yield record.expandedMembers()
+            else:
+                memberRecords = yield record.members()
</ins><span class="cx">             for record in memberRecords:
</span><del>-                if record is not None:
-                    principal = yield self.pcollection.principalForRecord(
-                        record
-                    )
</del><ins>+                if record is not None and (record.loginAllowed or record.recordType is BaseRecordType.group):
+                    principal = yield self.pcollection.principalForRecord(record)
</ins><span class="cx">                     if principal is not None:
</span><del>-                        if (
-                            principal.record.loginAllowed or
-                            principal.record.recordType is BaseRecordType.group
-                        ):
-                            memberPrincipals.append(principal)
</del><ins>+                        memberPrincipals.append(principal)
</ins><span class="cx">         returnValue(memberPrincipals)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def groupMembers(self):
</span><del>-        return self._expandMemberPrincipals()
</del><ins>+        return self._directGroupMembers(expanded=False)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @inlineCallbacks
</del><span class="cx">     def expandedGroupMembers(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Return the complete, flattened set of principals belonging to this
</span><span class="cx">         group.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        returnValue((yield self._expandMemberPrincipals(infinity=True)))
</del><ins>+        return self._directGroupMembers(expanded=True)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def groupMemberships(self):
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql.py (14092 => 14093)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql.py        2014-10-17 23:41:13 UTC (rev 14092)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py        2014-10-20 19:21:40 UTC (rev 14093)
</span><span class="lines">@@ -1813,7 +1813,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Returns the UIDs of all delegates for the given delegator.  If
</span><span class="cx">         expanded is False, only the direct delegates (users and groups)
</span><del>-        are returned.  If expanded is True, the expanded membmership is
</del><ins>+        are returned.  If expanded is True, the expanded membership is
</ins><span class="cx">         returned, not including the groups themselves.
</span><span class="cx"> 
</span><span class="cx">         @param delegator: the UID of the delegator
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpsclientpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/client.py (14092 => 14093)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/client.py        2014-10-17 23:41:13 UTC (rev 14092)
+++ CalendarServer/trunk/txdav/dps/client.py        2014-10-20 19:21:40 UTC (rev 14093)
</span><span class="lines">@@ -44,7 +44,7 @@
</span><span class="cx">     WikiAccessForUIDCommand, ContinuationCommand,
</span><span class="cx">     StatsCommand, ExternalDelegatesCommand, ExpandedMemberUIDsCommand,
</span><span class="cx">     AddMembersCommand, RemoveMembersCommand,
</span><del>-    UpdateRecordsCommand
</del><ins>+    UpdateRecordsCommand, ExpandedMembersCommand
</ins><span class="cx"> )
</span><span class="cx"> from txdav.who.delegates import RecordType as DelegatesRecordType
</span><span class="cx"> from txdav.who.directory import (
</span><span class="lines">@@ -483,6 +483,25 @@
</span><span class="cx">             return succeed([])
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def expandedMembers(self):
+        &quot;&quot;&quot;
+        Only allowed for delegates - not regular groups.
+        &quot;&quot;&quot;
+        if self.recordType in (
+            DelegatesRecordType.readDelegateGroup,
+            DelegatesRecordType.writeDelegateGroup,
+            DelegatesRecordType.readDelegatorGroup,
+            DelegatesRecordType.writeDelegatorGroup,
+        ):
+            return self.service._call(
+                ExpandedMembersCommand,
+                self.service._processMultipleRecords,
+                uid=self.uid.encode(&quot;utf-8&quot;)
+            )
+        else:
+            return succeed([])
+
+
</ins><span class="cx">     def groups(self):
</span><span class="cx">         return self.service._call(
</span><span class="cx">             GroupsCommand,
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpscommandspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/commands.py (14092 => 14093)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/commands.py        2014-10-17 23:41:13 UTC (rev 14092)
+++ CalendarServer/trunk/txdav/dps/commands.py        2014-10-20 19:21:40 UTC (rev 14093)
</span><span class="lines">@@ -149,6 +149,17 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class ExpandedMembersCommand(amp.Command):
+    arguments = [
+        ('uid', amp.String()),
+    ]
+    response = [
+        ('items', amp.ListOf(amp.String())),
+        ('continuation', amp.String(optional=True)),
+    ]
+
+
+
</ins><span class="cx"> class GroupsCommand(amp.Command):
</span><span class="cx">     arguments = [
</span><span class="cx">         ('uid', amp.String()),
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpsserverpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/server.py (14092 => 14093)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/server.py        2014-10-17 23:41:13 UTC (rev 14092)
+++ CalendarServer/trunk/txdav/dps/server.py        2014-10-20 19:21:40 UTC (rev 14093)
</span><span class="lines">@@ -35,7 +35,7 @@
</span><span class="cx">     RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
</span><span class="cx">     RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
</span><span class="cx">     RecordsMatchingTokensCommand, RecordsMatchingFieldsCommand,
</span><del>-    MembersCommand, GroupsCommand, SetMembersCommand,
</del><ins>+    MembersCommand, ExpandedMembersCommand, GroupsCommand, SetMembersCommand,
</ins><span class="cx">     VerifyPlaintextPasswordCommand, VerifyHTTPDigestCommand,
</span><span class="cx">     WikiAccessForUIDCommand, ContinuationCommand,
</span><span class="cx">     ExternalDelegatesCommand, StatsCommand, ExpandedMemberUIDsCommand,
</span><span class="lines">@@ -387,14 +387,33 @@
</span><span class="cx"> 
</span><span class="cx">         records = []
</span><span class="cx">         if record is not None:
</span><del>-            for member in (yield record.members()):
-                records.append(member)
</del><ins>+            records = (yield record.members())
</ins><span class="cx"> 
</span><span class="cx">         response = self._recordsToResponse(records)
</span><span class="cx">         # log.debug(&quot;Responding with: {response}&quot;, response=response)
</span><span class="cx">         returnValue(response)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @ExpandedMembersCommand.responder
+    @inlineCallbacks
+    def expandedMembers(self, uid):
+        uid = uid.decode(&quot;utf-8&quot;)
+        log.debug(&quot;ExpandedMembers: {u}&quot;, u=uid)
+        try:
+            record = (yield self._directory.recordWithUID(uid))
+        except Exception as e:
+            log.error(&quot;Failed in members&quot;, error=e)
+            record = None
+
+        records = []
+        if record is not None:
+            records = (yield record.members(expanded=True))
+
+        response = self._recordsToResponse(records)
+        # log.debug(&quot;Responding with: {response}&quot;, response=response)
+        returnValue(response)
+
+
</ins><span class="cx">     @AddMembersCommand.responder
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def addMembers(self, uid, memberUIDs):
</span></span></pre>
</div>
</div>

</body>
</html>