[CalendarServer-changes] [1217] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 20 09:48:15 PST 2007


Revision: 1217
          http://trac.macosforge.org/projects/calendarserver/changeset/1217
Author:   cdaboo at apple.com
Date:     2007-02-20 09:48:14 -0800 (Tue, 20 Feb 2007)

Log Message:
-----------
Make sure we use the "base" ports for the service when forming absolute prinicpalURIs. Clean-up the ability
to turn off schema integration. No longer use schema templates for calendar user addresses.

Modified Paths:
--------------
    CalendarServer/trunk/conf/caldavd-test-logged.plist
    CalendarServer/trunk/conf/caldavd-test.plist
    CalendarServer/trunk/conf/caldavd.plist
    CalendarServer/trunk/twistedcaldav/config.py
    CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/directory/test/test_opendirectoryschema.py

Modified: CalendarServer/trunk/conf/caldavd-test-logged.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-test-logged.plist	2007-02-20 16:27:54 UTC (rev 1216)
+++ CalendarServer/trunk/conf/caldavd-test-logged.plist	2007-02-20 17:48:14 UTC (rev 1217)
@@ -40,9 +40,15 @@
   <key>Port</key>
   <integer>8008</integer>
 
+  <key>BasePort</key>
+  <integer>8008</integer>
+
   <key>SSLPort</key>
   <integer>8443</integer>
 
+  <key>BaseSSLPort</key>
+  <integer>8443</integer>
+
   <key>SSLEnable</key>
   <true/>
 
@@ -91,8 +97,8 @@
     <dict>
       <key>node</key>
       <string>/Search</string>
-      <key>allUsers</key>
-      <false/>
+      <key>useFullSchema</key>
+      <true/>
     </dict>
   </dict>
   -->

Modified: CalendarServer/trunk/conf/caldavd-test.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-test.plist	2007-02-20 16:27:54 UTC (rev 1216)
+++ CalendarServer/trunk/conf/caldavd-test.plist	2007-02-20 17:48:14 UTC (rev 1217)
@@ -40,9 +40,15 @@
   <key>Port</key>
   <integer>8008</integer>
 
+  <key>BasePort</key>
+  <integer>8008</integer>
+
   <key>SSLPort</key>
   <integer>8443</integer>
 
+  <key>BaseSSLPort</key>
+  <integer>8443</integer>
+
   <key>SSLEnable</key>
   <true/>
 
@@ -97,8 +103,8 @@
     <dict>
       <key>node</key>
       <string>/Search</string>
-      <key>allUsers</key>
-      <false/>
+      <key>useFullSchema</key>
+      <true/>
     </dict>
   </dict>
   -->

Modified: CalendarServer/trunk/conf/caldavd.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd.plist	2007-02-20 16:27:54 UTC (rev 1216)
+++ CalendarServer/trunk/conf/caldavd.plist	2007-02-20 17:48:14 UTC (rev 1217)
@@ -45,9 +45,15 @@
   <key>Port</key>
   <integer>8008</integer>
 
+  <key>BasePort</key>
+  <integer>8008</integer>
+
   <key>SSLPort</key>
   <integer>8443</integer>
 
+  <key>BaseSSLPort</key>
+  <integer>8443</integer>
+
   <key>SSLEnable</key>
   <true/>
 
@@ -97,8 +103,8 @@
     <dict>
       <key>node</key>
       <string>/Search</string>
