[CalendarServer-changes] [14157] CalendarServer/branches/release/CalendarServer-5.3-dev/ twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed Nov 12 12:56:25 PST 2014


Revision: 14157
          http://trac.calendarserver.org//changeset/14157
Author:   cdaboo at apple.com
Date:     2014-11-12 12:56:24 -0800 (Wed, 12 Nov 2014)
Log Message:
-----------
Fix for clients that fail when resources/locations do not have an email address.

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/cachingdirectory.py
    CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/directory.py
    CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_cachedirectory.py
    CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_directory.py
    CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/ical.py
    CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py
    CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/test/test_icalendar.py

Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/cachingdirectory.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/cachingdirectory.py	2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/cachingdirectory.py	2014-11-12 20:56:24 UTC (rev 14157)
@@ -300,6 +300,11 @@
     def recordWithCalendarUserAddress(self, address):
         address = normalizeCUAddr(address)
         record = None
+
+        if config.Scheduling.Options.FakeResourceLocationEmail:
+            if address.startswith("mailto:") and address.endswith("@do_not_reply"):
+                address = "urn:uuid:{}".format(address[7:-13])
+
         if address.startswith("mailto:"):
             record = self._lookupRecord(None, CachingDirectoryService.INDEX_TYPE_CUA, address)
             return record if record and record.enabledForCalendaring else None

Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/directory.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/directory.py	2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/directory.py	2014-11-12 20:56:24 UTC (rev 14157)
@@ -225,6 +225,11 @@
     def recordWithCalendarUserAddress(self, address):
         address = normalizeCUAddr(address)
         record = None
+
+        if config.Scheduling.Options.FakeResourceLocationEmail:
+            if address.startswith("mailto:") and address.endswith("@do_not_reply"):
+                address = "urn:uuid:{}".format(address[7:-13])
+
         if address.startswith("urn:uuid:"):
             guid = address[9:]
             record = self.recordWithGUID(guid)
@@ -1171,6 +1176,10 @@
         if fullName is None:
             fullName = ""
 
+        if config.Scheduling.Options.FakeResourceLocationEmail:
+            if recordType in (service.recordType_locations, service.recordType_resources) and not emailAddresses:
+                emailAddresses = set(("%s at do_not_reply" % uid,))
+
         self.service = service
         self.recordType = recordType
         self.guid = guid

Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_cachedirectory.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_cachedirectory.py	2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_cachedirectory.py	2014-11-12 20:56:24 UTC (rev 14157)
@@ -383,3 +383,20 @@
             self.service.generateMemcacheKey(self.service.INDEX_TYPE_SHORTNAME, "foo", "users"),
             "dir|v2|20CB1593-DE3F-4422-A7D7-BA9C2099B317|users|shortname|foo",
         )
+
+
+    def test_fakeemail(self):
+
+        self.patch(config.Scheduling.Options, "FakeResourceLocationEmail", True)
+        self.dummyRecords()
+
+        self.assertTrue(self.service.recordWithCalendarUserAddress(
+            "mailto:{}@do_not_reply".format(self.guidForShortName("resource02", recordType=DirectoryService.recordType_resources))
+        ) is not None)
+        self.assertTrue(self.service.recordWithCalendarUserAddress(
+            "mailto:{}@do_not_reply".format(self.guidForShortName("location02", recordType=DirectoryService.recordType_locations))
+        ) is not None)
+        self.assertTrue(self.service.recordWithCalendarUserAddress(
+            "mailto:bogus at do_not_reply"
+        ) is None)
+        self.assertTrue(self.service.queried)

Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_directory.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_directory.py	2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_directory.py	2014-11-12 20:56:24 UTC (rev 14157)
@@ -1164,7 +1164,38 @@
         self.assertTrue(record is None)
 
 
+    def test_recordWithCalendarUserAddress_fake_email(self):
+        """
+        Make sure that recordWithCalendarUserAddress handles fake emails for
+        resources and locations.
+        """
 
