[CalendarServer-changes] [13568] twext/trunk/twext/who/opendirectory

source_changes at macosforge.org source_changes at macosforge.org
Thu May 29 18:35:10 PDT 2014


Revision: 13568
          http://trac.calendarserver.org//changeset/13568
Author:   sagen at apple.com
Date:     2014-05-29 18:35:10 -0700 (Thu, 29 May 2014)
Log Message:
-----------
Scrub unsupported recordTypes from queries

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

Modified: twext/trunk/twext/who/opendirectory/__init__.py
===================================================================
--- twext/trunk/twext/who/opendirectory/__init__.py	2014-05-29 22:56:05 UTC (rev 13567)
+++ twext/trunk/twext/who/opendirectory/__init__.py	2014-05-30 01:35:10 UTC (rev 13568)
@@ -35,4 +35,3 @@
     DirectoryService,
     NoQOPDigestCredentialFactory,
 )
-from ._constants import RecordType

Modified: twext/trunk/twext/who/opendirectory/_constants.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_constants.py	2014-05-29 22:56:05 UTC (rev 13567)
+++ twext/trunk/twext/who/opendirectory/_constants.py	2014-05-30 01:35:10 UTC (rev 13568)
@@ -32,21 +32,6 @@
 # idirectory constants
 #
 
-class RecordType(Names):
-
-    user = NamedConstant()
-    user.description = u"user"
-
-    group = NamedConstant()
-    group.description = u"group"
-
-    location = NamedConstant()
-    location.description = u"location"
-
-    resource = NamedConstant()
-    resource.description = u"resource"
-
-
 class FieldName(Names):
     searchPath = NamedConstant()
     searchPath.description = u"search path"
@@ -87,10 +72,8 @@
     group.recordType = BaseRecordType.group
 
     location = ValueConstant(u"dsRecTypeStandard:Locations")
-    location.recordType = RecordType.location
 
     resource = ValueConstant(u"dsRecTypeStandard:Resources")
-    resource.recordType = RecordType.resource
 
     # accessControl = ValueConstant(u"dsRecTypeStandard:AccessControls")
     # afpServer = ValueConstant(u"dsRecTypeStandard:AFPServer")

Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py	2014-05-29 22:56:05 UTC (rev 13567)
+++ twext/trunk/twext/who/opendirectory/_service.py	2014-05-30 01:35:10 UTC (rev 13568)
@@ -93,7 +93,13 @@
     """
 
 
+class UnsupportedRecordTypeError(OpenDirectoryError):
+    """
+    Record type not supported by service.
+    """
 
+
+
 #
 # Directory Service
 #
@@ -492,9 +498,9 @@
                     "recordType argument does not match expression"
                 )
 
-            recordTypes = ODRecordType.fromRecordType(
-                expression.fieldValue
-            ).value
+            recordTypes = [
+                ODRecordType.fromRecordType(expression.fieldValue).value
+            ]
             if MatchFlags.NOT in flags:
                 recordTypes = list(
                     set([t.value for t in ODRecordType.iterconstants()]) -
@@ -512,7 +518,7 @@
             if recordType is None:
                 recordTypes = [t.value for t in ODRecordType.iterconstants()]
             else:
-                recordTypes = ODRecordType.fromRecordType(recordType).value
+                recordTypes = [ODRecordType.fromRecordType(recordType).value]
 
             queryAttribute = ODAttribute.fromFieldName(
                 expression.fieldName
@@ -530,9 +536,22 @@
         else:
             node = self.node
 
+        # Scrub unsupported recordTypes
+        supportedODRecordTypes = [
+            ODRecordType.fromRecordType(rt).value for rt in self.recordTypes()
+        ]
+        scrubbedRecordTypes = []
+        for recordType in recordTypes:
+            if recordType in supportedODRecordTypes:
+                scrubbedRecordTypes.append(recordType)
+
+        if not scrubbedRecordTypes:
+            # None of the requested recordTypes are supported.
+            raise UnsupportedRecordTypeError(u",".join(recordTypes))
+
         query, error = ODQuery.queryWithNode_forRecordTypes_attribute_matchType_queryValues_returnAttributes_maximumResults_error_(
             node,
-            recordTypes,
+            scrubbedRecordTypes,
             queryAttribute,
             matchType | caseInsensitive,
             queryValue,
@@ -676,6 +695,9 @@
             except QueryNotSupportedError:
                 pass  # Let the superclass try
 
+            except UnsupportedRecordTypeError:
+                return succeed([])
+
         return BaseDirectoryService.recordsFromNonCompoundExpression(
             self, expression
         )
@@ -740,9 +762,12 @@
                 )
 
             elif isinstance(subExpression, MatchExpression):
-                subQuery = yield self._queryFromMatchExpression(
-                    subExpression, local=True
-                )
+                try:
+                    subQuery = yield self._queryFromMatchExpression(
+                        subExpression, local=True
+                    )
+                except UnsupportedRecordTypeError:
+                    continue
                 subRecords = yield self._recordsFromQuery(subQuery)
 
             else:
@@ -832,6 +857,8 @@
             returnValue((yield BaseDirectoryService.recordWithShortName(
                 self, recordType, shortName)))
 
+        except UnsupportedRecordTypeError:
+            returnValue(None)
 
 
 @implementer(IPlaintextPasswordVerifier, IHTTPDigestVerifier)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140529/63b7e6f8/attachment.html>


More information about the calendarserver-changes mailing list