# HG changeset patch # User Paul Boddie # Date 1454965437 -3600 # Node ID 96f9567b0a993c14f3ad79a0d8bc4d09df9b999c # Parent 1fc5f34543dc6d1784e7176cf2fa4baeef59df51 With quotas, reject indefinitely recurring events, allowing rule-based events. diff -r 1fc5f34543dc -r 96f9567b0a99 imiptools/handlers/scheduling/quota.py --- a/imiptools/handlers/scheduling/quota.py Mon Feb 08 20:18:15 2016 +0100 +++ b/imiptools/handlers/scheduling/quota.py Mon Feb 08 22:03:57 2016 +0100 @@ -75,6 +75,11 @@ total = _get_duration(handler) expiry = _get_expiry_time(handler) + # Reject indefinitely recurring events. + + if total == Endless() or not expiry: + return + # Obtain the journal entries and limits. journal = handler.get_journal() @@ -94,6 +99,11 @@ total = _get_duration(handler) + # Reject indefinitely recurring events. + + if total == Endless(): + return + # Obtain the journal entries and limits. journal = handler.get_journal() @@ -127,12 +137,16 @@ "Return the duration of the current object provided by the 'handler'." - # Count only explicit periods. - # NOTE: Should reject indefinitely recurring events. + # Reject indefinitely recurring events. + + if handler.obj.possibly_recurring_indefinitely(): + return Endless() + + # Otherwise, return a sum of the period durations. total = timedelta(0) - for period in handler.get_periods(handler.obj, explicit_only=True): + for period in handler.get_periods(handler.obj): duration = period.get_duration() # Decline events whose period durations are endless. @@ -151,10 +165,12 @@ the 'handler'. """ - # Count only explicit periods. - # NOTE: Should reject indefinitely recurring events. + # Reject indefinitely recurring events. - periods = handler.get_periods(handler.obj, explicit_only=True) + if handler.obj.possibly_recurring_indefinitely(): + return None + + periods = handler.get_periods(handler.obj) return periods and to_utc_datetime(periods[-1].get_end_point()) or None def _get_usage(entries): diff -r 1fc5f34543dc -r 96f9567b0a99 tests/templates/event-request-car-recurring.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/templates/event-request-car-recurring.txt Mon Feb 08 22:03:57 2016 +0100 @@ -0,0 +1,36 @@ +Content-Type: multipart/alternative; boundary="===============0047278175==" +MIME-Version: 1.0 +From: paul.boddie@example.com +To: resource-car-porsche911@example.com +Subject: Invitation! + +--===============0047278175== +Content-Type: text/plain; charset="us-ascii" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +This message contains a recurring event. + +--===============0047278175== +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/calendar; charset="us-ascii"; method="REQUEST" + +BEGIN:VCALENDAR +PRODID:-//imip-agent/test//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:paul.boddie@example.com +ATTENDEE;ROLE=CHAIR:mailto:paul.boddie@example.com +ATTENDEE;RSVP=TRUE:mailto:resource-car-porsche911@example.com +DTSTAMP:20141125T004600Z +DTSTART;TZID=Europe/Oslo:20141126T160000 +DTEND;TZID=Europe/Oslo:20141126T170000 +RRULE:FREQ=DAILY +SUMMARY:Test drives +UID:event24@example.com +END:VEVENT +END:VCALENDAR + +--===============0047278175==-- diff -r 1fc5f34543dc -r 96f9567b0a99 tests/templates/fb-request-car-all.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/templates/fb-request-car-all.txt Mon Feb 08 22:03:57 2016 +0100 @@ -0,0 +1,29 @@ +Content-Type: multipart/alternative; boundary="===============0945993647==" +MIME-Version: 1.0 +From: paul.boddie@example.com +To: resource-car-porsche911@example.com + +--===============0945993647== +Content-Type: text/plain; charset="us-ascii" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +This message contains a free/busy request. +--===============0945993647== +Content-Type: text/calendar; charset="us-ascii"; method="REQUEST" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +BEGIN:VCALENDAR +PRODID:-//imip-agent/test//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VFREEBUSY +ORGANIZER:mailto:paul.boddie@example.com +ATTENDEE:mailto:resource-car-porsche911@example.com +DTSTAMP:20141125T164400Z +UID:fb7@example.com +END:VFREEBUSY +END:VCALENDAR + +--===============0945993647==-- diff -r 1fc5f34543dc -r 96f9567b0a99 tests/test_resource_invitation_constraints_quota_recurring.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_resource_invitation_constraints_quota_recurring.sh Mon Feb 08 22:03:57 2016 +0100 @@ -0,0 +1,148 @@ +#!/bin/sh + +. "`dirname \"$0\"`/common.sh" + +USER="mailto:resource-car-porsche911@example.com" +SENDER="mailto:paul.boddie@example.com" +FBFILE="$STORE/$USER/freebusy" +FBSENDERFILE="$STORE/$SENDER/freebusy" +QUOTA="$USER" +JOURNALFILE="$JOURNAL/$QUOTA/journal/$SENDER" + +mkdir -p "$PREFS/$USER" +echo 'Europe/Oslo' > "$PREFS/$USER/TZID" +echo 'share' > "$PREFS/$USER/freebusy_sharing" +cat > "$PREFS/$USER/scheduling_function" < "$PREFS/$USER/confirmation_function" < "$PREFS/$USER/retraction_function" < "$JOURNAL/$QUOTA/limits" + + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-car-all.txt" 2>> $ERROR \ +| "$SHOWMAIL" \ +> out0.tmp + + grep -q 'METHOD:REPLY' out0.tmp \ +&& ! grep -q '^FREEBUSY' out0.tmp \ +&& echo "Success" \ +|| echo "Failed" + +# Attempt to schedule an event. + +"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-recurring.txt" 2>> $ERROR + + grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \ +&& grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBSENDERFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Present the request to the resource. + + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-recurring.txt" 2>> $ERROR \ +| tee out1r.tmp \ +| "$SHOWMAIL" \ +> out1.tmp + + grep -q 'METHOD:REPLY' out1.tmp \ +&& grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out1.tmp \ +&& echo "Success" \ +|| echo "Failed" + + ! [ -e "$FBFILE" ] \ +|| ( ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE" \ + && ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBFILE" ) \ +&& echo "Success" \ +|| echo "Failed" + +# Check the quota (event is not confirmed). + + ! [ -e "$JOURNALFILE" ] \ +|| ! grep -q "event24@example.com" "$JOURNALFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Modify the event and attempt to schedule it again. + + sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=11/;' "$TEMPLATES/event-request-car-recurring.txt" \ +| "$OUTGOING_SCRIPT" $ARGS 2>> $ERROR + + grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \ + grep -q "^20141205T150000Z${TAB}20141205T160000Z" "$FBSENDERFILE" \ +&& grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBSENDERFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Present the request to the resource. + + sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=11/;' "$TEMPLATES/event-request-car-recurring.txt" \ +| "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ +| tee out2r.tmp \ +| "$SHOWMAIL" \ +> out2.tmp + + grep -q 'METHOD:REPLY' out2.tmp \ +&& grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out2.tmp \ +&& echo "Success" \ +|| echo "Failed" + + ! [ -e "$FBFILE" ] \ +|| ( ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE" \ + && ! grep -q "^20141205T150000Z${TAB}20141205T160000Z" "$FBFILE" \ + && ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBFILE" ) \ +&& echo "Success" \ +|| echo "Failed" + +# Check the quota (event is confirmed). + + ! [ -e "$JOURNALFILE" ] \ +|| ! grep -q "event24@example.com" "$JOURNALFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Modify the event and attempt to schedule it again. + + sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=10/;' "$TEMPLATES/event-request-car-recurring.txt" \ +| "$OUTGOING_SCRIPT" $ARGS 2>> $ERROR + + grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \ + grep -q "^20141205T150000Z${TAB}20141205T160000Z" "$FBSENDERFILE" \ +&& ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBSENDERFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Present the request to the resource. + + sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=10/;' "$TEMPLATES/event-request-car-recurring.txt" \ +| "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ +| tee out2r.tmp \ +| "$SHOWMAIL" \ +> out2.tmp + + grep -q 'METHOD:REPLY' out2.tmp \ +&& grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out2.tmp \ +&& echo "Success" \ +|| echo "Failed" + + [ -e "$FBFILE" ] \ +&& grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE" \ +&& grep -q "^20141205T150000Z${TAB}20141205T160000Z" "$FBFILE" \ +&& ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "$FBFILE" \ +&& echo "Success" \ +|| echo "Failed" + +# Check the quota (event is confirmed). + + [ -e "$JOURNALFILE" ] \ +&& grep -q "event24@example.com" "$JOURNALFILE" \ +&& echo "Success" \ +|| echo "Failed"