[CalendarServer-changes] [13661] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 18 14:16:55 PDT 2014


Revision: 13661
          http://trac.calendarserver.org//changeset/13661
Author:   sagen at apple.com
Date:     2014-06-18 14:16:55 -0700 (Wed, 18 Jun 2014)
Log Message:
-----------
Landing recordtypes branch

Modified Paths:
--------------
    CalendarServer/trunk/contrib/od/test/test_live.py
    CalendarServer/trunk/requirements-stable.txt
    CalendarServer/trunk/txdav/dps/client.py
    CalendarServer/trunk/txdav/who/augment.py
    CalendarServer/trunk/txdav/who/delegates.py
    CalendarServer/trunk/txdav/who/directory.py
    CalendarServer/trunk/txdav/who/wiki.py

Property Changed:
----------------
    CalendarServer/trunk/


Property changes on: CalendarServer/trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /CalDAVTester/trunk:11193-11198
/CalendarServer/branches/config-separation:4379-4443
/CalendarServer/branches/egg-info-351:4589-4625
/CalendarServer/branches/generic-sqlstore:6167-6191
/CalendarServer/branches/new-store:5594-5934
/CalendarServer/branches/new-store-no-caldavfile:5911-5935
/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
/CalendarServer/branches/release/CalendarServer-5.2-dev:11972,12357-12358,12794,12814
/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
/CalendarServer/branches/users/cdaboo/cross-pod-sharing:12038-12191
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
/CalendarServer/branches/users/cdaboo/json:11622-11912
/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
/CalendarServer/branches/users/cdaboo/pods:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
/CalendarServer/branches/users/cdaboo/pycard:7227-7237
/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
/CalendarServer/branches/users/cdaboo/reverse-proxy-pods:11875-11900
/CalendarServer/branches/users/cdaboo/scheduling-queue-refresh:11783-12557
/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
/CalendarServer/branches/users/cdaboo/sharing-in-the-store:11935-12016
/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
/CalendarServer/branches/users/cdaboo/timezones:7443-7699
/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
/CalendarServer/branches/users/gaya/cleanrevisions:12152-12334
/CalendarServer/branches/users/gaya/sharedgroupfixes:12120-12142
/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
/CalendarServer/branches/users/glyph/conn-limit:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
/CalendarServer/branches/users/glyph/dalify:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
/CalendarServer/branches/users/glyph/deploybuild:7563-7572
/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
/CalendarServer/branches/users/glyph/disable-quota:7718-7727
/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
/CalendarServer/branches/users/glyph/hang-fix:11465-11491
/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
/CalendarServer/branches/users/glyph/linux-tests:6893-6900
/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
/CalendarServer/branches/users/glyph/new-export:7444-7485
/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
/CalendarServer/branches/users/glyph/oracle:7106-7155
/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
/CalendarServer/branches/users/glyph/other-html:8062-8091
/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
/CalendarServer/branches/users/glyph/q:9560-9688
/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
/CalendarServer/branches/users/glyph/quota:7604-7637
/CalendarServer/branches/users/glyph/sendfdport:5388-5424
/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
/CalendarServer/branches/users/glyph/sharedpool:6490-6550
/CalendarServer/branches/users/glyph/sharing-api:9192-9205
/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
/CalendarServer/branches/users/glyph/sql-store:5929-6073
/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
/CalendarServer/branches/users/glyph/subtransactions:7248-7258
/CalendarServer/branches/users/glyph/table-alias:8651-8664
/CalendarServer/branches/users/glyph/uidexport:7673-7676
/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
/CalendarServer/branches/users/sagen/applepush:8126-8184
/CalendarServer/branches/users/sagen/inboxitems:7380-7381
/CalendarServer/branches/users/sagen/locations-resources:5032-5051
/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
/CalendarServer/branches/users/sagen/move2who:12819-12860
/CalendarServer/branches/users/sagen/move2who-2:12861-12898
/CalendarServer/branches/users/sagen/move2who-3:12899-12913
/CalendarServer/branches/users/sagen/move2who-4:12914-13157
/CalendarServer/branches/users/sagen/move2who-5:13158-13163
/CalendarServer/branches/users/sagen/newcua:13309-13327
/CalendarServer/branches/users/sagen/newcua-1:13328-13330
/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/branches/users/sagen/resources-2:5084-5093
/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
/CalendarServer/branches/users/wsanchez/transations:5515-5593
   + /CalDAVTester/trunk:11193-11198
