1.1 --- a/imiptools/handlers/scheduling.py Wed Oct 28 11:56:06 2015 +0100
1.2 +++ b/imiptools/handlers/scheduling.py Wed Oct 28 12:52:31 2015 +0100
1.3 @@ -21,7 +21,8 @@
1.4
1.5 from imiptools.data import uri_values
1.6 from imiptools.dates import ValidityError, to_timezone
1.7 -from imiptools.period import get_common_periods, invert_freebusy, periods_from
1.8 +from imiptools.period import get_common_periods, invert_freebusy, \
1.9 + periods_from, remove_period, remove_periods
1.10
1.11 def schedule_in_freebusy(handler):
1.12
1.13 @@ -97,17 +98,27 @@
1.14 if scheduled in ("ACCEPTED", "COUNTER"):
1.15 return scheduled
1.16
1.17 - # Find free periods, update the object with the details.
1.18 # There should already be free/busy information for the user.
1.19
1.20 - all_free = [invert_freebusy(handler.store.get_freebusy(handler.user))]
1.21 + user_freebusy = handler.store.get_freebusy(handler.user)
1.22 + all_freebusy = [user_freebusy]
1.23 +
1.24 + # Subtract any periods from this event from the free/busy collections.
1.25 +
1.26 + event_periods = remove_period(user_freebusy, handler.uid, handler.recurrenceid)
1.27 +
1.28 + # Find busy periods for the other attendees.
1.29
1.30 for attendee in uri_values(handler.obj.get_values("ATTENDEE")):
1.31 if attendee != handler.user:
1.32 freebusy = handler.store.get_freebusy_for_other(handler.user, attendee)
1.33 if freebusy:
1.34 - all_free.append(invert_freebusy(freebusy))
1.35 + remove_periods(freebusy, event_periods)
1.36 + all_freebusy.append(freebusy)
1.37
1.38 + # Obtain free periods.
1.39 +
1.40 + all_free = [invert_freebusy(fb) for fb in all_freebusy]
1.41 free = get_common_periods(all_free)
1.42 permitted_values = handler.get_permitted_values()
1.43 periods = []
2.1 --- a/imiptools/period.py Wed Oct 28 11:56:06 2015 +0100
2.2 +++ b/imiptools/period.py Wed Oct 28 12:52:31 2015 +0100
2.3 @@ -501,20 +501,31 @@
2.4 elif freebusy[i] != period:
2.5 freebusy.insert(i, period)
2.6
2.7 +def remove_periods(freebusy, periods):
2.8 +
2.9 + "Remove from 'freebusy' the given 'periods'."
2.10 +
2.11 + for period in periods:
2.12 + i = bisect_left(freebusy, period)
2.13 + if i < len(freebusy) and freebusy[i] == period:
2.14 + del freebusy[i]
2.15 +
2.16 def remove_period(freebusy, uid, recurrenceid=None):
2.17
2.18 """
2.19 Remove from 'freebusy' all periods associated with 'uid' and 'recurrenceid'
2.20 (which if omitted causes the "parent" object's periods to be referenced).
2.21 +
2.22 + Return the removed periods.
2.23 """
2.24
2.25 - removed = False
2.26 + removed = []
2.27 i = 0
2.28 while i < len(freebusy):
2.29 fb = freebusy[i]
2.30 if fb.uid == uid and fb.recurrenceid == recurrenceid:
2.31 + removed.append(freebusy[i])
2.32 del freebusy[i]
2.33 - removed = True
2.34 else:
2.35 i += 1
2.36
3.1 --- a/tests/test_resource_invitation_constraints_next_free.sh Wed Oct 28 11:56:06 2015 +0100
3.2 +++ b/tests/test_resource_invitation_constraints_next_free.sh Wed Oct 28 12:52:31 2015 +0100
3.3 @@ -213,3 +213,35 @@
3.4 && grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBFILE" \
3.5 && echo "Success" \
3.6 || echo "Failed"
3.7 +
3.8 +# Test scheduling again with a different period. This should disregard the
3.9 +# existing event periods when computing availability in order to be able to
3.10 +# offer them again. Otherwise, an offer would be made for even later periods.
3.11 +
3.12 + sed 's/20141126T160000/20141126T161500/' < "$TEMPLATES/event-request-sauna-good.txt" \
3.13 +| tee out11.tmp \
3.14 +| "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \
3.15 +| "$SHOWMAIL" \
3.16 +> out12.tmp
3.17 +
3.18 + grep -q 'METHOD:COUNTER' out12.tmp \
3.19 +&& grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T210000' out12.tmp \
3.20 +&& echo "Success" \
3.21 +|| echo "Failed"
3.22 +
3.23 +# Note that the duration is different now.
3.24 +
3.25 + ! grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBOFFERFILE" \
3.26 +&& ! grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBOFFERFILE" \
3.27 +&& ! grep -q "^20141126T170000Z${TAB}20141126T174500Z" "$FBOFFERFILE" \
3.28 +&& ! grep -q "^20141126T180000Z${TAB}20141126T184500Z" "$FBOFFERFILE" \
3.29 +&& ! grep -q "^20141126T190000Z${TAB}20141126T194500Z" "$FBOFFERFILE" \
3.30 +&& grep -q "^20141126T200000Z${TAB}20141126T203000Z" "$FBOFFERFILE" \
3.31 +&& echo "Success" \
3.32 +|| echo "Failed"
3.33 +
3.34 + [ `grep "event19@example.com" "$FBFILE" | wc -l` = '5' ] \
3.35 +&& [ `grep "event13@example.com" "$FBFILE" | wc -l` = '1' ] \
3.36 +&& grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBFILE" \
3.37 +&& echo "Success" \
3.38 +|| echo "Failed"