<!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>[13653] CalendarServer/branches/users/sagen/recordtypes</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/13653">13653</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-06-18 13:27:26 -0700 (Wed, 18 Jun 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Removing some hacks because we can now pass recordTypes directly to recordsFromExpression</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenrecordtypescontribodtesttest_livepy">CalendarServer/branches/users/sagen/recordtypes/contrib/od/test/test_live.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenrecordtypesrequirementsstabletxt">CalendarServer/branches/users/sagen/recordtypes/requirements-stable.txt</a></li>
<li><a href="#CalendarServerbranchesuserssagenrecordtypestxdavwhodirectorypy">CalendarServer/branches/users/sagen/recordtypes/txdav/who/directory.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagenrecordtypescontribodtesttest_livepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/recordtypes/contrib/od/test/test_live.py (13652 => 13653)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/recordtypes/contrib/od/test/test_live.py        2014-06-18 20:26:18 UTC (rev 13652)
+++ CalendarServer/branches/users/sagen/recordtypes/contrib/od/test/test_live.py        2014-06-18 20:27:26 UTC (rev 13653)
</span><span class="lines">@@ -40,7 +40,16 @@
</span><span class="cx"> from twext.who.expression import (
</span><span class="cx"> CompoundExpression, Operand, MatchExpression, MatchType
</span><span class="cx"> )
</span><ins>+ 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
+ )
</ins><span class="cx">
</span><ins>+ class CalOpenDirectoryService(OpenDirectoryService, CalendarDirectoryServiceMixin):
+ pass
+
</ins><span class="cx"> LOCAL_SHORTNAMES = "odtestalbert odtestbill odtestcarl odtestdavid odtestsubgroupa".split()
</span><span class="cx"> NETWORK_SHORTNAMES = "odtestamanda odtestbetty odtestcarlene odtestdenise odtestsubgroupb odtestgrouptop".split()
</span><span class="cx">
</span><span class="lines">@@ -160,18 +169,119 @@
</span><span class="cx"> # We should get back users and groups since we did not specify a type:
</span><span class="cx"> self.verifyResults(
</span><span class="cx"> records,
</span><del>- ["odtestbetty", "odtestalbert", "anotherodtestalbert", "odtestgroupbetty", "odtestgroupalbert"],
</del><ins>+ [
+ "odtestbetty", "odtestalbert", "anotherodtestalbert",
+ "odtestgroupbetty", "odtestgroupalbert"
+ ],
</ins><span class="cx"> ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb"]
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @onlyIfPopulated
</span><span class="cx"> @inlineCallbacks
</span><del>- def test_compoundWithSingleRecordType(self):
</del><ins>+ def test_compoundWithExplicitRecordType(self):
</ins><span class="cx"> expression = CompoundExpression(
</span><span class="cx"> [
</span><span class="cx"> CompoundExpression(
</span><span class="cx"> [
</span><ins>+ 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(
+ [
</ins><span class="cx"> CompoundExpression(
</span><span class="cx"> [
</span><span class="cx"> MatchExpression(
</span><span class="lines">@@ -207,19 +317,17 @@
</span><span class="cx"> ],
</span><span class="cx"> Operand.AND
</span><span class="cx"> )
</span><del>- records = yield self.service.recordsFromExpression(expression)
</del><ins>+ try:
+ records = yield self.service.recordsFromExpression(expression)
+ except QueryNotSupportedError:
+ pass
+ else:
+ self.fail("This should have raised")
</ins><span class="cx">
</span><del>- # We should only get users back, not groups:
- self.verifyResults(
- records,
- ["odtestbetty", "odtestalbert", "anotherodtestalbert"],
- ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb", "odtestgroupbetty", "odtestgroupalbert"]
- )
</del><span class="cx">
</span><del>-
</del><span class="cx"> @onlyIfPopulated
</span><span class="cx"> @inlineCallbacks
</span><del>- def test_compoundWithMultipleRecordTypes(self):
</del><ins>+ def test_compoundWithEmbeddedMultipleRecordTypes(self):
</ins><span class="cx"> expression = CompoundExpression(
</span><span class="cx"> [
</span><span class="cx"> CompoundExpression(
</span><span class="lines">@@ -267,13 +375,111 @@
</span><span class="cx"> ],
</span><span class="cx"> Operand.AND
</span><span class="cx"> )
</span><del>- records = yield self.service.recordsFromExpression(expression)
</del><span class="cx">
</span><del>- # We should get users and groups back, since we asked for either type:
</del><ins>+ 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"])
</ins><span class="cx"> self.verifyResults(
</span><span class="cx"> records,
</span><del>- ["odtestbetty", "odtestalbert", "anotherodtestalbert", "odtestgroupbetty", "odtestgroupalbert"],
</del><ins>+ [
+ "odtestbetty", "odtestalbert", "anotherodtestalbert",
+ "odtestgroupbetty", "odtestgroupalbert"
+ ],
</ins><span class="cx"> ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb"]
</span><span class="cx"> )
</span><span class="cx">
</span><del>- test_compoundWithMultipleRecordTypes.skip = "This ends up doing a brute force query!"
</del><ins>+
+ @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_recordsMatchingFieldsNoRecordType(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_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",
+ ]
+ )
+
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenrecordtypesrequirementsstabletxt"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/recordtypes/requirements-stable.txt (13652 => 13653)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/recordtypes/requirements-stable.txt        2014-06-18 20:26:18 UTC (rev 13652)
+++ CalendarServer/branches/users/sagen/recordtypes/requirements-stable.txt        2014-06-18 20:27:26 UTC (rev 13653)
</span><span class="lines">@@ -5,7 +5,7 @@
</span><span class="cx"> # For CalendarServer development, don't try to get these projects from PyPI; use svn.
</span><span class="cx">
</span><span class="cx"> -e .
</span><del>--e svn+http://svn.calendarserver.org/repository/calendarserver/twext/branches/users/sagen/recordtypes@13649#egg=twextpy
</del><ins>+-e svn+http://svn.calendarserver.org/repository/calendarserver/twext/branches/users/sagen/recordtypes@13652#egg=twextpy
</ins><span class="cx"> -e svn+http://svn.calendarserver.org/repository/calendarserver/PyKerberos/trunk@13420#egg=kerberos
</span><span class="cx"> -e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@13621#egg=pycalendar
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenrecordtypestxdavwhodirectorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/recordtypes/txdav/who/directory.py (13652 => 13653)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/recordtypes/txdav/who/directory.py        2014-06-18 20:26:18 UTC (rev 13652)
+++ CalendarServer/branches/users/sagen/recordtypes/txdav/who/directory.py        2014-06-18 20:27:26 UTC (rev 13653)
</span><span class="lines">@@ -182,36 +182,16 @@
</span><span class="cx"> # CompoundExpression that ANDs the original expression with a
</span><span class="cx"> # typeSpecific one. Collect all the results from these expressions.
</span><span class="cx"> recordTypes = self.recordTypesForSearchContext(context)
</span><del>- 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)
-
</del><span class="cx"> else:
</span><del>- # No record type limits
- results = yield self.recordsFromExpression(expression)
- log.debug(
- "Tokens ({t}) matched {n} records",
- t=tokens, n=len(results)
- )
</del><ins>+ recordTypes = None
</ins><span class="cx">
</span><del>- log.debug("Tokens ({t}) matched records {r}", t=tokens, r=results)
</del><ins>+ results = yield self.recordsFromExpression(
+ expression, recordTypes=recordTypes
+ )
+ log.debug(
+ "Tokens ({t}) matched {n} records",
+ t=tokens, n=len(results)
+ )
</ins><span class="cx">
</span><span class="cx"> returnValue(results)
</span><span class="cx">
</span><span class="lines">@@ -254,37 +234,15 @@
</span><span class="cx"> )
</span><span class="cx"> subExpressions.append(subExpression)
</span><span class="cx">
</span><del>- 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
- )
- else:
- expression = CompoundExpression(subExpressions, operand)
</del><ins>+ expression = CompoundExpression(subExpressions, operand)
</ins><span class="cx">
</span><del>- # AND in the recordType if passed in
</del><span class="cx"> if recordType is not None:
</span><del>- typeExpression = MatchExpression(
- self.fieldName.recordType,
- recordType,
- MatchType.equals,
- MatchFlags.none
- )
- expression = CompoundExpression(
- [
- expression,
- typeExpression
- ],
- Operand.AND
- )
- return self.recordsFromExpression(expression)
</del><ins>+ recordTypes = [recordType]
+ else:
+ recordTypes = None
+ return self.recordsFromExpression(expression, recordTypes=recordTypes)
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> _oldRecordTypeNames = {
</span><span class="cx"> "address": "addresses",
</span><span class="cx"> "group": "groups",
</span></span></pre>
</div>
</div>
</body>
</html>