/CalendarServer/branches/config-separation:4379-4443
/CalendarServer/branches/egg-info-351:4589-4625
/CalendarServer/branches/generic-sqlstore:6167-6191
/CalendarServer/branches/new-store:5594-5934
/CalendarServer/branches/new-store-no-caldavfile:5911-5935
/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
/CalendarServer/branches/release/CalendarServer-5.2-dev:11972,12357-12358,12794,12814
/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
/CalendarServer/branches/users/cdaboo/cross-pod-sharing:12038-12191
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
/CalendarServer/branches/users/cdaboo/json:11622-11912
/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
/CalendarServer/branches/users/cdaboo/pods:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
/CalendarServer/branches/users/cdaboo/pycard:7227-7237
/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
/CalendarServer/branches/users/cdaboo/reverse-proxy-pods:11875-11900
/CalendarServer/branches/users/cdaboo/scheduling-queue-refresh:11783-12557
/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
/CalendarServer/branches/users/cdaboo/sharing-in-the-store:11935-12016
/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
/CalendarServer/branches/users/cdaboo/timezones:7443-7699
/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
/CalendarServer/branches/users/gaya/cleanrevisions:12152-12334
/CalendarServer/branches/users/gaya/sharedgroupfixes:12120-12142
/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
/CalendarServer/branches/users/glyph/conn-limit:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
/CalendarServer/branches/users/glyph/dalify:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
/CalendarServer/branches/users/glyph/deploybuild:7563-7572
/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
/CalendarServer/branches/users/glyph/disable-quota:7718-7727
/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
/CalendarServer/branches/users/glyph/hang-fix:11465-11491
/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
/CalendarServer/branches/users/glyph/linux-tests:6893-6900
/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
/CalendarServer/branches/users/glyph/new-export:7444-7485
/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
/CalendarServer/branches/users/glyph/oracle:7106-7155
/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
/CalendarServer/branches/users/glyph/other-html:8062-8091
/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
/CalendarServer/branches/users/glyph/q:9560-9688
/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
/CalendarServer/branches/users/glyph/quota:7604-7637
/CalendarServer/branches/users/glyph/sendfdport:5388-5424
/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
/CalendarServer/branches/users/glyph/sharedpool:6490-6550
/CalendarServer/branches/users/glyph/sharing-api:9192-9205
/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
/CalendarServer/branches/users/glyph/sql-store:5929-6073
/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
/CalendarServer/branches/users/glyph/subtransactions:7248-7258
/CalendarServer/branches/users/glyph/table-alias:8651-8664
/CalendarServer/branches/users/glyph/uidexport:7673-7676
/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
/CalendarServer/branches/users/sagen/applepush:8126-8184
/CalendarServer/branches/users/sagen/inboxitems:7380-7381
/CalendarServer/branches/users/sagen/locations-resources:5032-5051
/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
/CalendarServer/branches/users/sagen/move2who:12819-12860
/CalendarServer/branches/users/sagen/move2who-2:12861-12898
/CalendarServer/branches/users/sagen/move2who-3:12899-12913
/CalendarServer/branches/users/sagen/move2who-4:12914-13157
/CalendarServer/branches/users/sagen/move2who-5:13158-13163
/CalendarServer/branches/users/sagen/newcua:13309-13327
/CalendarServer/branches/users/sagen/newcua-1:13328-13330
/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
/CalendarServer/branches/users/sagen/recordtypes:13648-13656
/CalendarServer/branches/users/sagen/recordtypes-2:13657
/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/branches/users/sagen/resources-2:5084-5093
/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
/CalendarServer/branches/users/wsanchez/transations:5515-5593

