imip-agent

imiptools/handlers/scheduling/access.py

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