paul@1028 | 1 | #!/usr/bin/env python |
paul@1028 | 2 | |
paul@1028 | 3 | """ |
paul@1028 | 4 | Access-control-related scheduling functionality. |
paul@1028 | 5 | |
paul@1028 | 6 | Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> |
paul@1028 | 7 | |
paul@1028 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@1028 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@1028 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@1028 | 11 | version. |
paul@1028 | 12 | |
paul@1028 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@1028 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@1028 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@1028 | 16 | details. |
paul@1028 | 17 | |
paul@1028 | 18 | You should have received a copy of the GNU General Public License along with |
paul@1028 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@1028 | 20 | """ |
paul@1028 | 21 | |
paul@1028 | 22 | from imiptools.data import get_address |
paul@1028 | 23 | |
paul@1028 | 24 | def same_domain_only(handler): |
paul@1028 | 25 | |
paul@1028 | 26 | """ |
paul@1028 | 27 | Attempt to schedule the current object of the given 'handler' if the |
paul@1028 | 28 | organiser employs an address in the same domain as the resource. |
paul@1028 | 29 | """ |
paul@1028 | 30 | |
paul@1028 | 31 | organiser = get_address(handler.obj.get_value("ORGANIZER")) |
paul@1028 | 32 | user = get_address(handler.user) |
paul@1028 | 33 | |
paul@1028 | 34 | organiser_domain = organiser.rsplit("@", 1)[-1] |
paul@1028 | 35 | user_domain = user.rsplit("@", 1)[-1] |
paul@1028 | 36 | |
paul@1028 | 37 | return organiser_domain == user_domain and "ACCEPTED" or "DECLINED" |
paul@1028 | 38 | |
paul@1028 | 39 | # Registry of scheduling functions. |
paul@1028 | 40 | |
paul@1028 | 41 | scheduling_functions = { |
paul@1028 | 42 | "same_domain_only" : same_domain_only, |
paul@1028 | 43 | } |
paul@1028 | 44 | |
paul@1028 | 45 | # vim: tabstop=4 expandtab shiftwidth=4 |