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

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 2 13:31:38 PDT 2013


Revision: 10976
          http://trac.calendarserver.org//changeset/10976
Author:   cdaboo at apple.com
Date:     2013-04-02 13:31:37 -0700 (Tue, 02 Apr 2013)
Log Message:
-----------
Adjust location name when CN of matching ATTENDEE changes.

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	2013-04-02 19:25:14 UTC (rev 10975)
+++ CalendarServer/trunk/twistedcaldav/ical.py	2013-04-02 20:31:37 UTC (rev 10976)
@@ -2979,8 +2979,7 @@
                 # Check that we can lookup this calendar user address - if not
                 # we cannot do anything with it
                 cuaddr = normalizeCUAddr(prop.value())
-                name, guid, cuaddrs = lookupFunction(cuaddr, principalFunction,
-                    config)
+                name, guid, cuaddrs = lookupFunction(cuaddr, principalFunction, config)
                 if guid is None:
                     continue
 
@@ -2989,6 +2988,11 @@
                 if oldemail:
                     oldemail = "mailto:%s" % (oldemail,)
 
+                # Get any CN parameter
+                oldCN = prop.parameterValue("CN")
+
+                cutype = prop.parameterValue("CUTYPE")
+
                 if toUUID:
                     # Store the original CUA if http(s) or /path:
                     if config.Scheduling.Options.V1Compatibility:
@@ -3049,9 +3053,17 @@
                     if newaddr:
                         prop.setValue(newaddr)
 
-                # Always re-write the CN parameter
+                # Re-write the CN parameter
                 if name:
-                    prop.setParameter("CN", name)
+                    if name != oldCN:
+                        prop.setParameter("CN", name)
+
+                        # Also adjust any previously matching location property
+                        if cutype == "ROOM":
+                            location = component.getProperty("LOCATION")
+                            if location is not None:
+                                if location.value() == oldCN:
+                                    location.setValue(name)
                 else:
                     prop.removeParameter("CN")
 

Modified: CalendarServer/trunk/twistedcaldav/test/test_icalendar.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_icalendar.py	2013-04-02 19:25:14 UTC (rev 10975)
+++ CalendarServer/trunk/twistedcaldav/test/test_icalendar.py	2013-04-02 20:31:37 UTC (rev 10976)
@@ -7432,6 +7432,165 @@
             "base64-aHR0cDovL2V4YW1wbGUuY29tL3ByaW5jaXBhbHMvdXNlcnMvYnV6")
 
 
+    def test_normalizeCalendarUserAddressesAndLocationChange(self):
+        """
+        Ensure http(s) and /path 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/bar
+ATTENDEE;CN=Buzz;CUTYPE=ROOM:http://example.com/principals/locations/buzz
+LOCATION:Buzz
+DTSTAMP:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+"""
+
+        component = Component.fromString(data)
+
+
+        def lookupFunction(cuaddr, ignored1, ignored2):
+            return {
+                "/principals/users/foo" : (
+                    "Foo",
+                    "foo",
+                    ("urn:uuid:foo",)
+                ),
+                "http://example.com/principals/users/bar" : (
+                    "Bar",
+                    "bar",
+                    ("urn:uuid:bar",)
+                ),
+                "http://example.com/principals/locations/buzz" : (
+                    "{Restricted} Buzz",
+                    "buzz",
+                    ("urn:uuid:buzz",)
+                ),
+            }[cuaddr]
+
+        component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
+
+        # Location value changed
+        prop = component.mainComponent().getProperty("LOCATION")
+        self.assertEquals(prop.value(), "{Restricted} Buzz")
+        prop = component.getAttendeeProperty(("urn:uuid:buzz",))
+        self.assertEquals("urn:uuid:buzz", prop.value())
+        self.assertEquals(prop.parameterValue("CN"), "{Restricted} Buzz")
+
+
+    def test_normalizeCalendarUserAddressesAndLocationNoChange(self):
+        """
+        Ensure http(s) and /path 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/bar
+ATTENDEE;CN=Buzz;CUTYPE=ROOM:http://example.com/principals/locations/buzz
+LOCATION:Fuzz
+DTSTAMP:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+"""
+
+        component = Component.fromString(data)
+
+
+        def lookupFunction(cuaddr, ignored1, ignored2):
+            return {
+                "/principals/users/foo" : (
+                    "Foo",
+                    "foo",
+                    ("urn:uuid:foo",)
+                ),
+                "http://example.com/principals/users/bar" : (
+                    "Bar",
+                    "bar",
+                    ("urn:uuid:bar",)
+                ),
+                "http://example.com/principals/locations/buzz" : (
+                    "{Restricted} Buzz",
+                    "buzz",
+                    ("urn:uuid:buzz",)
+                ),
+            }[cuaddr]
+
+        component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
+
+        # Location value changed
+        prop = component.mainComponent().getProperty("LOCATION")
+        self.assertEquals(prop.value(), "Fuzz")
+        prop = component.getAttendeeProperty(("urn:uuid:buzz",))
+        self.assertEquals("urn:uuid:buzz", prop.value())
+        self.assertEquals(prop.parameterValue("CN"), "{Restricted} Buzz")
+
+
+    def test_normalizeCalendarUserAddressesAndLocationNoChangeOtherCUType(self):
+        """
+        Ensure http(s) and /path 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/bar
+ATTENDEE;CN=Buzz;CUTYPE=RESOURCE:http://example.com/principals/locations/buzz
+LOCATION:Buzz
+DTSTAMP:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+"""
+
+        component = Component.fromString(data)
+
+
+        def lookupFunction(cuaddr, ignored1, ignored2):
+            return {
+                "/principals/users/foo" : (
+                    "Foo",
+                    "foo",
+                    ("urn:uuid:foo",)
+                ),
+                "http://example.com/principals/users/bar" : (
+                    "Bar",
+                    "bar",
+                    ("urn:uuid:bar",)
+                ),
+                "http://example.com/principals/locations/buzz" : (
+                    "{Restricted} Buzz",
+                    "buzz",
+                    ("urn:uuid:buzz",)
+                ),
+            }[cuaddr]
+
+        component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
+
+        # Location value changed
+        prop = component.mainComponent().getProperty("LOCATION")
+        self.assertEquals(prop.value(), "Buzz")
+        prop = component.getAttendeeProperty(("urn:uuid:buzz",))
+        self.assertEquals("urn:uuid:buzz", prop.value())
+        self.assertEquals(prop.parameterValue("CN"), "{Restricted} Buzz")
+
+
     def test_serializationCaching(self):
 
         data = """BEGIN:VCALENDAR
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130402/176a9154/attachment-0001.html>


More information about the calendarserver-changes mailing list