[CalendarServer-changes] [13610] twext/trunk/twext/who/opendirectory/_service.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 5 20:39:33 PDT 2014


Revision: 13610
          http://trac.calendarserver.org//changeset/13610
Author:   sagen at apple.com
Date:     2014-06-05 20:39:32 -0700 (Thu, 05 Jun 2014)
Log Message:
-----------
Limit OD queries to the record types we're configured for

Modified Paths:
--------------
    twext/trunk/twext/who/opendirectory/_service.py

Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py	2014-06-05 20:05:39 UTC (rev 13609)
+++ twext/trunk/twext/who/opendirectory/_service.py	2014-06-06 03:39:32 UTC (rev 13610)
@@ -416,6 +416,22 @@
         if not recordTypes:
             return None
 
+        # Scrub unsupported recordTypes
+        supportedODRecordTypes = []
+        for rt in self.recordTypes():
+            odRecordType = ODRecordType.fromRecordType(rt)
+            if odRecordType is not None:
+                supportedODRecordTypes.append(odRecordType.value)
+        scrubbedRecordTypes = []
+        for recordType in recordTypes:
+            if recordType in supportedODRecordTypes:
+                scrubbedRecordTypes.append(recordType)
+
+        if not scrubbedRecordTypes:
+            # None of the requested recordTypes are supported.
+            return None
+
+
         if queryString:
             matchType = ODMatchType.compound.value
         else:
@@ -426,7 +442,7 @@
 
         query, error = ODQuery.queryWithNode_forRecordTypes_attribute_matchType_queryValues_returnAttributes_maximumResults_error_(
             node,
-            list(recordTypes),
+            scrubbedRecordTypes,
             None,
             matchType,
             queryString,
@@ -537,9 +553,11 @@
             node = self.node
 
         # Scrub unsupported recordTypes
-        supportedODRecordTypes = [
-            ODRecordType.fromRecordType(rt).value for rt in self.recordTypes()
-        ]
+        supportedODRecordTypes = []
+        for rt in self.recordTypes():
+            odRecordType = ODRecordType.fromRecordType(rt)
+            if odRecordType is not None:
+                supportedODRecordTypes.append(odRecordType.value)
         scrubbedRecordTypes = []
         for recordType in recordTypes:
             if recordType in supportedODRecordTypes:
@@ -643,7 +661,7 @@
         @type query: L{ODQuery}
 
         @return: The records produced by executing the query.
-        @rtype: iterable of L{DirectoryRecord}
+        @rtype: list of L{DirectoryRecord}
         """
 
         # FIXME: This is blocking.
@@ -651,7 +669,7 @@
         # its delegate...
 
         if query is None:
-            return succeed(tuple())
+            return succeed([])
 
         odRecords, error = query.resultsAllowingPartial_error_(False, None)
 
@@ -765,7 +783,7 @@
 
             elif isinstance(subExpression, MatchExpression):
                 try:
-                    subQuery = yield self._queryFromMatchExpression(
+                    subQuery = self._queryFromMatchExpression(
                         subExpression, local=True
                     )
                 except UnsupportedRecordTypeError:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140605/069cbc4b/attachment.html>


More information about the calendarserver-changes mailing list