# HG changeset patch # User Paul Boddie # Date 1446033151 -3600 # Node ID 6961576e0f0666342e817318d954ab5765c978db # Parent aa16ccd685322ea36d81959bc8a6e1e00a8bbad5 Disregard the existing event periods when rescheduling an event using resource and attendee free/busy details. diff -r aa16ccd68532 -r 6961576e0f06 imiptools/handlers/scheduling.py --- a/imiptools/handlers/scheduling.py Wed Oct 28 11:56:06 2015 +0100 +++ b/imiptools/handlers/scheduling.py Wed Oct 28 12:52:31 2015 +0100 @@ -21,7 +21,8 @@ from imiptools.data import uri_values from imiptools.dates import ValidityError, to_timezone -from imiptools.period import get_common_periods, invert_freebusy, periods_from +from imiptools.period import get_common_periods, invert_freebusy, \ + periods_from, remove_period, remove_periods def schedule_in_freebusy(handler): @@ -97,17 +98,27 @@ if scheduled in ("ACCEPTED", "COUNTER"): return scheduled - # Find free periods, update the object with the details. # There should already be free/busy information for the user. - all_free = [invert_freebusy(handler.store.get_freebusy(handler.user))] + user_freebusy = handler.store.get_freebusy(handler.user) + all_freebusy = [user_freebusy] + + # Subtract any periods from this event from the free/busy collections. + + event_periods = remove_period(user_freebusy, handler.uid, handler.recurrenceid) + + # Find busy periods for the other attendees. 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)) + remove_periods(freebusy, event_periods) + all_freebusy.append(freebusy) + # Obtain free periods. + + all_free = [invert_freebusy(fb) for fb in all_freebusy] free = get_common_periods(all_free) permitted_values = handler.get_permitted_values() periods = [] diff -r aa16ccd68532 -r 6961576e0f06 imiptools/period.py --- a/imiptools/period.py Wed Oct 28 11:56:06 2015 +0100 +++ b/imiptools/period.py Wed Oct 28 12:52:31 2015 +0100 @@ -501,20 +501,31 @@ elif freebusy[i] != period: freebusy.insert(i, period) +def remove_periods(freebusy, periods): + + "Remove from 'freebusy' the given 'periods'." + + for period in periods: + i = bisect_left(freebusy, period) + if i < len(freebusy) and freebusy[i] == period: + del freebusy[i] + def remove_period(freebusy, uid, recurrenceid=None): """ Remove from 'freebusy' all periods associated with 'uid' and 'recurrenceid' (which if omitted causes the "parent" object's periods to be referenced). + + Return the removed periods. """ - removed = False + removed = [] i = 0 while i < len(freebusy): fb = freebusy[i] if fb.uid == uid and fb.recurrenceid == recurrenceid: + removed.append(freebusy[i]) del freebusy[i] - removed = True else: i += 1 diff -r aa16ccd68532 -r 6961576e0f06 tests/test_resource_invitation_constraints_next_free.sh --- a/tests/test_resource_invitation_constraints_next_free.sh Wed Oct 28 11:56:06 2015 +0100 +++ b/tests/test_resource_invitation_constraints_next_free.sh Wed Oct 28 12:52:31 2015 +0100 @@ -213,3 +213,35 @@ && grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBFILE" \ && echo "Success" \ || echo "Failed" + +# Test scheduling again with a different period. This should disregard the +# existing event periods when computing availability in order to be able to +# offer them again. Otherwise, an offer would be made for even later periods. + + sed 's/20141126T160000/20141126T161500/' < "$TEMPLATES/event-request-sauna-good.txt" \ +| tee out11.tmp \ +| "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ +| "$SHOWMAIL" \ +> out12.tmp + + grep -q 'METHOD:COUNTER' out12.tmp \ +&& grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T210000' out12.tmp \ +&& echo "Success" \ +|| echo "Failed" + +# Note that the duration is different now. + + ! 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}20141126T203000Z" "$FBOFFERFILE" \ +&& echo "Success" \ +|| echo "Failed" + + [ `grep "event19@example.com" "$FBFILE" | wc -l` = '5' ] \ +&& [ `grep "event13@example.com" "$FBFILE" | wc -l` = '1' ] \ +&& grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBFILE" \ +&& echo "Success" \ +|| echo "Failed"