[CalendarServer-changes] [9149] CalendarServer/trunk/twistedcaldav/scheduling

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 18 14:24:07 PDT 2012


Revision: 9149
          http://trac.macosforge.org/projects/calendarserver/changeset/9149
Author:   cdaboo at apple.com
Date:     2012-04-18 14:24:06 -0700 (Wed, 18 Apr 2012)
Log Message:
-----------
Fix how a schedule object resource is detected and make sure any mismatch between new and old resources forces a
re-evaluation of the old data, so old incorrect values are fixed on the fly.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/scheduling/implicit.py
    CalendarServer/trunk/twistedcaldav/scheduling/test/test_implicit.py

Modified: CalendarServer/trunk/twistedcaldav/scheduling/implicit.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/scheduling/implicit.py	2012-04-18 20:58:45 UTC (rev 9148)
+++ CalendarServer/trunk/twistedcaldav/scheduling/implicit.py	2012-04-18 21:24:06 UTC (rev 9149)
@@ -71,6 +71,14 @@
         existing_type = "schedule" if is_scheduling_object else "calendar"
         new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"
 
+        # If the types do not currently match, re-check the stored one. We need this to work around the possibility
+        # that data exists using the older algorithm of determining a scheduling object resource, and that could be
+        # wrong.
+        if existing_type != new_type and resource and resource.exists():
+            resource.isScheduleObject = None
+            is_scheduling_object = (yield self.checkSchedulingObjectResource(resource))
+            existing_type = "schedule" if is_scheduling_object else "calendar"
+            
         if existing_type == "calendar":
             self.action = "create" if new_type == "schedule" else "none"
         else:
@@ -230,13 +238,9 @@
                 except ValueError:
                     # We have different ORGANIZERs in the same iCalendar object - this is an error
                     returnValue(False)
-                organizerPrincipal = resource.principalForCalendarUserAddress(organizer) if organizer else None
-                implicit = organizerPrincipal != None
-                log.debug("Implicit - checked scheduling object resource state for UID: '%s', result: %s" % (
-                    calendar.resourceUID(),
-                    implicit,
-                ))
-                returnValue(implicit)
+                    
+                # Any ORGANIZER => a scheduling object resource
+                returnValue(organizer is not None)
 
         returnValue(False)
         

Modified: CalendarServer/trunk/twistedcaldav/scheduling/test/test_implicit.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/scheduling/test/test_implicit.py	2012-04-18 20:58:45 UTC (rev 9148)
+++ CalendarServer/trunk/twistedcaldav/scheduling/test/test_implicit.py	2012-04-18 21:24:06 UTC (rev 9149)
@@ -17,11 +17,14 @@
 from pycalendar.datetime import PyCalendarDateTime
 from pycalendar.timezone import PyCalendarTimezone
 from twext.web2 import responsecode
+from twext.web2.test.test_server import SimpleRequest
 from twisted.internet.defer import succeed, inlineCallbacks
 from twistedcaldav.ical import Component
 from twistedcaldav.scheduling.implicit import ImplicitScheduler
 from twistedcaldav.scheduling.scheduler import ScheduleResponseQueue
+from twistedcaldav.test.util import HomeTestCase
 import twistedcaldav.test.util
