[CalendarServer-changes] [3543] CalendarServer/trunk/twistedcaldav/directory

source_changes at macosforge.org source_changes at macosforge.org
Wed Dec 17 19:49:15 PST 2008


Revision: 3543
          http://trac.macosforge.org/projects/calendarserver/changeset/3543
Author:   sagen at apple.com
Date:     2008-12-17 19:49:15 -0800 (Wed, 17 Dec 2008)
Log Message:
-----------
principal-property-search now allows searching on calendar-user-address-set in its various forms.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py

Modified: CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2008-12-18 03:39:03 UTC (rev 3542)
+++ CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2008-12-18 03:49:15 UTC (rev 3543)
@@ -349,6 +349,8 @@
         'firstName' : dsattributes.kDS1AttrFirstName,
         'lastName' : dsattributes.kDS1AttrLastName,
         'emailAddresses' : dsattributes.kDSNAttrEMailAddress,
+        'recordName' : dsattributes.kDSNAttrRecordName,
+        'guid' : dsattributes.kDS1AttrGeneratedUID,
     }
 
     _toODRecordTypes = {

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2008-12-18 03:39:03 UTC (rev 3542)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2008-12-18 03:49:15 UTC (rev 3543)
@@ -56,6 +56,7 @@
 from twistedcaldav.log import Logger
 from twistedcaldav import caldavxml, customxml
 from twistedcaldav.directory.wiki import getWikiACL
+from twistedcaldav.scheduling.cuaddress import normalizeCUAddr
 
 log = Logger()
 
@@ -84,6 +85,42 @@
             returnValue(self.defaultAccessControlList())
 
 
+
+# Converter methods for recordsMatchingFields()
+#
+# A DAV property can be associated with one of these converter methods,
+# which take the string being matched and return the appropriate record
+# field name to match against, as well as a new match string which has been
+# converted to the appropriate form.
+
+def cuTypeConverter(cuType):
+    """ Converts calendar user types to OD type names """
+
+    return "recordType", DirectoryRecord.fromCUType(cuType)
+
+def cuAddressConverter(origCUAddr):
+    """ Converts calendar user addresses to OD-compatible form """
+
+    cua = normalizeCUAddr(origCUAddr)
+
+    if cua.startswith("urn:uuid:"):
+        return "guid", cua[9:]
+
+    elif cua.startswith("mailto:"):
+        return "emailAddresses", cua[7:]
+
+    elif cua.startswith("/") or cua.startswith("http"):
+        ignored, collection, id = cua.rsplit("/", 2)
+        if collection == "__uids__":
+            return "guid", id
+        else:
+            return "recordName", id
+
+    else:
+        raise ValueError("Invalid calendar user address format: %s" %
+            (origCUAddr,))
+
+
 class DirectoryProvisioningResource (
     PermissionsMixIn,
     CalendarPrincipalCollectionResource,
@@ -144,8 +181,11 @@
         ("DAV:" , "displayname") :
             ("fullName", None, "Display Name", davxml.DisplayName),
         ("urn:ietf:params:xml:ns:caldav" , "calendar-user-type") :
-            ("recordType", DirectoryRecord.fromCUType, "Calendar User Type",
+            ("", cuTypeConverter, "Calendar User Type",
             caldavxml.CalendarUserType),
+        ("urn:ietf:params:xml:ns:caldav" , "calendar-user-address-set") :
+            ("", cuAddressConverter, "Calendar User Address Set",
+            caldavxml.CalendarUserAddressSet),
         (_cs_ns, "first-name") :
             ("firstName", None, "First Name", customxml.FirstNameProperty),
         (_cs_ns, "last-name") :
@@ -161,11 +201,11 @@
         that field's name, otherwise return None
         """
         field, converter, description, xmlClass = self._fieldMap.get(
-            property.qname(), (None, None, None))
+            property.qname(), (None, None, None, None))
         if field is None:
             return (None, None)
         elif converter is not None:
-            match = converter(match)
+            field, match = converter(match)
         return (field, match)
 
     def principalSearchPropertySet(self):

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py	2008-12-18 03:39:03 UTC (rev 3542)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py	2008-12-18 03:49:15 UTC (rev 3543)
@@ -406,6 +406,42 @@
                 for args in _authReadOnlyPrivileges(self, typeResource, typeResource.principalCollectionURL()):
                     yield self._checkPrivileges(*args)
 
+    def test_propertyToField(self):
+
+        class stubElement(object):
+            def __init__(self, ns, name):
+                self.ns = ns
+                self.name = name
+
+            def qname(self):
+                return self.ns, self.name
+
+        provisioningResource = self.principalRootResources['BasicDirectoryService']
+
+        expected = (
+            ("DAV:", "displayname", "morgen", "fullName", "morgen"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-type", "INDIVIDUAL", "recordType", "users"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-type", "GROUP", "recordType", "groups"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-type", "RESOURCE", "recordType", "resources"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-type", "ROOM", "recordType", "locations"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-address-set", "/principals/__uids__/AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA/", "guid", "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-address-set", "http://example.com:8008/principals/__uids__/AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA/", "guid", "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-address-set", "urn:uuid:AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA", "guid", "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-address-set", "/principals/users/example/", "recordName", "example"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-address-set", "https://example.com:8443/principals/users/example/", "recordName", "example"),
+            ("urn:ietf:params:xml:ns:caldav", "calendar-user-address-set", "mailto:example at example.com", "emailAddresses", "example at example.com"),
+            ("http://calendarserver.org/ns/", "first-name", "morgen", "firstName", "morgen"),
+            ("http://calendarserver.org/ns/", "last-name", "sagen", "lastName", "sagen"),
+            ("http://calendarserver.org/ns/", "email-address-set", "example at example.com", "emailAddresses", "example at example.com"),
+        )
+
+        for ns, property, match, field, converted in expected:
+            el = stubElement(ns, property)
+            self.assertEquals(
+                provisioningResource.propertyToField(el, match),
+                (field, converted)
+            )
+
     def _allRecords(self):
         """
         @return: an iterable of tuples
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081217/7fbbd2e3/attachment.html>


More information about the calendarserver-changes mailing list