+        self.patch(config.Scheduling.Options, "FakeResourceLocationEmail", True)
+
+        self.service.createRecord(
+            DirectoryService.recordType_resources,
+            guid="resource01",
+            shortNames=("resource 01", "Resource 01"),
+            fullName="Resource 01",
+            enabledForCalendaring=True,
+        )
+        self.service.createRecord(
+            DirectoryService.recordType_locations,
+            guid="location02",
+            shortNames=("location02", "Location 02"),
+            fullName="Location 02",
+            enabledForCalendaring=True,
+        )
+
+        record = self.service.recordWithCalendarUserAddress("mailto:resource01 at do_not_reply")
+        self.assertTrue(record is not None)
+        record = self.service.recordWithCalendarUserAddress("mailto:location02 at do_not_reply")
+        self.assertTrue(record is not None)
+        record = self.service.recordWithCalendarUserAddress("mailto:location01 at do_not_reply")
+        self.assertTrue(record is None)
+
+
+
 class DirectoryRecordTests(TestCase):
     """
     Test L{DirectoryRecord} apis.

Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/ical.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/ical.py	2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/ical.py	2014-11-12 20:56:24 UTC (rev 14157)
@@ -3248,6 +3248,10 @@
                 if oldemail:
                     oldemail = "mailto:%s" % (oldemail,)
 
+                    if config.Scheduling.Options.FakeResourceLocationEmail:
+                        if oldemail.endswith("@do_not_reply"):
+                            oldemail = None
+
                 # Get any CN parameter
                 oldCN = prop.parameterValue("CN")
 
@@ -3326,6 +3330,10 @@
                         else:
                             email = None
 
+                    if config.Scheduling.Options.FakeResourceLocationEmail:
+                        if email.endswith("@do_not_reply"):
+                            email = ""
+
                     if email:
                         prop.setParameter("EMAIL", email)
                     else:

Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py	2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py	2014-11-12 20:56:24 UTC (rev 14157)
@@ -733,6 +733,7 @@
             "AllowResourceWithoutOrganizer"       : True, # Allow resources to have events without an Organizer
             "TrackUnscheduledLocationData"        : True, # Track who the last modifier of an unscheduled location event is
             "TrackUnscheduledResourceData"        : True, # Track who the last modifier of an unscheduled resource event is
+            "FakeResourceLocationEmail"           : False, # Add fake email addresses to work around client bug
             "LimitFreeBusyAttendees"              : 30, # Maximum number of attendees to request freebusy for
             "AttendeeRefreshBatch"                : 5, # Number of attendees to do batched refreshes: 0 - no batching
             "AttendeeRefreshBatchDelaySeconds"    : 5, # Time after an iTIP REPLY for first batched attendee refresh

Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/test/test_icalendar.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/test/test_icalendar.py	2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/test/test_icalendar.py	2014-11-12 20:56:24 UTC (rev 14157)
@@ -31,6 +31,7 @@
 from pycalendar.duration import PyCalendarDuration
 from twistedcaldav.dateops import normalizeForExpand
 from pycalendar.value import PyCalendarValue
+from twistedcaldav.config import config
 
 class iCalendar (twistedcaldav.test.util.TestCase):
     """
@@ -8177,6 +8178,70 @@
         self.assertEquals(prop.parameterValue("CN"), "{Restricted} Buzz")
 
 
+    def test_normalizeCalendarUserAddressesWithFakeEmail(self):
+        """
+        Ensure fake email addresses are not inserted as EMAIL parameters.
+        """
+
+        self.patch(config.Scheduling.Options, "FakeResourceLocationEmail", True)
+
+        data = """BEGIN:VCALENDAR
+VERSION:2.0
+DTSTART:20071114T000000Z
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20071114T000000Z
+ATTENDEE:/principals/users/foo
+ATTENDEE;CN=Fake 1;CUTYPE=ROOM:mailto:fake1 at do_not_reply
+ATTENDEE;CN=Fake 2;EMAIL=fake2 at do_not_reply;CUTYPE=ROOM:mailto:fake2 at do_not_reply
+LOCATION:Buzz
+DTSTAMP:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+"""
+
+        result = """BEGIN:VCALENDAR
+VERSION:2.0
+DTSTART:20071114T000000Z
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20071114T000000Z
+ATTENDEE;CN=Foo;EMAIL=foo at example.com:urn:uuid:foo
+ATTENDEE;CN=Fake 1;CUTYPE=ROOM:urn:uuid:fake1
+ATTENDEE;CN=Fake 2;CUTYPE=ROOM:urn:uuid:fake2
+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", "mailto:foo at example.com")
+                ),
+                "mailto:fake1 at do_not_reply" : (
+                    "Fake 1",
+                    "fake1",
+                    ("urn:uuid:fake1", "mailto:fake1 at do_not_reply")
+                ),
+                "mailto:fake2 at do_not_reply" : (
+                    "Fake 2",
+                    "fake2",
+                    ("urn:uuid:fake2", "mailto:fake2 at do_not_reply")
+                ),
+            }[cuaddr]
+
+        component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
+
+        self.assertEqual(normalize_iCalStr(component), normalize_iCalStr(result))
+
+
     def test_serializationCaching(self):
 
         data = """BEGIN:VCALENDAR
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141112/adc69720/attachment-0001.html>


More information about the calendarserver-changes mailing list