[CalendarServer-changes] [2848] CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Sat Aug 23 19:38:39 PDT 2008


Revision: 2848
          http://trac.macosforge.org/projects/calendarserver/changeset/2848
Author:   cdaboo at apple.com
Date:     2008-08-23 19:38:38 -0700 (Sat, 23 Aug 2008)
Log Message:
-----------
Support setting SCHEDULE-STATUS based on implicit schedule responses.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/ical.py
    CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/method/put_common.py
    CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/schedule.py
    CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/implicit.py
    CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/itip.py
    CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/scheduler.py
    CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/test/test_icalendar.py

Modified: CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/ical.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/ical.py	2008-08-23 04:10:45 UTC (rev 2847)
+++ CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/ical.py	2008-08-24 02:38:38 UTC (rev 2848)
@@ -1226,6 +1226,27 @@
 
         return None
 
+    def setParameterToValueForPropertyWithValue(self, paramname, paramvalue, propname, propvalue):
+        """
+        Add or change the parameter to the specified value on the property having the specified value.
+        
+        @param paramname: the parameter name
+        @type paramname: C{str}
+        @param paramvalue: the parameter value to set
+        @type paramvalue: C{str}
+        @param propname: the property name
+        @type propname: C{str}
+        @param propvalue: the property value to test
+        @type propvalue: C{str}
+        """
+        
+        for component in self.subcomponents():
+            if component.name() == "VTIMEZONE":
+                continue
+            for property in component.properties(propname):
+                if property.value() == propvalue:
+                    property.params()[paramname] = [paramvalue]
+           
     def attendeesView(self, attendees):
         """
         Filter out any components that all attendees are not present in. Use EXDATEs

Modified: CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/method/put_common.py	2008-08-23 04:10:45 UTC (rev 2847)
+++ CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/method/put_common.py	2008-08-24 02:38:38 UTC (rev 2848)
@@ -683,6 +683,7 @@
             if not self.isiTIP and self.allowImplicitSchedule:
                 scheduler = ImplicitScheduler()
                 self.calendar = (yield scheduler.doImplicitScheduling(self.request, self.destination, self.calendar, False))
+                self.calendardata = str(self.calendar)
 
             # Initialize the rollback system
             self.setupRollback()

Modified: CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/schedule.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/schedule.py	2008-08-23 04:10:45 UTC (rev 2847)
+++ CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/schedule.py	2008-08-24 02:38:38 UTC (rev 2848)
@@ -300,8 +300,8 @@
         scheduler = CalDAVScheduler(request, self)
 
         # Do the POST processing treating
-        response = (yield scheduler.doSchedulingViaPOST())
-        returnValue(response)
+        result = (yield scheduler.doSchedulingViaPOST())
+        returnValue(result.response())
 
 class IScheduleInboxResource (CalDAVResource):
     """
@@ -372,5 +372,5 @@
         scheduler = IScheduleScheduler(request, self)
 
         # Do the POST processing treating this as a non-local schedule
-        response = (yield scheduler.doSchedulingViaPOST())
-        returnValue(response)
+        result = (yield scheduler.doSchedulingViaPOST())
+        returnValue(result.response())

Modified: CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/implicit.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/implicit.py	2008-08-23 04:10:45 UTC (rev 2847)
+++ CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/implicit.py	2008-08-24 02:38:38 UTC (rev 2848)
@@ -24,6 +24,7 @@
 from twistedcaldav.scheduling.scheduler import CalDAVScheduler
 from twistedcaldav.method import report_common
 from twistedcaldav.scheduling.icaldiff import iCalDiff
+from twistedcaldav import caldavxml
 
 __all__ = [
     "ImplicitScheduler",
@@ -324,8 +325,20 @@
 
     def handleSchedulingResponse(self, response, is_organizer):
         
-        # TODO: need to figure out how to process the response
-        pass
+        # Map each recipient in the response to a status code
+        responses = {}
+        for item in response.responses:
+            assert isinstance(item, caldavxml.Response), "Wrong element in response"
+            recipient = str(item.children[0].children[0])
+            status = str(item.children[1])
+            responses[recipient] = status
+            
+        # Now apply to each ATTENDEE/ORGANIZER in the original data
+        self.calendar.setParameterToValueForPropertyWithValue(
+            "SCHEDULE-STATUS",
+            status,
+            "ATTENDEE" if is_organizer else "ORGANIZER",
+            recipient)
 
     @inlineCallbacks
     def doImplicitAttendee(self):

Modified: CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/itip.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/itip.py	2008-08-23 04:10:45 UTC (rev 2847)
+++ CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/itip.py	2008-08-24 02:38:38 UTC (rev 2848)
@@ -438,6 +438,9 @@
                 "SCHEDULE-AGENT",
                 "SCHEDULE-STATUS",
             ))