Modified: CalendarServer/trunk/contrib/od/test/test_live.py
===================================================================
--- CalendarServer/trunk/contrib/od/test/test_live.py	2014-06-18 21:13:47 UTC (rev 13660)
+++ CalendarServer/trunk/contrib/od/test/test_live.py	2014-06-18 21:16:55 UTC (rev 13661)
@@ -40,7 +40,16 @@
     from twext.who.expression import (
         CompoundExpression, Operand, MatchExpression, MatchType
     )
+    from twext.who.idirectory import QueryNotSupportedError
+    from txdav.who.directory import CalendarDirectoryServiceMixin
+    from txdav.who.opendirectory import DirectoryService as OpenDirectoryService
+    from twext.who.expression import (
+        Operand, MatchType, MatchFlags, MatchExpression
+    )
 
+    class CalOpenDirectoryService(OpenDirectoryService, CalendarDirectoryServiceMixin):
+        pass
+
     LOCAL_SHORTNAMES = "odtestalbert odtestbill odtestcarl odtestdavid odtestsubgroupa".split()
     NETWORK_SHORTNAMES = "odtestamanda odtestbetty odtestcarlene odtestdenise odtestsubgroupb odtestgrouptop".split()
 
@@ -160,18 +169,119 @@
             # We should get back users and groups since we did not specify a type:
             self.verifyResults(
                 records,
-                ["odtestbetty", "odtestalbert", "anotherodtestalbert", "odtestgroupbetty", "odtestgroupalbert"],
+                [
+                    "odtestbetty", "odtestalbert", "anotherodtestalbert",
+                    "odtestgroupbetty", "odtestgroupalbert"
+                ],
                 ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb"]
             )
 
 
         @onlyIfPopulated
         @inlineCallbacks