-      <key>allUsers</key>
-      <false/>
+      <key>useFullSchema</key>
+      <true/>
     </dict>
   </dict>
   

Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py	2007-02-20 16:27:54 UTC (rev 1216)
+++ CalendarServer/trunk/twistedcaldav/config.py	2007-02-20 17:48:14 UTC (rev 1217)
@@ -23,10 +23,12 @@
 defaultConfigFile = '/etc/caldavd/caldavd.plist'
 
 defaultConfig = {
+    'BasePort': 8008,
+    'BaseSSLPort': 8443,
     'BindAddress': [],
     'CalendarUserProxyEnabled': True,
     'DirectoryService': {
-        'params': {'node': '/Search'},
+        'params': {'node': '/Search', 'useFullSchema': True},
         'type': 'twistedcaldav.directory.appleopendirectory.OpenDirectoryService'
     },
     'DocumentRoot': '/Library/CalendarServer/Documents',

Modified: CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2007-02-20 16:27:54 UTC (rev 1216)
+++ CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2007-02-20 17:48:14 UTC (rev 1217)
@@ -52,9 +52,11 @@
     def __repr__(self):
         return "<%s %r: %r>" % (self.__class__.__name__, self.realmName, self.node)
 
-    def __init__(self, node="/Search", allUsers=False, dosetup=True):
+    def __init__(self, node="/Search", useFullSchema=True, dosetup=True):
         """
         @param node: an OpenDirectory node name to bind to.
+        @param useFullSchema: C{True} if the directory schema is to be used to determine
+            which calendar users are enabled.
         @param dosetup: if C{True} then the directory records are initialized,
                         if C{False} they are not.
                         This should only be set to C{False} when doing unit tests.
@@ -68,17 +70,18 @@
         self.realmName = node
         self.directory = directory
         self.node = node
-        self.allUsers = allUsers
+        self.useFullSchema = useFullSchema
         self.computerRecordName = ""
         self._records = {}
         self._delayedCalls = set()
 
         if dosetup:
-            try:
-                self._lookupVHostRecord()
-            except Exception, e:
-                log.err("Unable to locate virtual host record: %s" % (e,))
-                raise
+            if self.useFullSchema:
+                try:
+                    self._lookupVHostRecord()
+                except Exception, e:
+                    log.err("Unable to locate virtual host record: %s" % (e,))
+                    raise
 
             for recordType in self.recordTypes():
                 self.recordsForType(recordType)
@@ -221,11 +224,10 @@
                 % (self.realmName, recordname)
             )
             return False
-        self.hostvariants = []
+        hostvariants = []
         for key, value in hostdetails.iteritems():
             if key in ("http", "https"):
-                self.hostvariants.append((key, hostname, value["port"]))
-        self.hostvariants = tuple(self.hostvariants)
+                hostvariants.append((key, hostname, value["port"]))
         
         # Look at the service data
         serviceInfos = vhosts[hostguid].get("serviceInfo", None)
@@ -247,85 +249,33 @@
                 % (self.realmName, recordname)
             )
             return False
-        
-        # Get useful templates
-        templates = serviceInfo.get("templates", None)
-        if not templates or not templates.has_key("calendarUserAddresses"):
-            log.msg(
-                "Open Directory (node=%s) /Computers/%s record does not have a "
-                "template for calendar user addresses in its XMLPlist attribute value"
-                % (self.realmName, recordname)
-            )
-            return False
-        
-        self.computerRecordName = recordname
 
-        # Grab the templates we need for calendar user addresses
-        self.cuaddrtemplates = tuple(templates["calendarUserAddresses"])
-        
         # Create the string we will use to match users with accounts on this server
         self.servicetag = "%s:%s:calendar" % (recordguid, hostguid)
         
+        self.computerRecordName = recordname
+        
         return True
     
-    def _templateExpandCalendarUserAddresses(self, recordType, recordName, record):
+    def _getCalendarUserAddresses(self, recordType, recordName, record):
         """
-        Expand this services calendar user address templates for the specified record.
+        Extract specific attributes from the directory record for use as calendar user address.
         
         @param recordName: a C{str} containing the record name being operated on.
         @param record: a C{dict} containing the attributes retrieved from the directory.
         @return: a C{set} of C{str} for each expanded calendar user address.
         """
         
-        # Make a dict of the substitutions we can do for this record. The only record parameters
-        # we substitute are name, guid and email. Note that email is multi-valued so we have to
-        # create a list of dicts for each one of those.
-        name = recordName
-        type = recordType
-        guid = record.get(dsattributes.kDS1AttrGeneratedUID)
+        # Now get the addresses
+        result = set()
+        
+        # Add each email address as a mailto URI
         emails = record.get(dsattributes.kDSNAttrEMailAddress)
-        if emails is not None and isinstance(emails, str):
-            emails = [emails]
-            
-        subslist = []
-        if emails:
+        if emails is not None:
+            if isinstance(emails, str):
+                emails = [emails]
             for email in emails:
-                subslist.append({
-                    "name"  : name,
-                    "type"  : type,
-                    "guid"  : guid,
-                    "email" : email,
-                })
-        else:
-            subslist.append({
-                "name"  : name,
-                "type"  : type,
-                "guid"  : guid,
-            })
-        
-        # Now do substitutions    
-        result = set()
-        for template in self.cuaddrtemplates:
-            
-            # Ignore %(principaluri)s templates as we already default to adding those
-            if template.find("%(principaluri)s") != -1:
-                continue
-
-            # Loop over each host variant
-            for scheme, hostname, port in self.hostvariants:
-                for subs in subslist:
-                    # Add in host substitution values
-                    subs.update({
-                        "scheme"   : scheme,
-                        "hostname" : hostname,
-                        "port"     : port,
-                    })
-                    
-                    # Special check for no email address for this record
-                    if (template.find("%(email)s") != -1) and not emails:
-                        continue
-
-                    result.add(template % subs)
+                result.add("mailto:%s" % (email,))
                 
         return result
 
@@ -347,10 +297,6 @@
         def reloadCache():
             log.msg("Reloading %s record cache" % (recordType,))
 
-            query = {
-                dsattributes.kDSNAttrServicesLocator: self.servicetag,
-            }
-    
             attrs = [
                 dsattributes.kDS1AttrGeneratedUID,
                 dsattributes.kDS1AttrDistinguishedName,
@@ -374,12 +320,10 @@
             records = {}
 
             try:
-                if self.allUsers:
-                    results = opendirectory.listAllRecordsWithAttributes(
-                        self.directory,
-                        listRecordType,
-                        attrs)
-                else:
+                if self.useFullSchema:
+                    query = {
+                        dsattributes.kDSNAttrServicesLocator: self.servicetag,
+                    }
                     results = opendirectory.queryRecordsWithAttributes(
                         self.directory,
                         query,
@@ -388,12 +332,17 @@
                         False,
                         listRecordType,
                         attrs)
+                else:
+                    results = opendirectory.listAllRecordsWithAttributes(
+                        self.directory,
+                        listRecordType,
+                        attrs)
             except opendirectory.ODError, ex:
                 log.msg("Open Directory (node=%s) error: %s" % (self.realmName, str(ex)))
                 raise
 
             for (key, value) in results.iteritems():
-                if not self.allUsers:
+                if self.useFullSchema:
 	                # Make sure this user has service enabled.
                     enabled = True
                     service = value.get(dsattributes.kDSNAttrServicesLocator)
@@ -414,8 +363,8 @@
                     continue
                 realName = value.get(dsattributes.kDS1AttrDistinguishedName)
 
-                # Get calendar user addresses expanded from service record templates.
-                cuaddrset = self._templateExpandCalendarUserAddresses(recordType, key, value)
+                # Get calendar user addresses from directory record.
+                cuaddrset = self._getCalendarUserAddresses(recordType, key, value)
 
                 # Special case for groups.
                 if recordType == DirectoryService.recordType_groups:

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2007-02-20 16:27:54 UTC (rev 1216)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2007-02-20 17:48:14 UTC (rev 1217)
@@ -439,14 +439,15 @@
         return self.record.guid
         
     def calendarUserAddresses(self):
-        # Add the principal URL to whatever calendar user addresses
+        # Add the principal URL and GUID to whatever calendar user addresses
         # the directory record provides.
         addresses = set(self.record.calendarUserAddresses)
         addresses.add(self.principalURL())
         if not config.SSLOnly:
-            addresses.add("http://%s:%s%s" % (config.ServerHostName, config.Port, self.principalURL(),))
+            addresses.add("http://%s:%s%s" % (config.ServerHostName, config.BasePort, self.principalURL(),))
         if config.SSLEnable:
-            addresses.add("https://%s:%s%s" % (config.ServerHostName, config.SSLPort, self.principalURL(),))
+            addresses.add("https://%s:%s%s" % (config.ServerHostName, config.BaseSSLPort, self.principalURL(),))
+        addresses.add("urn:uuid:%s" % (self.principalUID(),))
         
         return addresses
 

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_opendirectoryschema.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_opendirectoryschema.py	2007-02-20 16:27:54 UTC (rev 1216)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_opendirectoryschema.py	2007-02-20 17:48:14 UTC (rev 1217)
@@ -579,121 +579,6 @@
 </plist>
 """
 
-        plist_nocuaddrtemplates = """<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-    <dict>
-        <key>ReplicaName</key>
-        <string>Master</string>
-
-        <key>com.apple.od.role</key>
-        <string>master</string>
-
-        <key>com.apple.macosxserver.virtualhosts</key>
-        <dict>
-            <key>4F088107-51FD-4DE5-904D-2C0AD9C6C893</key>
-            <dict>
-                <key>hostname</key>
-                <string>foo.apple.com</string>
-
-                <key>hostDetails</key>
-                <dict>
-                    <key>access</key>
-                    <dict>
-                        <key>somethingorother</key>
-                        <string>somethingelse</string>
-                    </dict>
-                    <key>http</key>
-                    <dict>
-                        <key>port</key>
-                        <integer>80</integer>
-                    </dict>
-                    <key>https</key>
-                    <dict>
-                        <key>port</key>
-                        <string>443</string>
-                    </dict>
-                </dict>
-
-                <key>serviceType</key>
-                <array>
-                    <string>wiki</string>
-                    <string>webCalendar</string>
-                    <string>webMailingList</string>
-                </array>
-
-                <key>serviceInfo</key>
-                <dict>
-                    <key>webCalendar</key>
-                    <dict>
-                        <key>enabled</key>
-                        <true/>
-                        <key>urlMask</key>
-                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(name)s/webcalendar</string>
-                    </dict>
-                    <key>wiki</key>
-                    <dict>
-                        <key>enabled</key>
-                        <true/>
-                        <key>urlMask</key>
-                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(name)s/wiki</string>
-                    </dict>
-                    <key>webMailingList</key>
-                    <dict>
-                        <key>enabled</key>
-                        <true/>
-                        <key>urlMask</key>
-                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(name)s/mailinglist</string>
-                    </dict>
-                </dict>
-            </dict>
-            
-            <key>C18C34AC-3D9E-403C-8A33-BFC303F3840E</key>
-            <dict>
-                <key>hostname</key>
-                <string>calendar.apple.com</string>
-
-                <key>hostDetails</key>
-                <dict>
-                    <key>access</key>
-                    <dict>
-                        <key>somethingorother</key>
-                        <string>somethingelse</string>
-                    </dict>
-                    <key>http</key>
-                    <dict>
-                        <key>port</key>
-                        <integer>8008</integer>
-                    </dict>
-                    <key>https</key>
-                    <dict>
-                        <key>port</key>
-                        <integer>8443</integer>
-                    </dict>
-                </dict>
-
-                <key>serviceType</key>
-                <array>
-                    <string>calendar</string>
-                </array>
-
-                <key>serviceInfo</key>
-                <dict>
-                    <key>calendar</key>
-                    <dict>
-                        <key>templates</key>
-                        <dict>
-                            <key>principalPath</key>
-                            <string>/principals/%(type)s/%(name)s</string>
-                        </dict>
-                    </dict>
-                </dict>
-            </dict>
-
-        </dict>
-    </dict>
-</plist>
-"""
         plist_good = """<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
@@ -951,7 +836,6 @@
                 (PlistParse.plist_disabledservice,    "disabledservice"),
                 (PlistParse.plist_nohostname,         "nohostname"),
                 (PlistParse.plist_nohostdetails,      "nohostdetails"),
-                (PlistParse.plist_nocuaddrtemplates,  "nocuaddrtemplates"),
             )
             for plist, title in plists:
                 _doParse(plist, title)
@@ -963,8 +847,6 @@
             else:
                 # Verify that we extracted the proper items
                 self.assertEqual(service.servicetag, "GUIDIFY:C18C34AC-3D9E-403C-8A33-BFC303F3840E:calendar")
-                self.assertEqual(service.hostvariants, (("http", "calendar.apple.com", 8008), ("https", "calendar.apple.com", 8443)))
-                self.assertEqual(service.cuaddrtemplates, ("%(scheme)s://%(hostname)s:%(port)s/principals/%(type)s/%(name)s", "mailto:%(email)s", "urn:uuid:%(guid)s"))
 
         def test_expandcuaddrs(self):
             def _doTest(recordName, record, result, title):
@@ -972,7 +854,7 @@
                 if not service._parseXMLPlist("calendar.apple.com", recordName, PlistParse.plist_good, "GUIDIFY"):
                     self.fail(msg="Plist parse should not have failed: %s" % (recordName,))
                 else:
-                    expanded = service._templateExpandCalendarUserAddresses(DirectoryService.recordType_users, recordName, record)
+                    expanded = service._getCalendarUserAddresses(DirectoryService.recordType_users, recordName, record)
         
                     # Verify that we extracted the proper items
                     self.assertEqual(expanded, result, msg=title % (expanded, result,))
@@ -985,10 +867,7 @@
                     dsattributes.kDSNAttrEMailAddress: "user01 at example.com",
                  },
                  set((
-                    "http://calendar.apple.com:8008/principals/users/user01",
-                    "https://calendar.apple.com:8443/principals/users/user01",
                     "mailto:user01 at example.com",
-                    "urn:uuid:GUID-USER-01",
                  )),
                  "User with one email address, %s != %s",
                 ),
@@ -999,11 +878,8 @@
                     dsattributes.kDSNAttrEMailAddress: ["user02 at example.com", "user02 at calendar.example.com"],
                  },
                  set((
-                    "http://calendar.apple.com:8008/principals/users/user02",
-                    "https://calendar.apple.com:8443/principals/users/user02",
                     "mailto:user02 at example.com",
                     "mailto:user02 at calendar.example.com",
-                    "urn:uuid:GUID-USER-02",
                  )),
                  "User with multiple email addresses, %s != %s",
                 ),
@@ -1012,11 +888,7 @@
                  {
                     dsattributes.kDS1AttrGeneratedUID: "GUID-USER-03",
                  },
-                 set((
-                    "http://calendar.apple.com:8008/principals/users/user03",
-                    "https://calendar.apple.com:8443/principals/users/user03",
-                    "urn:uuid:GUID-USER-03",
-                 )),
+                 set(()),
                  "User with no email addresses, %s != %s",
                 ),
             )

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070220/297658c0/attachment.html


More information about the calendarserver-changes mailing list