1.1 --- a/imiptools/handlers/scheduling/quota.py Fri May 13 00:28:46 2016 +0200
1.2 +++ b/imiptools/handlers/scheduling/quota.py Fri May 13 01:10:08 2016 +0200
1.3 @@ -130,7 +130,7 @@
1.4 journal = handler.get_journal()
1.5 groups = journal.get_groups(quota)
1.6
1.7 - return quota, groups.get(organiser) or organiser
1.8 + return quota, groups.get(organiser) or groups.get("*") or organiser
1.9
1.10 def _get_duration(handler):
1.11
1.12 @@ -372,11 +372,13 @@
1.13 confirmation_functions = {
1.14 "check_quota" : add_to_quota,
1.15 "schedule_across_quota" : add_to_quota_freebusy,
1.16 + "schedule_for_delegate" : add_to_quota,
1.17 }
1.18
1.19 retraction_functions = {
1.20 "check_quota" : remove_from_quota,
1.21 "schedule_across_quota" : remove_from_quota_freebusy,
1.22 + "schedule_for_delegate" : remove_from_quota,
1.23 }
1.24
1.25 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/tests/common.sh Fri May 13 00:28:46 2016 +0200
2.2 +++ b/tests/common.sh Fri May 13 01:10:08 2016 +0200
2.3 @@ -24,8 +24,11 @@
2.4 SET_DELEGATES="$BASE_DIR/tools/set_delegates.py"
2.5 SET_DELEGATES_ARGS="-T $STORE_TYPE -j $JOURNAL"
2.6
2.7 -SET_QUOTA_LIMIT="$BASE_DIR/tools/set_quota_limits.py"
2.8 -SET_QUOTA_LIMIT_ARGS="-T $STORE_TYPE -j $JOURNAL"
2.9 +SET_QUOTA_GROUPS="$BASE_DIR/tools/set_quota_groups.py"
2.10 +SET_QUOTA_GROUPS_ARGS="-T $STORE_TYPE -j $JOURNAL"
2.11 +
2.12 +SET_QUOTA_LIMITS="$BASE_DIR/tools/set_quota_limits.py"
2.13 +SET_QUOTA_LIMITS_ARGS="-T $STORE_TYPE -j $JOURNAL"
2.14
2.15 TAB=`printf '\t'`
2.16
3.1 --- a/tests/templates/event-request-car-delegating.txt Fri May 13 00:28:46 2016 +0200
3.2 +++ b/tests/templates/event-request-car-delegating.txt Fri May 13 01:10:08 2016 +0200
3.3 @@ -1,6 +1,6 @@
3.4 Content-Type: multipart/alternative; boundary="===============0047278175=="
3.5 MIME-Version: 1.0
3.6 -From: paul.boddie@example.com
3.7 +From: vincent.vole@example.com
3.8 To: resource-car-porsche911@example.com
3.9 Subject: Invitation!
3.10
3.11 @@ -20,8 +20,8 @@
3.12 METHOD:REQUEST
3.13 VERSION:2.0
3.14 BEGIN:VEVENT
3.15 -ORGANIZER:mailto:paul.boddie@example.com
3.16 -ATTENDEE;ROLE=CHAIR:mailto:paul.boddie@example.com
3.17 +ORGANIZER:mailto:vincent.vole@example.com
3.18 +ATTENDEE;ROLE=CHAIR:mailto:vincent.vole@example.com
3.19 ATTENDEE;RSVP=TRUE:mailto:resource-car-porsche911@example.com
3.20 DTSTAMP:20141125T004600Z
3.21 DTSTART;TZID=Europe/Oslo:20141126T163000
4.1 --- a/tests/test_resource_invitation_constraints_quota.sh Fri May 13 00:28:46 2016 +0200
4.2 +++ b/tests/test_resource_invitation_constraints_quota.sh Fri May 13 01:10:08 2016 +0200
4.3 @@ -24,10 +24,10 @@
4.4 check_quota $QUOTA
4.5 EOF
4.6
4.7 -cat <<EOF | "$SET_QUOTA_LIMIT" "$QUOTA" $SET_QUOTA_LIMIT_ARGS
4.8 +cat <<EOF | "$SET_QUOTA_LIMITS" "$QUOTA" $SET_QUOTA_LIMITS_ARGS
4.9 * PT1H
4.10 EOF
4.11 -cat <<EOF | "$SET_QUOTA_LIMIT" "$OTHER_QUOTA" $SET_QUOTA_LIMIT_ARGS
4.12 +cat <<EOF | "$SET_QUOTA_LIMITS" "$OTHER_QUOTA" $SET_QUOTA_LIMITS_ARGS
4.13 * PT1H
4.14 EOF
4.15
4.16 @@ -117,7 +117,7 @@
4.17
4.18 # Increase the quota.
4.19
4.20 -cat <<EOF | "$SET_QUOTA_LIMIT" "$QUOTA" $SET_QUOTA_LIMIT_ARGS
4.21 +cat <<EOF | "$SET_QUOTA_LIMITS" "$QUOTA" $SET_QUOTA_LIMITS_ARGS
4.22 * PT2H
4.23 EOF
4.24
4.25 @@ -321,7 +321,7 @@
4.26
4.27 # Increase the quota.
4.28
4.29 -cat <<EOF | "$SET_QUOTA_LIMIT" "$QUOTA" $SET_QUOTA_LIMIT_ARGS
4.30 +cat <<EOF | "$SET_QUOTA_LIMITS" "$QUOTA" $SET_QUOTA_LIMITS_ARGS
4.31 * PT3H
4.32 EOF
4.33
5.1 --- a/tests/test_resource_invitation_constraints_quota_delegation.sh Fri May 13 00:28:46 2016 +0200
5.2 +++ b/tests/test_resource_invitation_constraints_quota_delegation.sh Fri May 13 01:10:08 2016 +0200
5.3 @@ -4,10 +4,12 @@
5.4
5.5 USER1="mailto:resource-car-porsche911@example.com"
5.6 USER2="mailto:resource-car-fiat500@example.com"
5.7 -SENDER="mailto:paul.boddie@example.com"
5.8 +SENDER1="mailto:paul.boddie@example.com"
5.9 +SENDER2="mailto:vincent.vole@example.com"
5.10 USER1ADDRESS="resource-car-porsche911@example.com"
5.11 USER2ADDRESS="resource-car-fiat500@example.com"
5.12 -SENDERADDRESS="paul.boddie@example.com"
5.13 +SENDER1ADDRESS="paul.boddie@example.com"
5.14 +SENDER2ADDRESS="vincent.vole@example.com"
5.15 QUOTA=cars
5.16 OTHER_QUOTA=rooms
5.17
5.18 @@ -17,7 +19,6 @@
5.19 cat > "$PREFS/$USER1/scheduling_function" <<EOF
5.20 schedule_for_delegate $QUOTA
5.21 schedule_in_freebusy
5.22 -check_quota $QUOTA
5.23 EOF
5.24
5.25 mkdir -p "$PREFS/$USER2"
5.26 @@ -26,14 +27,12 @@
5.27 cat > "$PREFS/$USER2/scheduling_function" <<EOF
5.28 schedule_for_delegate $QUOTA
5.29 schedule_in_freebusy
5.30 -check_quota $QUOTA
5.31 EOF
5.32
5.33 -cat <<EOF | "$SET_QUOTA_LIMIT" "$QUOTA" $SET_QUOTA_LIMIT_ARGS
5.34 -* PT2H
5.35 -EOF
5.36 -cat <<EOF | "$SET_QUOTA_LIMIT" "$OTHER_QUOTA" $SET_QUOTA_LIMIT_ARGS
5.37 -* PT2H
5.38 +# Have a common group for all organisers when scheduling.
5.39 +
5.40 +cat <<EOF | "$SET_QUOTA_GROUPS" "$QUOTA" $SET_QUOTA_GROUPS_ARGS
5.41 +* all
5.42 EOF
5.43
5.44 # Allow cars to delegate to each other.
5.45 @@ -56,7 +55,7 @@
5.46
5.47 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR
5.48
5.49 - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \
5.50 + "$LIST_SCRIPT" $LIST_ARGS "$SENDER1" "freebusy" \
5.51 | tee out0s.tmp \
5.52 | grep -q "^20141126T150000Z${TAB}20141126T160000Z" \
5.53 && echo "Success" \
5.54 @@ -82,7 +81,7 @@
5.55
5.56 # Check the quota (event is confirmed).
5.57
5.58 - "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \
5.59 + "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "all" \
5.60 | tee out1e.tmp \
5.61 | grep -q "event21@example.com" \
5.62 && echo "Success" \
5.63 @@ -92,7 +91,7 @@
5.64
5.65 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-delegating.txt" 2>> $ERROR
5.66
5.67 - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \
5.68 + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy" \
5.69 | tee out1s.tmp \
5.70 | grep -q "^20141126T153000Z${TAB}20141126T163000Z" \
5.71 && echo "Success" \
5.72 @@ -109,7 +108,7 @@
5.73 "$SHOWMAIL" 1 < out2r.tmp \
5.74 > out2p1.tmp
5.75
5.76 -if grep -q "To: $SENDERADDRESS" out2p0.tmp ; then
5.77 +if grep -q "To: $SENDER2ADDRESS" out2p0.tmp ; then
5.78 ORGFN=out2p0.tmp ; DELFN=out2p1.tmp
5.79 else
5.80 ORGFN=out2p1.tmp ; DELFN=out2p0.tmp
5.81 @@ -126,7 +125,7 @@
5.82
5.83 # The other will be a reply to the organiser.
5.84
5.85 - grep -q "To: $SENDERADDRESS" "$ORGFN" \
5.86 + grep -q "To: $SENDER2ADDRESS" "$ORGFN" \
5.87 && grep -q 'METHOD:REPLY' "$ORGFN" \
5.88 && grep -q 'ATTENDEE.*;PARTSTAT=DELEGATED.*:'"$USER1" "$ORGFN" \
5.89 && grep -q 'ATTENDEE.*:'"$USER2" "$ORGFN" \
5.90 @@ -151,7 +150,7 @@
5.91
5.92 # Check the quota (event is not confirmed).
5.93
5.94 - "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \
5.95 + "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "all" \
5.96 > out2e.tmp
5.97
5.98 grep -q "event21@example.com" "out2e.tmp" \
5.99 @@ -169,14 +168,14 @@
5.100 # Check the free/busy status of the attendees at the organiser.
5.101 # Currently, neither are attending.
5.102
5.103 - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy_other" "$USER1" \
5.104 + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy_other" "$USER1" \
5.105 > out3s0.tmp \
5.106
5.107 ! grep -q "^20141126T153000Z${TAB}20141126T163000Z" out3s0.tmp \
5.108 && echo "Success" \
5.109 || echo "Failed"
5.110
5.111 - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy_other" "$USER2" \
5.112 + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy_other" "$USER2" \
5.113 > out3s1.tmp \
5.114
5.115 ! grep -q "^20141126T153000Z${TAB}20141126T163000Z" out3s1.tmp \
5.116 @@ -194,7 +193,7 @@
5.117 "$SHOWMAIL" 1 < out4r.tmp \
5.118 > out4p1.tmp
5.119
5.120 -if grep -q "To: $SENDERADDRESS" out4p0.tmp ; then
5.121 +if grep -q "To: $SENDER2ADDRESS" out4p0.tmp ; then
5.122 ORGFN=out4p0.tmp ; DELFN=out4p1.tmp
5.123 else
5.124 ORGFN=out4p1.tmp ; DELFN=out4p0.tmp
5.125 @@ -202,7 +201,7 @@
5.126
5.127 # One of the responses will be a reply sent to the organiser.
5.128
5.129 - grep -q "To: $SENDERADDRESS" "$ORGFN" \
5.130 + grep -q "To: $SENDER2ADDRESS" "$ORGFN" \
5.131 && grep -q 'METHOD:REPLY' "$ORGFN" \
5.132 && grep -q 'ATTENDEE.*;PARTSTAT=DELEGATED.*:'"$USER1" "$ORGFN" \
5.133 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED.*:'"$USER2" "$ORGFN" \
5.134 @@ -244,14 +243,14 @@
5.135 # Check the free/busy status of the attendees at the organiser.
5.136 # Now, the delegate is attending.
5.137
5.138 - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy_other" "$USER1" \
5.139 + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy_other" "$USER1" \
5.140 > out5s0.tmp \
5.141
5.142 ! grep -q "^20141126T153000Z${TAB}20141126T163000Z" out5s0.tmp \
5.143 && echo "Success" \
5.144 || echo "Failed"
5.145
5.146 - "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy_other" "$USER2" \
5.147 + "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy_other" "$USER2" \
5.148 > out5s1.tmp \
5.149
5.150 grep -q "^20141126T153000Z${TAB}20141126T163000Z" out5s1.tmp \
6.1 --- a/tests/test_resource_invitation_constraints_quota_recurring.sh Fri May 13 00:28:46 2016 +0200
6.2 +++ b/tests/test_resource_invitation_constraints_quota_recurring.sh Fri May 13 01:10:08 2016 +0200
6.3 @@ -16,7 +16,7 @@
6.4
6.5 # Employ a user-specific quota (no argument with the functions above).
6.6
6.7 -cat <<EOF | "$SET_QUOTA_LIMIT" "$QUOTA" $SET_QUOTA_LIMIT_ARGS
6.8 +cat <<EOF | "$SET_QUOTA_LIMITS" "$QUOTA" $SET_QUOTA_LIMITS_ARGS
6.9 * PT10H
6.10 EOF
6.11
7.1 --- a/tests/test_resource_invitation_constraints_quota_recurring_limits.sh Fri May 13 00:28:46 2016 +0200
7.2 +++ b/tests/test_resource_invitation_constraints_quota_recurring_limits.sh Fri May 13 01:10:08 2016 +0200
7.3 @@ -26,7 +26,7 @@
7.4 check_quota $QUOTA
7.5 EOF
7.6
7.7 -cat <<EOF | "$SET_QUOTA_LIMIT" "$QUOTA" $SET_QUOTA_LIMIT_ARGS
7.8 +cat <<EOF | "$SET_QUOTA_LIMITS" "$QUOTA" $SET_QUOTA_LIMITS_ARGS
7.9 mailto:vincent.vole@example.com PT10H
7.10 * PT5H
7.11 EOF
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/tools/set_quota_groups.py Fri May 13 01:10:08 2016 +0200
8.3 @@ -0,0 +1,100 @@
8.4 +#!/usr/bin/env python
8.5 +
8.6 +"""
8.7 +Set a mapping of users to groups for a quota.
8.8 +
8.9 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
8.10 +
8.11 +This program is free software; you can redistribute it and/or modify it under
8.12 +the terms of the GNU General Public License as published by the Free Software
8.13 +Foundation; either version 3 of the License, or (at your option) any later
8.14 +version.
8.15 +
8.16 +This program is distributed in the hope that it will be useful, but WITHOUT
8.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
8.19 +details.
8.20 +
8.21 +You should have received a copy of the GNU General Public License along with
8.22 +this program. If not, see <http://www.gnu.org/licenses/>.
8.23 +"""
8.24 +
8.25 +from codecs import getreader
8.26 +from os.path import abspath, split
8.27 +import sys
8.28 +
8.29 +# Find the modules.
8.30 +
8.31 +try:
8.32 + import imiptools
8.33 +except ImportError:
8.34 + parent = abspath(split(split(__file__)[0])[0])
8.35 + if split(parent)[1] == "imip-agent":
8.36 + sys.path.append(parent)
8.37 +
8.38 +from imiptools import config
8.39 +from imiptools.stores import get_journal
8.40 +from imiptools.text import get_table_from_stream
8.41 +
8.42 +# Main program.
8.43 +
8.44 +if __name__ == "__main__":
8.45 +
8.46 + # Interpret the command line arguments.
8.47 +
8.48 + args = []
8.49 + store_type = []
8.50 + journal_dir = []
8.51 +
8.52 + # Collect quota details first, switching to other arguments when encountering
8.53 + # switches.
8.54 +
8.55 + l = args
8.56 +
8.57 + for arg in sys.argv[1:]:
8.58 + if arg == "-T":
8.59 + l = store_type
8.60 + elif arg == "-j":
8.61 + l = journal_dir
8.62 + else:
8.63 + l.append(arg)
8.64 +
8.65 + try:
8.66 + quota, = args
8.67 + except ValueError:
8.68 + print >>sys.stderr, """\
8.69 +Usage: %s <quota> [ <options> ]
8.70 +
8.71 +Read from standard input a list of user-to-group mappings of the following
8.72 +form:
8.73 +
8.74 +<user> <user or group>
8.75 +
8.76 +For example:
8.77 +
8.78 +* all
8.79 +
8.80 +The values may be separated using any whitespace characters.
8.81 +
8.82 +General options:
8.83 +
8.84 +-j Indicates the journal directory location
8.85 +-T Indicates the store type (the configured value if omitted)
8.86 +""" % split(sys.argv[0])[1]
8.87 + sys.exit(1)
8.88 +
8.89 + # Override defaults if indicated.
8.90 +
8.91 + getvalue = lambda value, default=None: value and value[0] or default
8.92 +
8.93 + store_type = getvalue(store_type, config.STORE_TYPE)
8.94 + journal_dir = getvalue(journal_dir)
8.95 +
8.96 + # Obtain store-related objects.
8.97 +
8.98 + journal = get_journal(store_type, journal_dir)
8.99 + f = getreader("utf-8")(sys.stdin)
8.100 + groups = dict(get_table_from_stream(f, tab_separated=False))
8.101 + journal.set_groups(quota, groups)
8.102 +
8.103 +# vim: tabstop=4 expandtab shiftwidth=4