[CalendarServer-changes] [13009] CalendarServer/branches/users/sagen/move2who-4/txdav

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 26 20:38:48 PDT 2014


Revision: 13009
          http://trac.calendarserver.org//changeset/13009
Author:   sagen at apple.com
Date:     2014-03-26 20:38:48 -0700 (Wed, 26 Mar 2014)
Log Message:
-----------
Make canonicalCalendarUserAddress less random, more canonical.

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/itip.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_directory.py

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/itip.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/itip.py	2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/itip.py	2014-03-27 03:38:48 UTC (rev 13009)
@@ -951,6 +951,8 @@
     @staticmethod
     def generateAttendeeReply(original, attendee, changedRids=None, force_decline=False):
 
+        print("XYZZY generateAttendeeReply", original, attendee)
+
         # Start with a copy of the original as we may have to modify bits of it
         itip = original.duplicate()
         itip.replaceProperty(Property("PRODID", iCalendarProductID))
@@ -970,6 +972,7 @@
             if component.name() in ignoredComponents:
                 continue
             if not component.getAttendeeProperty((attendee,)):
+                print("XYZZY removing componeont", component, attendee)
                 itip.removeComponent(component)
 
         # No alarms
@@ -1015,6 +1018,7 @@
             if component.name() == "VPOLL":
                 iTipGenerator.generateVPOLLReply(component, attendee)
 
+        print("XYZZY AFTER", itip)
         return itip
 
 

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py	2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py	2014-03-27 03:38:48 UTC (rev 13009)
@@ -322,7 +322,7 @@
 
             # FIXME, how can this be None?
             if attendees is None:
-                print("Attendees is None", self.calendar)
+                print("XYZZY Attendees is None", self.calendar)
 
             # Must have only one
             if len(attendees) != 1:

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py	2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py	2014-03-27 03:38:48 UTC (rev 13009)
@@ -72,21 +72,29 @@
 
 
     def canonicalCalendarUserAddress(self):
-        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
+        """
+            Return a CUA for this record, preferring in this order:
+            urn:uuid: form
+            mailto: form
+            /principals/__uids__/ form
+            first in calendarUserAddresses list (sorted)
+        """
 
+        sortedCuas = sorted(self.calendarUserAddresses)
 
+        for prefix in (
+            "urn:uuid:",
+            "mailto:",
+            "/principals/__uids__/"
+        ):
+            for candidate in sortedCuas:
+                if candidate.startswith(prefix):
+                    return candidate
+
+        # fall back to using the first one
+        return sortedCuas[0]
+
+
     def calendarsEnabled(self):
         return True
 

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py	2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py	2014-03-27 03:38:48 UTC (rev 13009)
@@ -231,8 +231,11 @@
 
     @property
     def calendarUserAddresses(self):
-        if not self.hasCalendars:
-            return frozenset()
+        try:
+            if not self.hasCalendars:
+                return frozenset()
+        except AttributeError:
+            pass
 
         try:
             cuas = set(
@@ -325,24 +328,25 @@
             Return a CUA for this record, preferring in this order:
             urn:uuid: form
             mailto: form
-            first in calendarUserAddresses list
+            /principals/__uids__/ form
+            first in calendarUserAddresses list (sorted)
         """
 
-        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
+        sortedCuas = sorted(self.calendarUserAddresses)
 
+        for prefix in (
+            "urn:uuid:",
+            "mailto:",
+            "/principals/__uids__/"
+        ):
+            for candidate in sortedCuas:
+                if candidate.startswith(prefix):
+                    return candidate
 
+        # fall back to using the first one
+        return sortedCuas[0]
+
+
     def enabledAsOrganizer(self):
         # FIXME:
         from twistedcaldav.config import config

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_directory.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_directory.py	2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_directory.py	2014-03-27 03:38:48 UTC (rev 13009)
@@ -20,8 +20,17 @@
 
 from twisted.internet.defer import inlineCallbacks
 from twistedcaldav.test.util import StoreTestCase
+from twext.who.directory import DirectoryRecord
+from twext.who.idirectory import FieldName, RecordType
+from txdav.who.directory import CalendarDirectoryRecordMixin
+from uuid import UUID
 
 
+
+class TestDirectoryRecord(DirectoryRecord, CalendarDirectoryRecordMixin):
+    pass
+
+
 class DirectoryTestCase(StoreTestCase):
 
     @inlineCallbacks
@@ -40,3 +49,50 @@
             set([u"Chris Lecroy", u"Cyrus Daboo", u"David Reid", u"Wilfredo Sanchez"]),
             set([r.displayName for r in expanded])
         )
+
+
+    def test_canonicalCalendarUserAddress(self):
+
+        record = TestDirectoryRecord(
+            self.directory,
+            {
+                FieldName.uid: u"uid",
+                FieldName.shortNames: [u"name"],
+                FieldName.recordType: RecordType.user,
+            }
+        )
+        self.assertEquals(
+            record.canonicalCalendarUserAddress(),
+            u"/principals/__uids__/uid/"
+        )
+
+
+        record = TestDirectoryRecord(
+            self.directory,
+            {
+                FieldName.uid: u"uid",
+                FieldName.shortNames: [u"name"],
+                FieldName.emailAddresses: [u"test at example.com"],
+                FieldName.recordType: RecordType.user,
+            }
+        )
+        self.assertEquals(
+            record.canonicalCalendarUserAddress(),
+            u"mailto:test at example.com"
+        )
+
+
+        record = TestDirectoryRecord(
+            self.directory,
+            {
+                FieldName.uid: u"uid",
+                FieldName.guid: UUID("E2F6C57F-BB15-4EF9-B0AC-47A7578386F1"),
+                FieldName.shortNames: [u"name"],
+                FieldName.emailAddresses: [u"test at example.com"],
+                FieldName.recordType: RecordType.user,
+            }
+        )
+        self.assertEquals(
+            record.canonicalCalendarUserAddress(),
+            u"urn:uuid:E2F6C57F-BB15-4EF9-B0AC-47A7578386F1"
+        )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140326/5359c329/attachment.html>


More information about the calendarserver-changes mailing list