# HG changeset patch # User Paul Boddie # Date 1445968008 -3600 # Node ID 2963ca0b67b20c2bae86bd3304760eebad0b4a49 # Parent 17b5b91e95cd40184f1d63c5839c7ea61354a624 Added support for scheduling events using free/busy details for all attendees, instead of just for the requested resource. diff -r 17b5b91e95cd -r 2963ca0b67b2 docs/preferences.txt --- a/docs/preferences.txt Tue Oct 27 18:44:26 2015 +0100 +++ b/docs/preferences.txt Tue Oct 27 18:46:48 2015 +0100 @@ -219,7 +219,8 @@ to the permitted_times setting (see above), if configured, and attempt to schedule the event according to the free/busy records for the - resource, seeking the next available free period for + resource and for any attendees for whom records are + available, seeking the next available free period for each period that conflicts with an existing event The scheduling mechanism can be extended by implementing additional scheduling diff -r 17b5b91e95cd -r 2963ca0b67b2 imiptools/handlers/scheduling.py --- a/imiptools/handlers/scheduling.py Tue Oct 27 18:44:26 2015 +0100 +++ b/imiptools/handlers/scheduling.py Tue Oct 27 18:46:48 2015 +0100 @@ -19,8 +19,9 @@ this program. If not, see . """ +from imiptools.data import uri_values from imiptools.dates import ValidityError, to_timezone -from imiptools.period import invert_freebusy, periods_from +from imiptools.period import get_common_periods, invert_freebusy, periods_from def schedule_in_freebusy(handler): @@ -97,9 +98,17 @@ return scheduled # Find free periods, update the object with the details. + # There should already be free/busy information for the user. - freebusy = handler.store.get_freebusy(handler.user) - free = invert_freebusy(freebusy) + all_free = [invert_freebusy(handler.store.get_freebusy(handler.user))] + + for attendee in uri_values(handler.obj.get_values("ATTENDEE")): + if attendee != handler.user: + freebusy = handler.store.get_freebusy_for_other(handler.user, attendee) + if freebusy: + all_free.append(invert_freebusy(freebusy)) + + free = get_common_periods(all_free) permitted_values = handler.get_permitted_values() periods = [] diff -r 17b5b91e95cd -r 2963ca0b67b2 tests/templates/fb-publish-conflicts.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/templates/fb-publish-conflicts.txt Tue Oct 27 18:46:48 2015 +0100 @@ -0,0 +1,32 @@ +Content-Type: multipart/alternative; boundary="===============0945993647==" +MIME-Version: 1.0 +From: paul.boddie@example.com +To: resource-room-sauna@example.com +Subject: Availability + +--===============0945993647== +Content-Type: text/plain; charset="us-ascii" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +This message contains a free/busy object. +--===============0945993647== +Content-Type: text/calendar; charset="us-ascii"; method="PUBLISH" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +BEGIN:VCALENDAR +PRODID:-//imip-agent/test//EN +METHOD:PUBLISH +VERSION:2.0 +BEGIN:VFREEBUSY +ORGANIZER:mailto:paul.boddie@example.com +ATTENDEE:mailto:resource-room-sauna@example.com +UID:mailto:resource-room-sauna@example.com +DTSTAMP:20140301T163916Z +FREEBUSY;FBTYPE=BUSY:20141126T160000Z/20141126T170000Z +FREEBUSY;FBTYPE=BUSY:20141126T180000Z/20141126T190000Z +END:VFREEBUSY +END:VCALENDAR + +--===============0945993647==-- diff -r 17b5b91e95cd -r 2963ca0b67b2 tests/test_resource_invitation_constraints_next_free.sh --- a/tests/test_resource_invitation_constraints_next_free.sh Tue Oct 27 18:44:26 2015 +0100 +++ b/tests/test_resource_invitation_constraints_next_free.sh Tue Oct 27 18:46:48 2015 +0100 @@ -14,6 +14,7 @@ SENDER="mailto:paul.boddie@example.com" RIVALSENDER="mailto:vincent.vole@example.com" FBFILE="$STORE/$USER/freebusy" +FBOTHERFILE="$STORE/$USER/freebusy-other/$SENDER" FBOFFERFILE="$STORE/$USER/freebusy-offers" FBSENDERFILE="$STORE/$SENDER/freebusy" FBSENDEROTHERFILE="$STORE/$SENDER/freebusy-other/$USER" @@ -79,6 +80,17 @@ | "$SHOWMAIL" \ > out2.tmp +# Publish some conflicting periods as busy. + + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-publish-conflicts.txt" 2>> $ERROR \ +| "$SHOWMAIL" \ +> out3.tmp + + grep -q "^20141126T160000Z${TAB}20141126T170000Z" "$FBOTHERFILE" \ +&& grep -q "^20141126T180000Z${TAB}20141126T190000Z" "$FBOTHERFILE" \ +&& echo "Success" \ +|| echo "Failed" + # Attempt to schedule an event with the resource. "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-sauna-good.txt" 2>> $ERROR @@ -88,7 +100,8 @@ || echo "Failed" # Present the request to the resource. This should cause the event to be -# proposed one hour later. +# proposed not just after the requested period, but also after the busy periods +# published to the resource. "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-sauna-good.txt" 2>> $ERROR \ | tee out6r.tmp \ @@ -101,7 +114,11 @@ || echo "Failed" ! grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBOFFERFILE" \ -&& grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBOFFERFILE" \ +&& ! grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBOFFERFILE" \ +&& ! grep -q "^20141126T170000Z${TAB}20141126T174500Z" "$FBOFFERFILE" \ +&& ! grep -q "^20141126T180000Z${TAB}20141126T184500Z" "$FBOFFERFILE" \ +&& ! grep -q "^20141126T190000Z${TAB}20141126T194500Z" "$FBOFFERFILE" \ +&& grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBOFFERFILE" \ && echo "Success" \ || echo "Failed" @@ -135,7 +152,7 @@ "$OUTGOING_SCRIPT" $ARGS < out8.tmp 2>> $ERROR ! grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBSENDERFILE" \ -&& grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBSENDERFILE" \ +&& grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBSENDERFILE" \ && echo "Success" \ || echo "Failed" @@ -152,17 +169,21 @@ > out9.tmp grep -q 'METHOD:REPLY' out9.tmp \ -&& grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T170000' out9.tmp \ +&& grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T210000' out9.tmp \ && echo "Success" \ || echo "Failed" ! grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBOFFERFILE" \ && ! grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBOFFERFILE" \ +&& ! grep -q "^20141126T170000Z${TAB}20141126T174500Z" "$FBOFFERFILE" \ +&& ! grep -q "^20141126T180000Z${TAB}20141126T184500Z" "$FBOFFERFILE" \ +&& ! grep -q "^20141126T190000Z${TAB}20141126T194500Z" "$FBOFFERFILE" \ +&& ! grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBOFFERFILE" \ && echo "Success" \ || echo "Failed" [ `grep "event19@example.com" "$FBFILE" | wc -l` = '5' ] \ && [ `grep "event13@example.com" "$FBFILE" | wc -l` = '1' ] \ -&& grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBFILE" \ +&& grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBFILE" \ && echo "Success" \ || echo "Failed"