+from twext.web2.http import HTTPError
 
 class FakeScheduler(object):
     """
@@ -837,3 +840,179 @@
             self.assertEqual(count, result_count)
             self.assertEqual(len(recipients), result_count)
             self.assertEqual(set(recipients), set(result_set))
+
+class ImplicitRequests (HomeTestCase):
+    """
+    Test twistedcaldav.scheduyling.implicit with a Request object. 
+    """
+
+    @inlineCallbacks
+    def test_testImplicitSchedulingPUT_ScheduleState(self):
+        """
+        Test that checkImplicitState() always returns True for any organizer, valid or not.
+        """
+        
+        data = (
+            (
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+END:VEVENT
+END:VCALENDAR
+""",
+                False,
+            ),
+            (
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN="User 01":mailto:wsanchez at example.com
+ATTENDEE:mailto:wsanchez at example.com
+ATTENDEE:mailto:user2 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+                True,
+            ),
+            (
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN="User 01":mailto:bogus at bogus.com
+ATTENDEE:mailto:wsanchez at example.com
+ATTENDEE:mailto:bogus at bogus.com
+END:VEVENT
+END:VCALENDAR
+""",
+                True,
+            ),
+        )
+
+        for calendar, result in data:
+            calendar = Component.fromString(calendar)
+
+            request = SimpleRequest(self.site, "PUT", "/calendar/1.ics")
+            calresource = yield request.locateResource("/calendar/1.ics")
+            self.assertEqual(calresource.isScheduleObject, None)
+            
+            scheduler = ImplicitScheduler()
+            doAction, isScheduleObject = (yield scheduler.testImplicitSchedulingPUT(request, calresource, "/calendar/1.ics", calendar, False))
+            self.assertEqual(doAction, result)
+            self.assertEqual(isScheduleObject, result)
+            request._newStoreTransaction.abort()
+
+    @inlineCallbacks
+    def test_testImplicitSchedulingPUT_FixScheduleState(self):
+        """
+        Test that testImplicitSchedulingPUT will fix an old cached schedule object state by
+        re-evaluating the calendar data.
+        """
+        
+        request = SimpleRequest(self.site, "PUT", "/calendar/1.ics")
+        calresource = yield request.locateResource("/calendar/1.ics")
+        self.assertEqual(calresource.isScheduleObject, None)
+        calresource.isScheduleObject = False
+        
+        calendarOld = Component.fromString("""BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN="User 02":mailto:user2 at example.com
+ATTENDEE:mailto:wsanchez at example.com
+ATTENDEE:mailto:user2 at example.com
+END:VEVENT
+END:VCALENDAR
+""")
+
+
+        calendarNew = Component.fromString("""BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN="User 02":mailto:user2 at example.com
+ATTENDEE:mailto:wsanchez at example.com
+ATTENDEE:mailto:user2 at example.com
+END:VEVENT
+END:VCALENDAR
+""")
+
+        calresource.exists = lambda :True
+        calresource.iCalendarForUser = lambda request:succeed(calendarOld)
+        
+        scheduler = ImplicitScheduler()
+        try:
+            doAction, isScheduleObject = (yield scheduler.testImplicitSchedulingPUT(request, calresource, "/calendars/users/user01/calendar/1.ics", calendarNew, False))
+        except:
+            self.fail("Exception must not be raised")
+        self.assertTrue(doAction)
+        self.assertTrue(isScheduleObject)
+
+    @inlineCallbacks
+    def test_testImplicitSchedulingPUT_NoChangeScheduleState(self):
+        """
+        Test that testImplicitSchedulingPUT will prevent attendees from changing the
+        schedule object state.
+        """
+        
+        request = SimpleRequest(self.site, "PUT", "/calendar/1.ics")
+        calresource = yield request.locateResource("/calendar/1.ics")
+        self.assertEqual(calresource.isScheduleObject, None)
+        calresource.isScheduleObject = False
+        
+        calendarOld = Component.fromString("""BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+END:VEVENT
+END:VCALENDAR
+""")
+
+
+        calendarNew = Component.fromString("""BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN="User 02":mailto:user2 at example.com
+ATTENDEE:mailto:wsanchez at example.com
+ATTENDEE:mailto:user2 at example.com
+END:VEVENT
+END:VCALENDAR
+""")
+
+        calresource.exists = lambda :True
+        calresource.iCalendarForUser = lambda request:succeed(calendarOld)
+        
+        scheduler = ImplicitScheduler()
+        try:
+            yield scheduler.testImplicitSchedulingPUT(request, calresource, "/calendars/users/user01/calendar/1.ics", calendarNew, False)
+        except HTTPError:
+            pass
+        except:
+            self.fail("HTTPError exception must be raised")
+        else:
+            self.fail("Exception must be raised")
+        request._newStoreTransaction.abort()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120418/cc628650/attachment.html>


More information about the calendarserver-changes mailing list