1.1 --- a/imiptools/handlers/scheduling/quota.py Mon Feb 08 20:18:15 2016 +0100
1.2 +++ b/imiptools/handlers/scheduling/quota.py Mon Feb 08 22:03:57 2016 +0100
1.3 @@ -75,6 +75,11 @@
1.4 total = _get_duration(handler)
1.5 expiry = _get_expiry_time(handler)
1.6
1.7 + # Reject indefinitely recurring events.
1.8 +
1.9 + if total == Endless() or not expiry:
1.10 + return
1.11 +
1.12 # Obtain the journal entries and limits.
1.13
1.14 journal = handler.get_journal()
1.15 @@ -94,6 +99,11 @@
1.16
1.17 total = _get_duration(handler)
1.18
1.19 + # Reject indefinitely recurring events.
1.20 +
1.21 + if total == Endless():
1.22 + return
1.23 +
1.24 # Obtain the journal entries and limits.
1.25
1.26 journal = handler.get_journal()
1.27 @@ -127,12 +137,16 @@
1.28
1.29 "Return the duration of the current object provided by the 'handler'."
1.30
1.31 - # Count only explicit periods.
1.32 - # NOTE: Should reject indefinitely recurring events.
1.33 + # Reject indefinitely recurring events.
1.34 +
1.35 + if handler.obj.possibly_recurring_indefinitely():
1.36 + return Endless()
1.37 +
1.38 + # Otherwise, return a sum of the period durations.
1.39
1.40 total = timedelta(0)
1.41
1.42 - for period in handler.get_periods(handler.obj, explicit_only=True):
1.43 + for period in handler.get_periods(handler.obj):
1.44 duration = period.get_duration()
1.45
1.46 # Decline events whose period durations are endless.
1.47 @@ -151,10 +165,12 @@
1.48 the 'handler'.
1.49 """
1.50
1.51 - # Count only explicit periods.
1.52 - # NOTE: Should reject indefinitely recurring events.
1.53 + # Reject indefinitely recurring events.
1.54
1.55 - periods = handler.get_periods(handler.obj, explicit_only=True)
1.56 + if handler.obj.possibly_recurring_indefinitely():
1.57 + return None
1.58 +
1.59 + periods = handler.get_periods(handler.obj)
1.60 return periods and to_utc_datetime(periods[-1].get_end_point()) or None
1.61
1.62 def _get_usage(entries):
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/templates/event-request-car-recurring.txt Mon Feb 08 22:03:57 2016 +0100
2.3 @@ -0,0 +1,36 @@
2.4 +Content-Type: multipart/alternative; boundary="===============0047278175=="
2.5 +MIME-Version: 1.0
2.6 +From: paul.boddie@example.com
2.7 +To: resource-car-porsche911@example.com
2.8 +Subject: Invitation!
2.9 +
2.10 +--===============0047278175==
2.11 +Content-Type: text/plain; charset="us-ascii"
2.12 +MIME-Version: 1.0
2.13 +Content-Transfer-Encoding: 7bit
2.14 +
2.15 +This message contains a recurring event.
2.16 +
2.17 +--===============0047278175==
2.18 +MIME-Version: 1.0
2.19 +Content-Transfer-Encoding: 7bit
2.20 +Content-Type: text/calendar; charset="us-ascii"; method="REQUEST"
2.21 +
2.22 +BEGIN:VCALENDAR
2.23 +PRODID:-//imip-agent/test//EN
2.24 +METHOD:REQUEST
2.25 +VERSION:2.0
2.26 +BEGIN:VEVENT
2.27 +ORGANIZER:mailto:paul.boddie@example.com
2.28 +ATTENDEE;ROLE=CHAIR:mailto:paul.boddie@example.com
2.29 +ATTENDEE;RSVP=TRUE:mailto:resource-car-porsche911@example.com
2.30 +DTSTAMP:20141125T004600Z
2.31 +DTSTART;TZID=Europe/Oslo:20141126T160000
2.32 +DTEND;TZID=Europe/Oslo:20141126T170000
2.33 +RRULE:FREQ=DAILY
2.34 +SUMMARY:Test drives
2.35 +UID:event24@example.com
2.36 +END:VEVENT
2.37 +END:VCALENDAR
2.38 +
2.39 +--===============0047278175==--
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/templates/fb-request-car-all.txt Mon Feb 08 22:03:57 2016 +0100
3.3 @@ -0,0 +1,29 @@
3.4 +Content-Type: multipart/alternative; boundary="===============0945993647=="
3.5 +MIME-Version: 1.0
3.6 +From: paul.boddie@example.com
3.7 +To: resource-car-porsche911@example.com
3.8 +
3.9 +--===============0945993647==
3.10 +Content-Type: text/plain; charset="us-ascii"
3.11 +MIME-Version: 1.0
3.12 +Content-Transfer-Encoding: 7bit
3.13 +
3.14 +This message contains a free/busy request.
3.15 +--===============0945993647==
3.16 +Content-Type: text/calendar; charset="us-ascii"; method="REQUEST"
3.17 +MIME-Version: 1.0
3.18 +Content-Transfer-Encoding: 7bit
3.19 +
3.20 +BEGIN:VCALENDAR
3.21 +PRODID:-//imip-agent/test//EN
3.22 +METHOD:REQUEST
3.23 +VERSION:2.0
3.24 +BEGIN:VFREEBUSY
3.25 +ORGANIZER:mailto:paul.boddie@example.com
3.26 +ATTENDEE:mailto:resource-car-porsche911@example.com
3.27 +DTSTAMP:20141125T164400Z
3.28 +UID:fb7@example.com
3.29 +END:VFREEBUSY
3.30 +END:VCALENDAR
3.31 +
3.32 +--===============0945993647==--
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/test_resource_invitation_constraints_quota_recurring.sh Mon Feb 08 22:03:57 2016 +0100
4.3 @@ -0,0 +1,148 @@
4.4 +#!/bin/sh
4.5 +
4.6 +. "`dirname \"$0\"`/common.sh"
4.7 +
4.8 +USER="mailto:resource-car-porsche911@example.com"
4.9 +SENDER="mailto:paul.boddie@example.com"
4.10 +FBFILE="$STORE/$USER/freebusy"
4.11 +FBSENDERFILE="$STORE/$SENDER/freebusy"
4.12 +QUOTA="$USER"
4.13 +JOURNALFILE="$JOURNAL/$QUOTA/journal/$SENDER"
4.14 +
4.15 +mkdir -p "$PREFS/$USER"
4.16 +echo 'Europe/Oslo' > "$PREFS/$USER/TZID"
4.17 +echo 'share' > "$PREFS/$USER/freebusy_sharing"
4.18 +cat > "$PREFS/$USER/scheduling_function" <<EOF
4.19 +schedule_in_freebusy
4.20 +check_quota
4.21 +EOF
4.22 +cat > "$PREFS/$USER/confirmation_function" <<EOF
4.23 +add_to_quota
4.24 +EOF
4.25 +cat > "$PREFS/$USER/retraction_function" <<EOF
4.26 +remove_from_quota
4.27 +EOF
4.28 +
4.29 +# Employ a user-specific quota (no argument with the functions above).
4.30 +
4.31 +mkdir -p "$JOURNAL/$QUOTA"
4.32 +echo '* PT10H' > "$JOURNAL/$QUOTA/limits"
4.33 +
4.34 + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-car-all.txt" 2>> $ERROR \
4.35 +| "$SHOWMAIL" \
4.36 +> out0.tmp
4.37 +
4.38 + grep -q 'METHOD:REPLY' out0.tmp \
4.39 +&& ! grep -q '^FREEBUSY' out0.tmp \
4.40 +&& echo "Success" \
4.41 +|| echo "Failed"
4.42 +
4.43 +# Attempt to schedule an event.
4.44 +
4.45 +"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-recurring.txt" 2>> $ERROR
4.46 +
4.47 + grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \
4.48 +&& grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBSENDERFILE" \
4.49 +&& echo "Success" \
4.50 +|| echo "Failed"
4.51 +
4.52 +# Present the request to the resource.
4.53 +
4.54 + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-recurring.txt" 2>> $ERROR \
4.55 +| tee out1r.tmp \
4.56 +| "$SHOWMAIL" \
4.57 +> out1.tmp
4.58 +
4.59 + grep -q 'METHOD:REPLY' out1.tmp \
4.60 +&& grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out1.tmp \
4.61 +&& echo "Success" \
4.62 +|| echo "Failed"
4.63 +
4.64 + ! [ -e "$FBFILE" ] \
4.65 +|| ( ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE" \
4.66 + && ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBFILE" ) \
4.67 +&& echo "Success" \
4.68 +|| echo "Failed"
4.69 +
4.70 +# Check the quota (event is not confirmed).
4.71 +
4.72 + ! [ -e "$JOURNALFILE" ] \
4.73 +|| ! grep -q "event24@example.com" "$JOURNALFILE" \
4.74 +&& echo "Success" \
4.75 +|| echo "Failed"
4.76 +
4.77 +# Modify the event and attempt to schedule it again.
4.78 +
4.79 + sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=11/;' "$TEMPLATES/event-request-car-recurring.txt" \
4.80 +| "$OUTGOING_SCRIPT" $ARGS 2>> $ERROR
4.81 +
4.82 + grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \
4.83 + grep -q "^20141205T150000Z${TAB}20141205T160000Z" "$FBSENDERFILE" \
4.84 +&& grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBSENDERFILE" \
4.85 +&& echo "Success" \
4.86 +|| echo "Failed"
4.87 +
4.88 +# Present the request to the resource.
4.89 +
4.90 + sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=11/;' "$TEMPLATES/event-request-car-recurring.txt" \
4.91 +| "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \
4.92 +| tee out2r.tmp \
4.93 +| "$SHOWMAIL" \
4.94 +> out2.tmp
4.95 +
4.96 + grep -q 'METHOD:REPLY' out2.tmp \
4.97 +&& grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out2.tmp \
4.98 +&& echo "Success" \
4.99 +|| echo "Failed"
4.100 +
4.101 + ! [ -e "$FBFILE" ] \
4.102 +|| ( ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE" \
4.103 + && ! grep -q "^20141205T150000Z${TAB}20141205T160000Z" "$FBFILE" \
4.104 + && ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBFILE" ) \
4.105 +&& echo "Success" \
4.106 +|| echo "Failed"
4.107 +
4.108 +# Check the quota (event is confirmed).
4.109 +
4.110 + ! [ -e "$JOURNALFILE" ] \
4.111 +|| ! grep -q "event24@example.com" "$JOURNALFILE" \
4.112 +&& echo "Success" \
4.113 +|| echo "Failed"
4.114 +
4.115 +# Modify the event and attempt to schedule it again.
4.116 +
4.117 + sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=10/;' "$TEMPLATES/event-request-car-recurring.txt" \
4.118 +| "$OUTGOING_SCRIPT" $ARGS 2>> $ERROR
4.119 +
4.120 + grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \
4.121 + grep -q "^20141205T150000Z${TAB}20141205T160000Z" "$FBSENDERFILE" \
4.122 +&& ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBSENDERFILE" \
4.123 +&& echo "Success" \
4.124 +|| echo "Failed"
4.125 +
4.126 +# Present the request to the resource.
4.127 +
4.128 + sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=10/;' "$TEMPLATES/event-request-car-recurring.txt" \
4.129 +| "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \
4.130 +| tee out2r.tmp \
4.131 +| "$SHOWMAIL" \
4.132 +> out2.tmp
4.133 +
4.134 + grep -q 'METHOD:REPLY' out2.tmp \
4.135 +&& grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out2.tmp \
4.136 +&& echo "Success" \
4.137 +|| echo "Failed"
4.138 +
4.139 + [ -e "$FBFILE" ] \
4.140 +&& grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE" \
4.141 +&& grep -q "^20141205T150000Z${TAB}20141205T160000Z" "$FBFILE" \
4.142 +&& ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBFILE" \
4.143 +&& echo "Success" \
4.144 +|| echo "Failed"
4.145 +
4.146 +# Check the quota (event is confirmed).
4.147 +
4.148 + [ -e "$JOURNALFILE" ] \
4.149 +&& grep -q "event24@example.com" "$JOURNALFILE" \
4.150 +&& echo "Success" \
4.151 +|| echo "Failed"