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

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 21 08:41:05 PST 2012


Revision: 8734
          http://trac.macosforge.org/projects/calendarserver/changeset/8734
Author:   sagen at apple.com
Date:     2012-02-21 08:41:03 -0800 (Tue, 21 Feb 2012)
Log Message:
-----------
When normalizing CUAs to UUID form, http(s) CUAs are tucked away into a parameter, and restored when normalizing to non-UUID form.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/ical.py
    CalendarServer/trunk/twistedcaldav/test/test_icalendar.py

Modified: CalendarServer/trunk/twistedcaldav/ical.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/ical.py	2012-02-21 03:09:34 UTC (rev 8733)
+++ CalendarServer/trunk/twistedcaldav/ical.py	2012-02-21 16:41:03 UTC (rev 8734)
@@ -2537,12 +2537,24 @@
                     oldemail = "mailto:%s" % (oldemail,)
 
                 if toUUID:
+                    # Store the original CUA if http(s):
+                    if cuaddr.startswith("http"):
+                        prop.setParameter("CALENDARSERVER-OLD-CUA",
+                            prop.value())
+
                     # Always re-write value to urn:uuid
                     prop.setValue("urn:uuid:%s" % (guid,))
 
                 # If it is already a non-UUID address leave it be
                 elif cuaddr.startswith("urn:uuid:"):
-                    if oldemail:
+
+                    # Restore old CUA
+                    oldExternalCUA = prop.parameterValue("CALENDARSERVER-OLD-CUA")
+                    if oldExternalCUA:
+                        newaddr = oldExternalCUA
+                        prop.removeParameterValue("CALENDARSERVER-OLD-CUA",
+                            oldExternalCUA)
+                    elif oldemail:
                         # Use the EMAIL parameter if it exists
                         newaddr = oldemail
                     else:

Modified: CalendarServer/trunk/twistedcaldav/test/test_icalendar.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_icalendar.py	2012-02-21 03:09:34 UTC (rev 8733)
+++ CalendarServer/trunk/twistedcaldav/test/test_icalendar.py	2012-02-21 16:41:03 UTC (rev 8734)
@@ -5977,9 +5977,10 @@
             self.assertEquals(expected, ical.hasInstancesAfter(cutoff))
 
 
-    def test_normalizeCalendarUserAddresses(self):
+    def test_normalizeCalendarUserAddressesFromUUID(self):
         """
-        Ensure mailto is preferred, followed by path form, then http form
+        Ensure mailto is preferred, followed by path form, then http form.
+        If CALENDARSERVER-OLD-CUA parameter is present, restore that value.
         """
 
         data = """BEGIN:VCALENDAR
@@ -5991,6 +5992,7 @@
 ATTENDEE:urn:uuid:foo
 ATTENDEE:urn:uuid:bar
 ATTENDEE:urn:uuid:baz
+ATTENDEE;CALENDARSERVER-OLD-CUA="http://example.com/principals/users/buz":urn:uuid:buz
 DTSTAMP:20071114T000000Z
 END:VEVENT
 END:VCALENDAR
@@ -6011,10 +6013,15 @@
                     ("urn:uuid:bar", "mailto:bar at example.com", "http://example.com/bar", "/bar")
                 ),
                 "urn:uuid:baz" : (
-                    "BaZ",
+                    "Baz",
                     "baz",
                     ("urn:uuid:baz", "http://example.com/baz")
                 ),
+                "urn:uuid:buz" : (
+                    "Buz",
+                    "buz",
+                    ("urn:uuid:buz",)
+                ),
             }[cuaddr]
 
         component.normalizeCalendarUserAddresses(lookupFunction, toUUID=False)
@@ -6025,4 +6032,54 @@
             component.getAttendeeProperty(("/foo",)).value())
         self.assertEquals("http://example.com/baz",
             component.getAttendeeProperty(("http://example.com/baz",)).value())
+        self.assertEquals("http://example.com/principals/users/buz",
+            component.getAttendeeProperty(("http://example.com/principals/users/buz",)).value())
 
+
+    def test_normalizeCalendarUserAddressesToUUID(self):
+        """
+        Ensure http(s) CUA values are tucked away into the property using
+        CALENDARSERVER-OLD-CUA parameter.
+        """
+
+        data = """BEGIN:VCALENDAR
+VERSION:2.0
+DTSTART:20071114T000000Z
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20071114T000000Z
+ATTENDEE:/principals/users/foo
+ATTENDEE:http://example.com/principals/users/buz
+DTSTAMP:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+"""
+
+        component = Component.fromString(data)
+
+        def lookupFunction(cuaddr):
+            return {
+                "/principals/users/foo" : (
+                    "Foo",
+                    "foo",
+                    ("urn:uuid:foo", )
+                ),
+                "http://example.com/principals/users/buz" : (
+                    "Buz",
+                    "buz",
+                    ("urn:uuid:buz", )
+                ),
+            }[cuaddr]
+
+        component.normalizeCalendarUserAddresses(lookupFunction, toUUID=True)
+
+        # /principal CUAs are not stored in CALENDARSERVER-OLD-CUA
+        prop = component.getAttendeeProperty(("urn:uuid:foo",))
+        self.assertEquals("urn:uuid:foo", prop.value())
+        self.assertEquals(prop.parameterValue("CALENDARSERVER-OLD-CUA"), None)
+
+        # http CUAs are stored in CALENDARSERVER-OLD-CUA
+        prop = component.getAttendeeProperty(("urn:uuid:buz",))
+        self.assertEquals("urn:uuid:buz", prop.value())
+        self.assertEquals(prop.parameterValue("CALENDARSERVER-OLD-CUA"),
+            "http://example.com/principals/users/buz")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120221/ffafe216/attachment.html>


More information about the calendarserver-changes mailing list