[CalendarServer-changes] [7654] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 23 19:00:13 PDT 2011


Revision: 7654
          http://trac.macosforge.org/projects/calendarserver/changeset/7654
Author:   sagen at apple.com
Date:     2011-06-23 19:00:12 -0700 (Thu, 23 Jun 2011)
Log Message:
-----------
Adds principal.canonicalCalendarUserAddress( ) so the mail gateway tokens db will consistently use the urn:uuid: form of CUAs (9641872)

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py
    CalendarServer/trunk/twistedcaldav/scheduling/implicit.py
    CalendarServer/trunk/twistedcaldav/scheduling/scheduler.py

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2011-06-23 23:54:01 UTC (rev 7653)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2011-06-24 02:00:12 UTC (rev 7654)
@@ -869,6 +869,29 @@
 
         return addresses
 
+    def canonicalCalendarUserAddress(self):
+        """
+        Return a CUA for this principal, preferring in this order:
+            urn:uuid: form
+            mailto: form
+            first in calendarUserAddresses( ) list
+        """
+
+        cua = ""
+        for candidate in self.calendarUserAddresses():
+            # Pick the first one, but urn:uuid: and mailto: can override
+            if not cua:
+                cua = candidate
+            # But always immediately choose the urn:uuid: form
+            if candidate.startswith("urn:uuid:"):
+                cua = candidate
+                break
+            # Prefer mailto: if no urn:uuid:
+            elif candidate.startswith("mailto:"):
+                cua = candidate
+        return cua
+
+
     def enabledAsOrganizer(self):
         if self.record.recordType == DirectoryService.recordType_users:
             return True

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py	2011-06-23 23:54:01 UTC (rev 7653)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py	2011-06-24 02:00:12 UTC (rev 7654)
@@ -431,6 +431,14 @@
                 record.enabledForCalendaring = False
                 self.failIf(recordResource.calendarUserAddresses())
 
+    def test_canonicalCalendarUserAddress(self):
+        """
+        DirectoryPrincipalResource.canonicalCalendarUserAddress()
+        """
+        for provisioningResource, recordType, recordResource, record in self._allRecords():
+            if record.enabledForCalendaring:
+                self.failUnless(recordResource.canonicalCalendarUserAddress().startswith("urn:uuid:"))
+
     def test_addressBookHomeURLs(self):
         """
         DirectoryPrincipalResource.addressBookHomeURLs(),

Modified: CalendarServer/trunk/twistedcaldav/scheduling/implicit.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/scheduling/implicit.py	2011-06-23 23:54:01 UTC (rev 7653)
+++ CalendarServer/trunk/twistedcaldav/scheduling/implicit.py	2011-06-24 02:00:12 UTC (rev 7654)
@@ -336,15 +336,10 @@
                     (caldav_namespace, "invalid-originator"),
                     "Originator not enabled",
                 ))
-    
-            # Pick the first mailto cu address or the first other type
-            for item in self.originatorPrincipal.calendarUserAddresses():
-                if not self.originator:
-                    self.originator = item
-                if item.startswith("mailto:"):
-                    self.originator = item
-                    break
 
+            # Pick the canonical CUA:
+            self.originator = self.originatorPrincipal.canonicalCalendarUserAddress()
+
         # Get the ORGANIZER and verify it is the same for all components
         try:
             self.organizer = self.calendar.validOrganizerForScheduling()

Modified: CalendarServer/trunk/twistedcaldav/scheduling/scheduler.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/scheduling/scheduler.py	2011-06-23 23:54:01 UTC (rev 7653)
+++ CalendarServer/trunk/twistedcaldav/scheduling/scheduler.py	2011-06-24 02:00:12 UTC (rev 7654)
@@ -1,4 +1,4 @@
-##
+
 # Copyright (c) 2005-2010 Apple Inc. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -173,13 +173,8 @@
             if originatorPrincipalURL:
                 originatorPrincipal = (yield self.request.locateResource(originatorPrincipalURL))
                 if originatorPrincipal:
-                    # Pick the first mailto cu address or the first other type
-                    for item in originatorPrincipal.calendarUserAddresses():
-                        if not originator:
-                            originator = item
-                        if item.startswith("mailto:"):
-                            originator = item
-                            break
+                    # Pick the canonical CUA:
+                    self.originator = self.originatorPrincipal.canonicalCalendarUserAddress()
 
         if not originator:
             log.err("%s request must have Originator" % (self.method,))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110623/975712a1/attachment.html>


More information about the calendarserver-changes mailing list