# HG changeset patch # User Paul Boddie # Date 1442157072 -7200 # Node ID bcf0f90542e14cb3be5cd990dba236608e6861ca # Parent 79a612e2f4e70d58d9075a867517c884bcf19bba Introduced common REFRESH-upon-ADD support with support and tests for resources. diff -r 79a612e2f4e7 -r bcf0f90542e1 imiptools/handlers/common.py --- a/imiptools/handlers/common.py Sun Sep 13 17:09:56 2015 +0200 +++ b/imiptools/handlers/common.py Sun Sep 13 17:11:12 2015 +0200 @@ -79,6 +79,37 @@ self.obj.get_datetime("DTSTART") and (self.obj.get_datetime("DTEND") or self.obj.get_duration("DURATION"))) + def will_refresh(self): + + """ + Indicate whether a REFRESH message should be used to respond to an ADD + message. + """ + + return not self.get_stored_object_version() or self.get_add_method_response() == "refresh" + + def make_refresh(self): + + "Make a REFRESH message." + + organiser = get_uri(self.obj.get_value("ORGANIZER")) + attendees = uri_dict(self.obj.get_value_map("ATTENDEE")) + + # Add SENT-BY details to the recipient's attributes. + + attendee_attr = attendees[self.user] + self.update_sender(attendee_attr) + + # Make a new object with a minimal property selection. + + obj = self.obj.copy() + obj.preserve(("ORGANIZER", "DTSTAMP", "UID", "RECURRENCE-ID")) + obj["ATTENDEE"] = [(self.user, attendee_attr)] + + # Send a REFRESH message in response. + + self.add_result("REFRESH", [get_address(organiser)], obj.to_part("REFRESH")) + def update_event_in_freebusy(self, for_organiser=True): """ diff -r 79a612e2f4e7 -r bcf0f90542e1 imiptools/handlers/person.py --- a/imiptools/handlers/person.py Sun Sep 13 17:09:56 2015 +0200 +++ b/imiptools/handlers/person.py Sun Sep 13 17:11:12 2015 +0200 @@ -45,24 +45,8 @@ # Request details where configured, doing so for unknown objects anyway. - refreshing = not self.get_stored_object_version() or self.get_add_method_response() == "refresh" - - if refreshing: - - # Add SENT-BY details to the recipient's attributes. - - attendee_attr = attendees[self.user] - self.update_sender(attendee_attr) - - # Make a new object with a minimal property selection. - - obj = self.obj.copy() - obj.preserve(("ORGANIZER", "DTSTAMP", "UID", "RECURRENCE-ID")) - obj["ATTENDEE"] = [(self.user, attendee_attr)] - - # Send a REFRESH message in response. - - self.add_result("REFRESH", [get_address(organiser)], obj.to_part("REFRESH")) + if self.will_refresh(): + self.make_refresh() # Record the event as a recurrence of the parent object. @@ -74,7 +58,7 @@ # Stop if requesting the full event. - if refreshing: + if self.will_refresh(): return # Set the additional occurrence. diff -r 79a612e2f4e7 -r bcf0f90542e1 imiptools/handlers/resource.py --- a/imiptools/handlers/resource.py Sun Sep 13 17:09:56 2015 +0200 +++ b/imiptools/handlers/resource.py Sun Sep 13 17:11:12 2015 +0200 @@ -19,7 +19,7 @@ this program. If not, see . """ -from imiptools.data import get_address, to_part +from imiptools.data import get_address, to_part, uri_dict from imiptools.dates import ValidityError from imiptools.handlers import Handler from imiptools.handlers.common import CommonFreebusy, CommonEvent @@ -58,17 +58,16 @@ This does not request a response concerning participation, apparently. """ - # Ignore unknown objects. - # NOTE: We could issue a REFRESH to get such objects. + # Request details where configured, doing so for unknown objects anyway. - if not self.get_stored_object_version(): + if self.will_refresh(): + self.make_refresh() return # Record the event as a recurrence of the parent object. self.update_recurrenceid() - event = self.obj.to_node() - self.store.set_event(self.user, self.uid, self.recurrenceid, event) + self.store.set_event(self.user, self.uid, self.recurrenceid, self.obj.to_node()) # Update free/busy information. @@ -79,7 +78,7 @@ "Attempt to schedule the current object for the current user." method = "REPLY" - attendee_attr = self.obj.get_value_map("ATTENDEE")[self.user] + attendee_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[self.user] # Check any constraints on the request. diff -r 79a612e2f4e7 -r bcf0f90542e1 tests/templates/event-add-recurring.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/templates/event-add-recurring.txt Sun Sep 13 17:11:12 2015 +0200 @@ -0,0 +1,34 @@ +Content-Type: multipart/alternative; boundary="===============0047278175==" +MIME-Version: 1.0 +From: paul.boddie@example.com +To: resource-room-confroom@example.com +Subject: Invitation! + +--===============0047278175== +Content-Type: text/plain; charset="us-ascii" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +This message contains an event. + +--===============0047278175== +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/calendar; charset="us-ascii"; method="ADD" + +BEGIN:VCALENDAR +PRODID:-//imip-agent/test//EN +METHOD:ADD +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:paul.boddie@example.com +ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com +DTSTAMP:20141009T182400Z +DTSTART;TZID=Europe/Oslo:20150109T100000 +DTEND;TZID=Europe/Oslo:20150109T110000 +SUMMARY:Recurring event +UID:event3@example.com +END:VEVENT +END:VCALENDAR + +--===============0047278175==-- diff -r 79a612e2f4e7 -r bcf0f90542e1 tests/test_resource_invitation_add.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_resource_invitation_add.sh Sun Sep 13 17:11:12 2015 +0200 @@ -0,0 +1,129 @@ +#!/bin/sh + +THIS_DIR=`dirname $0` + +TEMPLATES="$THIS_DIR/templates" +PERSON_SCRIPT="$THIS_DIR/../imip_person.py" +RESOURCE_SCRIPT="$THIS_DIR/../imip_resource.py" +SHOWMAIL="$THIS_DIR/../tools/showmail.py" +STORE=/tmp/store +STATIC=/tmp/static +PREFS=/tmp/prefs +ARGS="-S $STORE -P $STATIC -p $PREFS -d" +USER="mailto:resource-room-confroom@example.com" +SENDER="mailto:paul.boddie@example.com" +FBFILE="$STORE/$USER/freebusy" +FBSENDERFILE="$STORE/$SENDER/freebusy" +FBSENDEROTHERFILE="$STORE/$SENDER/freebusy-other/$USER" +TAB=`printf '\t'` + +OUTGOING_SCRIPT="$THIS_DIR/../imip_person_outgoing.py" + +ERROR=err.tmp + +rm -r $STORE +rm -r $STATIC +rm -r $PREFS +rm $ERROR +rm out*.tmp + +mkdir -p "$PREFS/$USER" +echo 'Europe/Oslo' > "$PREFS/$USER/TZID" +echo 'share' > "$PREFS/$USER/freebusy_sharing" + +mkdir -p "$PREFS/$SENDER" +echo 'Europe/Oslo' > "$PREFS/$SENDER/TZID" +echo 'always' > "$PREFS/$SENDER/event_refreshing" + +# Publish an event, testing registration in the outgoing handler. + +"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-recurring.txt" 2>> $ERROR + + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBSENDERFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Present the request to the recipient. + + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-recurring.txt" 2>> $ERROR \ +| "$SHOWMAIL" \ +> out1.tmp + + grep -q 'METHOD:REPLY' out1.tmp \ +&& echo "Success" \ +|| echo "Failed" + + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Present the response to the sender. + + "$PERSON_SCRIPT" $ARGS < out1.tmp 2>> $ERROR \ +| "$SHOWMAIL" \ +> out2.tmp + + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBSENDEROTHERFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Attempt to add an occurrence to the event. + +"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-add-recurring.txt" 2>> $ERROR + + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBSENDERFILE" \ +&& grep -q "^20150109T090000Z${TAB}20150109T100000Z" "$FBSENDERFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Present the request to the recipient. + + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-add-recurring.txt" 2>> $ERROR \ +| "$SHOWMAIL" \ +> out3.tmp + + grep -q 'METHOD:REFRESH' out3.tmp \ +&& echo "Success" \ +|| echo "Failed" + + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBFILE" \ +&& ! grep -q "^20150109T090000Z${TAB}20150109T100000Z" "$FBFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Present the refresh message to the organiser. + + "$PERSON_SCRIPT" $ARGS < out3.tmp 2>> $ERROR \ +| "$SHOWMAIL" \ +> out4.tmp + + grep -q 'METHOD:REQUEST' out4.tmp \ +&& echo "Success" \ +|| echo "Failed" + +# Present the request to the recipient. + + "$RESOURCE_SCRIPT" $ARGS < out4.tmp 2>> $ERROR \ +| tee out5r.tmp \ +| "$SHOWMAIL" \ +> out5.tmp + + grep -q 'METHOD:REPLY' out5.tmp \ +&& echo "Success" \ +|| echo "Failed" + + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBFILE" \ +&& grep -q "^20150109T090000Z${TAB}20150109T100000Z" "$FBFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Present the response to the sender. + + "$PERSON_SCRIPT" $ARGS < out5r.tmp 2>> $ERROR \ +| "$SHOWMAIL" \ +> out6.tmp + + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBSENDEROTHERFILE" \ +&& grep -q "^20150109T090000Z${TAB}20150109T100000Z" "$FBSENDEROTHERFILE" \ +&& echo "Success" \ +|| echo "Failed"