-        def test_compoundWithSingleRecordType(self):
+        def test_compoundWithExplicitRecordType(self):
             expression = CompoundExpression(
                 [
                     CompoundExpression(
                         [
+                            MatchExpression(
+                                self.service.fieldName.fullNames, u"be",
+                                matchType=MatchType.contains
+                            ),
+                            MatchExpression(
+                                self.service.fieldName.emailAddresses, u"be",
+                                matchType=MatchType.startsWith
+                            ),
+                        ],
+                        Operand.OR
+                    ),
+                    CompoundExpression(
+                        [
+                            MatchExpression(
+                                self.service.fieldName.fullNames, u"test",
+                                matchType=MatchType.contains
+                            ),
+                            MatchExpression(
+                                self.service.fieldName.emailAddresses, u"test",
+                                matchType=MatchType.startsWith
+                            ),
+                        ],
+                        Operand.OR
+                    ),
+                ],
+                Operand.AND
+            )
+            records = yield self.service.recordsFromExpression(
+                expression, recordTypes=[self.service.recordType.user]
+            )
+
+            # We should get back users but not groups:
+            self.verifyResults(
+                records,
+                ["odtestbetty", "odtestalbert", "anotherodtestalbert"],
+                ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb"]
+            )
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_compoundWithMultipleExplicitRecordTypes(self):
+            expression = CompoundExpression(
+                [
+                    CompoundExpression(
+                        [
+                            MatchExpression(
+                                self.service.fieldName.fullNames, u"be",
+                                matchType=MatchType.contains
+                            ),
+                            MatchExpression(
+                                self.service.fieldName.emailAddresses, u"be",
+                                matchType=MatchType.startsWith
+                            ),
+                        ],
+                        Operand.OR
+                    ),
+                    CompoundExpression(
+                        [
+                            MatchExpression(
+                                self.service.fieldName.fullNames, u"test",
+                                matchType=MatchType.contains
+                            ),
+                            MatchExpression(
+                                self.service.fieldName.emailAddresses, u"test",
+                                matchType=MatchType.startsWith
+                            ),
+                        ],
+                        Operand.OR
+                    ),
+                ],
+                Operand.AND
+            )
+            records = yield self.service.recordsFromExpression(
+                expression, recordTypes=[
+                    self.service.recordType.user,
+                    self.service.recordType.group
+                ]
+            )
+
+            # We should get back users and groups:
+            self.verifyResults(
+                records,
+                [
+                    "odtestbetty", "odtestalbert", "anotherodtestalbert",
+                    "odtestgroupbetty", "odtestgroupalbert"
+                ],
+                ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb"]
+            )
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_compoundWithEmbeddedSingleRecordType(self):
+            expression = CompoundExpression(
+                [
+                    CompoundExpression(
+                        [
                             CompoundExpression(
                                 [
                                     MatchExpression(
@@ -207,19 +317,17 @@
                 ],
                 Operand.AND
             )
-            records = yield self.service.recordsFromExpression(expression)
+            try:
+                records = yield self.service.recordsFromExpression(expression)
+            except QueryNotSupportedError:
+                pass
+            else:
+                self.fail("This should have raised")
 
-            # We should only get users back, not groups:
-            self.verifyResults(
-                records,
-                ["odtestbetty", "odtestalbert", "anotherodtestalbert"],
-                ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb", "odtestgroupbetty", "odtestgroupalbert"]
-            )
 
-
         @onlyIfPopulated
         @inlineCallbacks
-        def test_compoundWithMultipleRecordTypes(self):
+        def test_compoundWithEmbeddedMultipleRecordTypes(self):
             expression = CompoundExpression(
                 [
                     CompoundExpression(
@@ -267,13 +375,135 @@
                 ],
                 Operand.AND
             )
-            records = yield self.service.recordsFromExpression(expression)
 
-            # We should get users and groups back, since we asked for either type:
+            try:
+                records = yield self.service.recordsFromExpression(expression)
+            except QueryNotSupportedError:
+                pass
+            else:
+                self.fail("This should have raised")
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_recordsMatchingTokens(self):
+            self.calService = CalOpenDirectoryService()
+            records = yield self.calService.recordsMatchingTokens([u"be", u"test"])
             self.verifyResults(
                 records,
-                ["odtestbetty", "odtestalbert", "anotherodtestalbert", "odtestgroupbetty", "odtestgroupalbert"],
+                [
+                    "odtestbetty", "odtestalbert", "anotherodtestalbert",
+                    "odtestgroupbetty", "odtestgroupalbert"
+                ],
                 ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb"]
             )
 
-        test_compoundWithMultipleRecordTypes.skip = "This ends up doing a brute force query!"
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_recordsMatchingTokensWithContextUser(self):
+            self.calService = CalOpenDirectoryService()
+            records = yield self.calService.recordsMatchingTokens(
+                [u"be", u"test"],
+                context=self.calService.searchContext_user
+            )
+            self.verifyResults(
+                records,
+                [
+                    "odtestbetty", "odtestalbert", "anotherodtestalbert",
+                ],
+                [
+                    "odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb",
+                    "odtestgroupbetty", "odtestgroupalbert"
+                ]
+            )
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_recordsMatchingTokensWithContextGroup(self):
+            self.calService = CalOpenDirectoryService()
+            records = yield self.calService.recordsMatchingTokens(
+                [u"be", u"test"],
+                context=self.calService.searchContext_group
+            )
+            self.verifyResults(
+                records,
+                [
+                    "odtestgroupbetty", "odtestgroupalbert"
+                ],
+                [
+                    "odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb",
+                    "odtestbetty", "odtestalbert", "anotherodtestalbert"
+                ]
+            )
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_recordsMatchingMultipleFieldsNoRecordType(self):
+            self.calService = CalOpenDirectoryService()
+            fields = (
+                (u"fullNames", u"be", MatchFlags.caseInsensitive, MatchType.contains),
+                (u"fullNames", u"test", MatchFlags.caseInsensitive, MatchType.contains),
+            )
+            records = (yield self.calService.recordsMatchingFields(
+                fields, operand=Operand.AND, recordType=None
+            ))
+            self.verifyResults(
+                records,
+                [
+                    "odtestgroupbetty", "odtestgroupalbert",
+                    "odtestbetty", "odtestalbert", "anotherodtestalbert"
+                ],
+                [
+                    "odtestamanda",
+                ]
+            )
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_recordsMatchingSingleFieldNoRecordType(self):
+            self.calService = CalOpenDirectoryService()
+            fields = (
+                (u"fullNames", u"test", MatchFlags.caseInsensitive, MatchType.contains),
+            )
+            records = (yield self.calService.recordsMatchingFields(
+                fields, operand=Operand.AND, recordType=None
+            ))
+            print("final records", records)
+            self.verifyResults(
+                records,
+                [
+                    "odtestgroupbetty", "odtestgroupalbert",
+                    "odtestbetty", "odtestalbert", "anotherodtestalbert",
+                    "odtestamanda",
+                ],
+                [
+                    "nobody",
+                ]
+            )
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_recordsMatchingFieldsWithRecordType(self):
+            self.calService = CalOpenDirectoryService()
+            fields = (
+                (u"fullNames", u"be", MatchFlags.caseInsensitive, MatchType.contains),
+                (u"fullNames", u"test", MatchFlags.caseInsensitive, MatchType.contains),
+            )
+            records = (yield self.calService.recordsMatchingFields(
+                fields, operand=Operand.AND, recordType=self.calService.recordType.user
+            ))
+            self.verifyResults(
+                records,
+                [
+                    "odtestbetty", "odtestalbert", "anotherodtestalbert"
+                ],
+                [
+                    "odtestamanda", "odtestgroupalbert", "odtestgroupbetty",
+                ]
+            )
+

Modified: CalendarServer/trunk/requirements-stable.txt
===================================================================
--- CalendarServer/trunk/requirements-stable.txt	2014-06-18 21:13:47 UTC (rev 13660)
+++ CalendarServer/trunk/requirements-stable.txt	2014-06-18 21:16:55 UTC (rev 13661)
@@ -5,7 +5,7 @@
 # For CalendarServer development, don't try to get these projects from PyPI; use svn.
 
 -e .
--e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13640#egg=twextpy
+-e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13660#egg=twextpy
 -e svn+http://svn.calendarserver.org/repository/calendarserver/PyKerberos/trunk@13420#egg=kerberos
 -e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@13621#egg=pycalendar
 

Modified: CalendarServer/trunk/txdav/dps/client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/client.py	2014-06-18 21:13:47 UTC (rev 13660)
+++ CalendarServer/trunk/txdav/dps/client.py	2014-06-18 21:16:55 UTC (rev 13661)
@@ -324,7 +324,7 @@
         )
 
 
-    def recordsFromExpression(self, expression):
+    def recordsFromExpression(self, expression, recordTypes=None):
         raise NotImplementedError(
             "This won't work until expressions are serializable to send "
             "across AMP"

Modified: CalendarServer/trunk/txdav/who/augment.py
===================================================================
--- CalendarServer/trunk/txdav/who/augment.py	2014-06-18 21:13:47 UTC (rev 13660)
+++ CalendarServer/trunk/txdav/who/augment.py	2014-06-18 21:16:55 UTC (rev 13661)
@@ -133,8 +133,10 @@
 
 
     @inlineCallbacks
-    def recordsFromExpression(self, expression):
-        records = yield self._directory.recordsFromExpression(expression)
+    def recordsFromExpression(self, expression, recordTypes=None):
+        records = yield self._directory.recordsFromExpression(
+            expression, recordTypes=recordTypes
+        )
         augmented = []
         for record in records:
             record = yield self._augment(record)

Modified: CalendarServer/trunk/txdav/who/delegates.py
===================================================================
--- CalendarServer/trunk/txdav/who/delegates.py	2014-06-18 21:13:47 UTC (rev 13660)
+++ CalendarServer/trunk/txdav/who/delegates.py	2014-06-18 21:16:55 UTC (rev 13661)
@@ -199,7 +199,7 @@
 
 
     @inlineCallbacks
-    def recordsFromExpression(self, expression, records=None):
+    def recordsFromExpression(self, expression, recordTypes=None, records=None):
         """
         It's only ever appropriate to look up delegate group record by
         shortName or uid.  When wrapped by an aggregate directory, looking up

Modified: CalendarServer/trunk/txdav/who/directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/directory.py	2014-06-18 21:13:47 UTC (rev 13660)
+++ CalendarServer/trunk/txdav/who/directory.py	2014-06-18 21:16:55 UTC (rev 13661)
@@ -178,40 +178,17 @@
         results = []
 
         if context is not None:
-            # We're limiting record types, so for each recordType, build a
-            # CompoundExpression that ANDs the original expression with a
-            # typeSpecific one.  Collect all the results from these expressions.
             recordTypes = self.recordTypesForSearchContext(context)
-            log.debug("Tokens: {t}, recordTypes {r}", t=tokens, r=recordTypes)
-            for recordType in recordTypes:
-                typeSpecific = MatchExpression(
-                    self.fieldName.recordType,
-                    recordType,
-                    MatchType.equals,
-                    MatchFlags.none
-                )
-
-                typeSpecific = CompoundExpression(
-                    [expression, typeSpecific],
-                    Operand.AND
-                )
-
-                subResults = yield self.recordsFromExpression(typeSpecific)
-                log.debug(
-                    "Tokens ({t}) matched {n} of {r}",
-                    t=tokens, n=len(subResults), r=recordType
-                )
-                results.extend(subResults)
-
         else:
-            # No record type limits
-            results = yield self.recordsFromExpression(expression)
-            log.debug(
-                "Tokens ({t}) matched {n} records",
-                t=tokens, n=len(results)
-            )
+            recordTypes = None
 
-        log.debug("Tokens ({t}) matched records {r}", t=tokens, r=results)
+        results = yield self.recordsFromExpression(
+            expression, recordTypes=recordTypes
+        )
+        log.debug(
+            "Tokens ({t}) matched {n} records",
+            t=tokens, n=len(results)
+        )
 
         returnValue(results)
 
@@ -255,36 +232,17 @@
             subExpressions.append(subExpression)
 
         if len(subExpressions) == 1:
-            # FIXME: twext.who.opendirectory takes a CompoundExpression and
-            # inspects it for MatchExpressions on recordType, and pulls those
-            # out of the query structure.  However, if all that remains is
-            # essentially a MatchExpression, but we tell OD to use
-            # ODMatchType.compound for it, we get no results back.  Until we
-            # fix twext.who, this workaround keeds the query compound even
-            # when the record type portion is removed:
-            expression = CompoundExpression(
-                [subExpressions[0], subExpressions[0]], operand
-            )
+            expression = subExpressions[0]
         else:
             expression = CompoundExpression(subExpressions, operand)
 
-        # AND in the recordType if passed in
         if recordType is not None:
-            typeExpression = MatchExpression(
-                self.fieldName.recordType,
-                recordType,
-                MatchType.equals,
-                MatchFlags.none
-            )
-            expression = CompoundExpression(
-                [
-                    expression,
-                    typeExpression
-                ],
-                Operand.AND
-            )
-        return self.recordsFromExpression(expression)
+            recordTypes = [recordType]
+        else:
+            recordTypes = None
+        return self.recordsFromExpression(expression, recordTypes=recordTypes)
 
+
     _oldRecordTypeNames = {
         "address": "addresses",
         "group": "groups",

Modified: CalendarServer/trunk/txdav/who/wiki.py
===================================================================
--- CalendarServer/trunk/txdav/who/wiki.py	2014-06-18 21:13:47 UTC (rev 13660)
+++ CalendarServer/trunk/txdav/who/wiki.py	2014-06-18 21:16:55 UTC (rev 13661)
@@ -133,7 +133,7 @@
         return succeed(None)
 
 
-    def recordsFromExpression(self, expression, records=None):
+    def recordsFromExpression(self, expression, recordTypes=None, records=None):
         return succeed(())
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140618/0df6d340/attachment-0001.html>


More information about the calendarserver-changes mailing list