+            stripPropertyParameters(component.properties("ORGANIZER"), (
+                "SCHEDULE-STATUS",
+            ))
         
         # No alarms
         itip.removeAlarms()

Modified: CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/scheduler.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/scheduler.py	2008-08-23 04:10:45 UTC (rev 2847)
+++ CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/scheduling/scheduler.py	2008-08-24 02:38:38 UTC (rev 2848)
@@ -86,8 +86,8 @@
         self.loadRecipientsFromRequestHeaders()
         yield self.loadCalendarFromRequest()
 
-        response = (yield self.doScheduling())
-        returnValue(response)
+        result = (yield self.doScheduling())
+        returnValue(result)
 
     @inlineCallbacks
     def doSchedulingViaPUT(self, originator, recipients, calendar):
@@ -105,8 +105,8 @@
         self.recipients = recipients
         self.calendar = calendar
 
-        response = (yield self.doScheduling())
-        returnValue(response)
+        result = (yield self.doScheduling())
+        returnValue(result)
 
     @inlineCallbacks
     def doScheduling(self):
@@ -132,9 +132,9 @@
         self.finalChecks()
 
         # Do scheduling tasks
-        response = (yield self.generateSchedulingResponse())
+        result = (yield self.generateSchedulingResponse())
 
-        returnValue(response)
+        returnValue(result)
 
     def loadOriginatorFromRequestHeaders(self):
         # Must have Originator header
@@ -321,7 +321,7 @@
             yield self.generateIMIPSchedulingResponses(imip_recipients, responses, freebusy)
     
         # Return with final response if we are done
-        returnValue(responses.response())
+        returnValue(responses)
     
     @inlineCallbacks
     def generateLocalSchedulingResponses(self, recipients, responses, freebusy):

Modified: CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/test/test_icalendar.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/test/test_icalendar.py	2008-08-23 04:10:45 UTC (rev 2847)
+++ CalendarServer/branches/users/cdaboo/implicit-2805/twistedcaldav/test/test_icalendar.py	2008-08-24 02:38:38 UTC (rev 2848)
@@ -440,6 +440,147 @@
             component = Component.fromString(caldata)
             self.assertEqual(component.getAttendeesByInstance(), result)
 
+    def test_set_parameter_value(self):
+        data = (
+            # ATTENDEE - no existing parameter
+            (
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;SCHEDULE-STATUS="2.0;OK":mailto:user02 at example.com
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+                (
+                    "SCHEDULE-STATUS",
+                    "2.0;OK",
+                    "ATTENDEE",
+                    "mailto:user02 at example.com",
+                ),
+            ),
+            # ATTENDEE - existing parameter
+            (
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;SCHEDULE-STATUS="5.0;BAD":mailto:user02 at example.com
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;SCHEDULE-STATUS="2.0;OK":mailto:user02 at example.com
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+                (
+                    "SCHEDULE-STATUS",
+                    "2.0;OK",
+                    "ATTENDEE",
+                    "mailto:user02 at example.com",
+                ),
+            ),
+            # ORGANIZER - no existing parameter
+            (
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+ORGANIZER;SCHEDULE-STATUS="2.0;OK":mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+                (
+                    "SCHEDULE-STATUS",
+                    "2.0;OK",
+                    "ORGANIZER",
+                    "mailto:user01 at example.com",
+                ),
+            ),
+            # ORGANIZER - existing parameter
+            (
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+ORGANIZER;SCHEDULE-STATUS="5.0;BAD":mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+ORGANIZER;SCHEDULE-STATUS="2.0;OK":mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+                (
+                    "SCHEDULE-STATUS",
+                    "2.0;OK",
+                    "ORGANIZER",
+                    "mailto:user01 at example.com",
+                ),
+            ),
+        )
+
+        for original, result, args in data:
+            component = Component.fromString(original)
+            component.setParameterToValueForPropertyWithValue(*args)
+            self.assertEqual(result, str(component).replace("\r", ""))        
+
     def test_attendees_views(self):
         
         data = (
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080823/cfa6f514/attachment-0001.html 


More information about the calendarserver-changes mailing list