[CalendarServer-changes] [13590] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sun Jun 1 19:10:46 PDT 2014
Revision: 13590
http://trac.calendarserver.org//changeset/13590
Author: gaya at apple.com
Date: 2014-06-01 19:10:46 -0700 (Sun, 01 Jun 2014)
Log Message:
-----------
Use recordsMatchingFields() for directory gateway; enable <feature>directory-gateway</feature> in caldavtester
Modified Paths:
--------------
CalDAVTester/trunk/scripts/server/serverinfo.xml
CalDAVTester/trunk/scripts/tests/CardDAV/reports.xml
CalendarServer/trunk/twistedcaldav/directorybackedaddressbook.py
CalendarServer/trunk/txdav/carddav/datastore/query/filter.py
CalendarServer/trunk/txdav/who/directory.py
CalendarServer/trunk/txdav/who/vcard.py
Added Paths:
-----------
CalendarServer/trunk/calendarserver/
Removed Paths:
-------------
CalendarServer/trunk/calendarserver/
Modified: CalDAVTester/trunk/scripts/server/serverinfo.xml
===================================================================
--- CalDAVTester/trunk/scripts/server/serverinfo.xml 2014-06-02 00:38:06 UTC (rev 13589)
+++ CalDAVTester/trunk/scripts/server/serverinfo.xml 2014-06-02 02:10:46 UTC (rev 13590)
@@ -110,7 +110,7 @@
<feature>carddav</feature> <!-- Basic CardDAV feature enabler -->
<feature>default-addressbook</feature> <!-- Default address book behavior -->
<feature>shared-addressbooks</feature> <!-- Shared address books extension -->
- <!-- <feature>directory-gateway</feature> --> <!-- Directory gateway extension -->
+ <feature>directory-gateway</feature> <!-- Directory gateway extension -->
</features>
Modified: CalDAVTester/trunk/scripts/tests/CardDAV/reports.xml
===================================================================
--- CalDAVTester/trunk/scripts/tests/CardDAV/reports.xml 2014-06-02 00:38:06 UTC (rev 13589)
+++ CalDAVTester/trunk/scripts/tests/CardDAV/reports.xml 2014-06-02 02:10:46 UTC (rev 13590)
@@ -1024,7 +1024,7 @@
</verify>
</request>
</test>
- <test name='3' ignore='no'>
+ <test name='3' ignore='yes'>
<description>query for EMAIL does not contain "b"</description>
<request print-response="no">
<method>REPORT</method>
Modified: CalendarServer/trunk/twistedcaldav/directorybackedaddressbook.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directorybackedaddressbook.py 2014-06-02 00:38:06 UTC (rev 13589)
+++ CalendarServer/trunk/twistedcaldav/directorybackedaddressbook.py 2014-06-02 02:10:46 UTC (rev 13590)
@@ -182,48 +182,63 @@
}
propNames, expression = expressionFromABFilter(
- addressBookFilter, vcardPropToRecordFieldMap, vCardConstantProperties
+ addressBookFilter, vcardPropToRecordFieldMap, vCardConstantProperties,
)
if expression:
- if defaultKind and "KIND" not in propNames:
- defaultRecordExpression = MatchExpression(
- FieldName.recordType,
- vCardKindToRecordTypeMap[defaultKind],
- MatchType.equals
- )
- if expression is True:
- expression = defaultRecordExpression
- else:
- expression = CompoundExpression(
- (expression, defaultRecordExpression,),
- Operand.AND
+
+ # if CompoundExpression of MatchExpression: recordsWithFieldValue() else recordsMatchingType()
+ fields = []
+ if expression is not True:
+
+ def fieldForMatchExpression(match):
+ return (
+ match.fieldName.name,
+ match.fieldValue,
+ match.flags,
+ match.matchType,
)
- elif expression is True: # True means all records
- allowedRecordTypes = set(self.directory.recordTypes()) & set(recordTypeToVCardKindMap.keys())
- expression = CompoundExpression(
- [
- MatchExpression(FieldName.recordType, recordType, MatchType.equals)
- for recordType in allowedRecordTypes
- ], Operand.OR
- )
+ if isinstance(expression, CompoundExpression):
+ operand = expression.operand
+ for match in expression.expressions:
+ if isinstance(match, MatchExpression):
+ if match.fieldName != FieldName.recordType:
+ fields.append(fieldForMatchExpression(match))
+ else:
+ fields = []
+ break
+ elif isinstance(expression, MatchExpression):
+ operand = Operand.OR
+ if expression.fieldName != FieldName.recordType:
+ fields.append(fieldForMatchExpression(expression))
+
maxRecords = int(maxResults * 1.2)
# keep trying query till we get results based on filter. Especially when doing "all results" query
while True:
+ queryLimited = False
log.debug("doAddressBookDirectoryQuery: expression={expression!r}, propNames={propNames}", expression=expression, propNames=propNames)
- records = yield self.directory.recordsFromExpression(expression)
- log.debug("doAddressBookDirectoryQuery: #records={n}, records={records!r}", n=len(records), records=records)
- queryLimited = False
+ allRecords = set()
+ if fields:
+ records = yield self.directory.recordsMatchingFields(fields, operand)
+ log.debug("doAddressBookDirectoryQuery: recordsMatchingFields({f}, {o}): #records={n}, records={records!r}",
+ f=fields, o=operand, n=len(records), records=records)
+ allRecords = set(records)
+ else:
+ for recordType in set(self.directory.recordTypes()) & set(recordTypeToVCardKindMap.keys()):
+ records = yield self.directory.recordsWithRecordType(recordType)
+ log.debug("doAddressBookDirectoryQuery: #records={n}, records={records!r}", n=len(records), records=records)
+ allRecords |= set(records)
- vCardsResults = [(yield ABDirectoryQueryResult(self).generate(record)) for record in records]
+ vCardsResults = [(yield ABDirectoryQueryResult(self).generate(record)) for record in allRecords]
filteredResults = set()
for vCardResult in vCardsResults:
if addressBookFilter.match(vCardResult.vCard()):
+ log.debug("doAddressBookDirectoryQuery: vCard did match filter:\n{vcard}", vcard=vCardResult.vCard())
filteredResults.add(vCardResult)
else:
log.debug("doAddressBookDirectoryQuery: vCard did not match filter:\n{vcard}", vcard=vCardResult.vCard())
@@ -266,9 +281,9 @@
propertyNames = []
if addressBookQuery.qname() == ("DAV:", "prop"):
- for property in addressBookQuery.children:
- if isinstance(property, carddavxml.AddressData):
- for addressProperty in property.children:
+ for prop in addressBookQuery.children:
+ if isinstance(prop, carddavxml.AddressData):
+ for addressProperty in prop.children:
if isinstance(addressProperty, carddavxml.Property):
propertyNames.append(addressProperty.attributes["name"])
@@ -360,7 +375,7 @@
def definedExpression(defined, allOf):
- if constant or propFilter.filter_name in ("N" , "FN", "UID", "SOURCE", "KIND",):
+ if constant or propFilter.filter_name in ("N" , "FN", "UID", "KIND",):
return defined # all records have this property so no records do not have it
else:
# FIXME: The startsWith expression below, which works with LDAP and OD. is not currently supported
@@ -386,11 +401,11 @@
params = vCardPropToParamMap.get(propFilter.filter_name.upper())
defined = params and paramFilterElement.filter_name.upper() in params
- #defined test
+ # defined test
if defined != paramFilterElement.defined:
return False
- #parameter value text match
+ # parameter value text match
if defined and paramFilterElement.filters:
paramValues = params[paramFilterElement.filter_name.upper()]
if paramValues and paramFilterElement.filters[0].text.upper() not in paramValues:
@@ -401,10 +416,10 @@
def textMatchElementExpression(propFilterAllOf, textMatchElement):
- # pre process text match strings for ds query
+ # preprocess text match strings for ds query
def getMatchStrings(propFilter, matchString):
- if propFilter.filter_name in ("REV" , "BDAY",):
+ if propFilter.filter_name in ("REV", "BDAY",):
rawString = matchString
matchString = ""
for c in rawString:
Modified: CalendarServer/trunk/txdav/carddav/datastore/query/filter.py
===================================================================
--- CalendarServer/trunk/txdav/carddav/datastore/query/filter.py 2014-06-02 00:38:06 UTC (rev 13589)
+++ CalendarServer/trunk/txdav/carddav/datastore/query/filter.py 2014-06-02 02:10:46 UTC (rev 13590)
@@ -136,7 +136,7 @@
return not allof
return allof
else:
- return False
+ return True
def valid(self):
@@ -242,8 +242,8 @@
"""
allof = self.propfilter_test == "allof"
- if self.qualifier and allof != self.qualifier.match(item):
- return not allof
+ if self.qualifier and allof and not self.qualifier.match(item):
+ return False
if len(self.filters) > 0:
for filter in self.filters:
Modified: CalendarServer/trunk/txdav/who/directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/directory.py 2014-06-02 00:38:06 UTC (rev 13589)
+++ CalendarServer/trunk/txdav/who/directory.py 2014-06-02 02:10:46 UTC (rev 13590)
@@ -326,19 +326,7 @@
)
- @property
- def calendarUserAddresses(self):
- try:
- if not (
- self.hasCalendars or (
- config.GroupAttendees.Enabled and
- self.recordType == BaseRecordType.group
- )
- ):
- return frozenset()
- except AttributeError:
- pass
-
+ def _calendarAddresses(self):
cuas = set()
# urn:x-uid:
@@ -366,6 +354,22 @@
return frozenset(cuas)
+
+ @property
+ def calendarUserAddresses(self):
+ try:
+ if not (
+ self.hasCalendars or (
+ config.GroupAttendees.Enabled and
+ self.recordType == BaseRecordType.group
+ )
+ ):
+ return frozenset()
+ except AttributeError:
+ pass
+
+ return self._calendarAddresses()
+
# Mapping from directory record.recordType to RFC2445 CUTYPE values
_cuTypes = {
BaseRecordType.user: 'INDIVIDUAL',
@@ -427,7 +431,7 @@
))
- def canonicalCalendarUserAddress(self):
+ def canonicalCalendarUserAddress(self, checkCal=True):
"""
Return a CUA for this record, preferring in this order:
urn:x-uid: form
@@ -437,8 +441,13 @@
first in calendarUserAddresses list (sorted)
"""
- sortedCuas = sorted(self.calendarUserAddresses)
+ if checkCal:
+ cuas = self.calendarUserAddresses
+ else:
+ cuas = self._calendarAddresses()
+ sortedCuas = sorted(cuas)
+
for prefix in (
"urn:x-uid:",
"urn:uuid:",
@@ -450,7 +459,7 @@
return candidate
# fall back to using the first one
- return sortedCuas[0]
+ return sortedCuas[0] if sortedCuas else None # groups may not have cua
def enabledAsOrganizer(self):
Modified: CalendarServer/trunk/txdav/who/vcard.py
===================================================================
--- CalendarServer/trunk/txdav/who/vcard.py 2014-06-02 00:38:06 UTC (rev 13589)
+++ CalendarServer/trunk/txdav/who/vcard.py 2014-06-02 02:10:46 UTC (rev 13590)
@@ -323,8 +323,9 @@
# add members
# FIXME: members() is a deferred, so all of vCardFromRecord is deferred.
for memberRecord in (yield record.members()):
- if memberRecord:
- vcard.addProperty(Property("X-ADDRESSBOOKSERVER-MEMBER", memberRecord.canonicalCalendarUserAddress().encode("utf-8")))
+ cua = memberRecord.canonicalCalendarUserAddress(False)
+ if cua:
+ vcard.addProperty(Property("X-ADDRESSBOOKSERVER-MEMBER", cua.encode("utf-8")))
#===================================================================
# vCard 4.0 http://tools.ietf.org/html/rfc6350
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140601/a38ce8e4/attachment-0001.html>
More information about the calendarserver-changes
mailing list