[CalendarServer-changes] [14093] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Oct 20 12:21:40 PDT 2014


Revision: 14093
          http://trac.calendarserver.org//changeset/14093
Author:   cdaboo at apple.com
Date:     2014-10-20 12:21:40 -0700 (Mon, 20 Oct 2014)
Log Message:
-----------
Use store api to do proxy principal expansion rather than have group expansion logic in the app-layer.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py
    CalendarServer/trunk/txdav/common/datastore/sql.py
    CalendarServer/trunk/txdav/dps/client.py
    CalendarServer/trunk/txdav/dps/commands.py
    CalendarServer/trunk/txdav/dps/server.py

Modified: CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py
===================================================================
--- 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)
@@ -373,36 +373,6 @@
         return self.parent.principalCollections()
 
 
-    @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)
-
-
     def _recordTypeFromProxyType(self):
         return {
             "calendar-proxy-read": DelegateRecordType.readDelegateGroup,
@@ -413,7 +383,7 @@
 
 
     @inlineCallbacks
-    def _directGroupMembers(self):
+    def _directGroupMembers(self, expanded=False):
         """
         Fault in the record representing the sub principal for this proxy type
         (either read-only or read-write), then fault in the direct members of
@@ -425,32 +395,28 @@
             self.parent.principalUID()
         )
         if record is not None:
-            memberRecords = yield record.members()
+            if expanded:
+                memberRecords = yield record.expandedMembers()
+            else:
+                memberRecords = yield record.members()
             for record in memberRecords:
-                if record is not None:
-                    principal = yield self.pcollection.principalForRecord(
-                        record
-                    )
+                if record is not None and (record.loginAllowed or record.recordType is BaseRecordType.group):
+                    principal = yield self.pcollection.principalForRecord(record)
                     if principal is not None:
-                        if (
-                            principal.record.loginAllowed or
-                            principal.record.recordType is BaseRecordType.group
-                        ):
-                            memberPrincipals.append(principal)
+                        memberPrincipals.append(principal)
         returnValue(memberPrincipals)
 
 
     def groupMembers(self):
-        return self._expandMemberPrincipals()
+        return self._directGroupMembers(expanded=False)
 
 
-    @inlineCallbacks
     def expandedGroupMembers(self):
         """
         Return the complete, flattened set of principals belonging to this
         group.
         """
-        returnValue((yield self._expandMemberPrincipals(infinity=True)))
+        return self._directGroupMembers(expanded=True)
 
 
     def groupMemberships(self):

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- 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)
@@ -1813,7 +1813,7 @@
         """
         Returns the UIDs of all delegates for the given delegator.  If
         expanded is False, only the direct delegates (users and groups)
-        are returned.  If expanded is True, the expanded membmership is
+        are returned.  If expanded is True, the expanded membership is
         returned, not including the groups themselves.
 
         @param delegator: the UID of the delegator

Modified: CalendarServer/trunk/txdav/dps/client.py
===================================================================
--- 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)
@@ -44,7 +44,7 @@
     WikiAccessForUIDCommand, ContinuationCommand,
     StatsCommand, ExternalDelegatesCommand, ExpandedMemberUIDsCommand,
     AddMembersCommand, RemoveMembersCommand,
-    UpdateRecordsCommand
+    UpdateRecordsCommand, ExpandedMembersCommand
 )
 from txdav.who.delegates import RecordType as DelegatesRecordType
 from txdav.who.directory import (
@@ -483,6 +483,25 @@
             return succeed([])
 
 
+    def expandedMembers(self):
+        """
+        Only allowed for delegates - not regular groups.
+        """
+        if self.recordType in (
+            DelegatesRecordType.readDelegateGroup,
+            DelegatesRecordType.writeDelegateGroup,
+            DelegatesRecordType.readDelegatorGroup,
+            DelegatesRecordType.writeDelegatorGroup,
+        ):
+            return self.service._call(
+                ExpandedMembersCommand,
+                self.service._processMultipleRecords,
+                uid=self.uid.encode("utf-8")
+            )
+        else:
+            return succeed([])
+
+
     def groups(self):
         return self.service._call(
             GroupsCommand,

Modified: CalendarServer/trunk/txdav/dps/commands.py
===================================================================
--- 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)
@@ -149,6 +149,17 @@
 
 
 
+class ExpandedMembersCommand(amp.Command):
+    arguments = [
+        ('uid', amp.String()),
+    ]
+    response = [
+        ('items', amp.ListOf(amp.String())),
+        ('continuation', amp.String(optional=True)),
+    ]
+
+
+
 class GroupsCommand(amp.Command):
     arguments = [
         ('uid', amp.String()),

Modified: CalendarServer/trunk/txdav/dps/server.py
===================================================================
--- 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)
@@ -35,7 +35,7 @@
     RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
     RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
     RecordsMatchingTokensCommand, RecordsMatchingFieldsCommand,
-    MembersCommand, GroupsCommand, SetMembersCommand,
+    MembersCommand, ExpandedMembersCommand, GroupsCommand, SetMembersCommand,
     VerifyPlaintextPasswordCommand, VerifyHTTPDigestCommand,
     WikiAccessForUIDCommand, ContinuationCommand,
     ExternalDelegatesCommand, StatsCommand, ExpandedMemberUIDsCommand,
@@ -387,14 +387,33 @@
 
         records = []
         if record is not None:
-            for member in (yield record.members()):
-                records.append(member)
+            records = (yield record.members())
 
         response = self._recordsToResponse(records)
         # log.debug("Responding with: {response}", response=response)
         returnValue(response)
 
 
+    @ExpandedMembersCommand.responder
+    @inlineCallbacks
+    def expandedMembers(self, uid):
+        uid = uid.decode("utf-8")
+        log.debug("ExpandedMembers: {u}", u=uid)
+        try:
+            record = (yield self._directory.recordWithUID(uid))
+        except Exception as e:
+            log.error("Failed in members", error=e)
+            record = None
+
+        records = []
+        if record is not None:
+            records = (yield record.members(expanded=True))
+
+        response = self._recordsToResponse(records)
+        # log.debug("Responding with: {response}", response=response)
+        returnValue(response)
+
+
     @AddMembersCommand.responder
     @inlineCallbacks
     def addMembers(self, uid, memberUIDs):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141020/8e50086f/attachment.html>


More information about the calendarserver-changes mailing list