# HG changeset patch # User Paul Boddie # Date 1463094608 -7200 # Node ID 9cb6a6acfe171c72f8d761a9fb75f7e114c1ff95 # Parent 3252084e96084160922e83b70a2bd8af7723c5cd Incorporated check_quota functionality into the schedule_for_delegate function. Added support for quota user groups mapping all (or all remaining unindicated) organisers to a common group. Added a tool for setting quota user-to-group mappings. diff -r 3252084e9608 -r 9cb6a6acfe17 imiptools/handlers/scheduling/quota.py --- a/imiptools/handlers/scheduling/quota.py Fri May 13 00:28:46 2016 +0200 +++ b/imiptools/handlers/scheduling/quota.py Fri May 13 01:10:08 2016 +0200 @@ -130,7 +130,7 @@ journal = handler.get_journal() groups = journal.get_groups(quota) - return quota, groups.get(organiser) or organiser + return quota, groups.get(organiser) or groups.get("*") or organiser def _get_duration(handler): @@ -372,11 +372,13 @@ confirmation_functions = { "check_quota" : add_to_quota, "schedule_across_quota" : add_to_quota_freebusy, + "schedule_for_delegate" : add_to_quota, } retraction_functions = { "check_quota" : remove_from_quota, "schedule_across_quota" : remove_from_quota_freebusy, + "schedule_for_delegate" : remove_from_quota, } # vim: tabstop=4 expandtab shiftwidth=4 diff -r 3252084e9608 -r 9cb6a6acfe17 tests/common.sh --- a/tests/common.sh Fri May 13 00:28:46 2016 +0200 +++ b/tests/common.sh Fri May 13 01:10:08 2016 +0200 @@ -24,8 +24,11 @@ SET_DELEGATES="$BASE_DIR/tools/set_delegates.py" SET_DELEGATES_ARGS="-T $STORE_TYPE -j $JOURNAL" -SET_QUOTA_LIMIT="$BASE_DIR/tools/set_quota_limits.py" -SET_QUOTA_LIMIT_ARGS="-T $STORE_TYPE -j $JOURNAL" +SET_QUOTA_GROUPS="$BASE_DIR/tools/set_quota_groups.py" +SET_QUOTA_GROUPS_ARGS="-T $STORE_TYPE -j $JOURNAL" + +SET_QUOTA_LIMITS="$BASE_DIR/tools/set_quota_limits.py" +SET_QUOTA_LIMITS_ARGS="-T $STORE_TYPE -j $JOURNAL" TAB=`printf '\t'` diff -r 3252084e9608 -r 9cb6a6acfe17 tests/templates/event-request-car-delegating.txt --- a/tests/templates/event-request-car-delegating.txt Fri May 13 00:28:46 2016 +0200 +++ b/tests/templates/event-request-car-delegating.txt Fri May 13 01:10:08 2016 +0200 @@ -1,6 +1,6 @@ Content-Type: multipart/alternative; boundary="===============0047278175==" MIME-Version: 1.0 -From: paul.boddie@example.com +From: vincent.vole@example.com To: resource-car-porsche911@example.com Subject: Invitation! @@ -20,8 +20,8 @@ METHOD:REQUEST VERSION:2.0 BEGIN:VEVENT -ORGANIZER:mailto:paul.boddie@example.com -ATTENDEE;ROLE=CHAIR:mailto:paul.boddie@example.com +ORGANIZER:mailto:vincent.vole@example.com +ATTENDEE;ROLE=CHAIR:mailto:vincent.vole@example.com ATTENDEE;RSVP=TRUE:mailto:resource-car-porsche911@example.com DTSTAMP:20141125T004600Z DTSTART;TZID=Europe/Oslo:20141126T163000 diff -r 3252084e9608 -r 9cb6a6acfe17 tests/test_resource_invitation_constraints_quota.sh --- a/tests/test_resource_invitation_constraints_quota.sh Fri May 13 00:28:46 2016 +0200 +++ b/tests/test_resource_invitation_constraints_quota.sh Fri May 13 01:10:08 2016 +0200 @@ -24,10 +24,10 @@ check_quota $QUOTA EOF -cat < "$PREFS/$USER1/scheduling_function" < "$PREFS/$USER2/scheduling_function" <> $ERROR - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \ + "$LIST_SCRIPT" $LIST_ARGS "$SENDER1" "freebusy" \ | tee out0s.tmp \ | grep -q "^20141126T150000Z${TAB}20141126T160000Z" \ && echo "Success" \ @@ -82,7 +81,7 @@ # Check the quota (event is confirmed). - "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \ + "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "all" \ | tee out1e.tmp \ | grep -q "event21@example.com" \ && echo "Success" \ @@ -92,7 +91,7 @@ "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-delegating.txt" 2>> $ERROR - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \ + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy" \ | tee out1s.tmp \ | grep -q "^20141126T153000Z${TAB}20141126T163000Z" \ && echo "Success" \ @@ -109,7 +108,7 @@ "$SHOWMAIL" 1 < out2r.tmp \ > out2p1.tmp -if grep -q "To: $SENDERADDRESS" out2p0.tmp ; then +if grep -q "To: $SENDER2ADDRESS" out2p0.tmp ; then ORGFN=out2p0.tmp ; DELFN=out2p1.tmp else ORGFN=out2p1.tmp ; DELFN=out2p0.tmp @@ -126,7 +125,7 @@ # The other will be a reply to the organiser. - grep -q "To: $SENDERADDRESS" "$ORGFN" \ + grep -q "To: $SENDER2ADDRESS" "$ORGFN" \ && grep -q 'METHOD:REPLY' "$ORGFN" \ && grep -q 'ATTENDEE.*;PARTSTAT=DELEGATED.*:'"$USER1" "$ORGFN" \ && grep -q 'ATTENDEE.*:'"$USER2" "$ORGFN" \ @@ -151,7 +150,7 @@ # Check the quota (event is not confirmed). - "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \ + "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "all" \ > out2e.tmp grep -q "event21@example.com" "out2e.tmp" \ @@ -169,14 +168,14 @@ # Check the free/busy status of the attendees at the organiser. # Currently, neither are attending. - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy_other" "$USER1" \ + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy_other" "$USER1" \ > out3s0.tmp \ ! grep -q "^20141126T153000Z${TAB}20141126T163000Z" out3s0.tmp \ && echo "Success" \ || echo "Failed" - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy_other" "$USER2" \ + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy_other" "$USER2" \ > out3s1.tmp \ ! grep -q "^20141126T153000Z${TAB}20141126T163000Z" out3s1.tmp \ @@ -194,7 +193,7 @@ "$SHOWMAIL" 1 < out4r.tmp \ > out4p1.tmp -if grep -q "To: $SENDERADDRESS" out4p0.tmp ; then +if grep -q "To: $SENDER2ADDRESS" out4p0.tmp ; then ORGFN=out4p0.tmp ; DELFN=out4p1.tmp else ORGFN=out4p1.tmp ; DELFN=out4p0.tmp @@ -202,7 +201,7 @@ # One of the responses will be a reply sent to the organiser. - grep -q "To: $SENDERADDRESS" "$ORGFN" \ + grep -q "To: $SENDER2ADDRESS" "$ORGFN" \ && grep -q 'METHOD:REPLY' "$ORGFN" \ && grep -q 'ATTENDEE.*;PARTSTAT=DELEGATED.*:'"$USER1" "$ORGFN" \ && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED.*:'"$USER2" "$ORGFN" \ @@ -244,14 +243,14 @@ # Check the free/busy status of the attendees at the organiser. # Now, the delegate is attending. - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy_other" "$USER1" \ + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy_other" "$USER1" \ > out5s0.tmp \ ! grep -q "^20141126T153000Z${TAB}20141126T163000Z" out5s0.tmp \ && echo "Success" \ || echo "Failed" - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy_other" "$USER2" \ + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy_other" "$USER2" \ > out5s1.tmp \ grep -q "^20141126T153000Z${TAB}20141126T163000Z" out5s1.tmp \ diff -r 3252084e9608 -r 9cb6a6acfe17 tests/test_resource_invitation_constraints_quota_recurring.sh --- a/tests/test_resource_invitation_constraints_quota_recurring.sh Fri May 13 00:28:46 2016 +0200 +++ b/tests/test_resource_invitation_constraints_quota_recurring.sh Fri May 13 01:10:08 2016 +0200 @@ -16,7 +16,7 @@ # Employ a user-specific quota (no argument with the functions above). -cat < + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from codecs import getreader +from os.path import abspath, split +import sys + +# Find the modules. + +try: + import imiptools +except ImportError: + parent = abspath(split(split(__file__)[0])[0]) + if split(parent)[1] == "imip-agent": + sys.path.append(parent) + +from imiptools import config +from imiptools.stores import get_journal +from imiptools.text import get_table_from_stream + +# Main program. + +if __name__ == "__main__": + + # Interpret the command line arguments. + + args = [] + store_type = [] + journal_dir = [] + + # Collect quota details first, switching to other arguments when encountering + # switches. + + l = args + + for arg in sys.argv[1:]: + if arg == "-T": + l = store_type + elif arg == "-j": + l = journal_dir + else: + l.append(arg) + + try: + quota, = args + except ValueError: + print >>sys.stderr, """\ +Usage: %s [ ] + +Read from standard input a list of user-to-group mappings of the following +form: + + + +For example: + +* all + +The values may be separated using any whitespace characters. + +General options: + +-j Indicates the journal directory location +-T Indicates the store type (the configured value if omitted) +""" % split(sys.argv[0])[1] + sys.exit(1) + + # Override defaults if indicated. + + getvalue = lambda value, default=None: value and value[0] or default + + store_type = getvalue(store_type, config.STORE_TYPE) + journal_dir = getvalue(journal_dir) + + # Obtain store-related objects. + + journal = get_journal(store_type, journal_dir) + f = getreader("utf-8")(sys.stdin) + groups = dict(get_table_from_stream(f, tab_separated=False)) + journal.set_groups(quota, groups) + +# vim: tabstop=4 expandtab shiftwidth=4