Code

b12c7e6ca0791024e5df3c7da6a2fdc6d301149c
[roundup.git] / templates / classic / detectors / userauditor.py
1 # Copyright (c) 2003 Richard Jones (richard@mechanicalcat.net)
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9 #
10 #   The above copyright notice and this permission notice shall be included in
11 #   all copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
20 #
21 #$Id: userauditor.py,v 1.2 2003-11-11 22:25:37 richard Exp $
23 def audit_user_fields(db, cl, nodeid, newvalues):
24     ''' Make sure user properties are valid.
26         - email address has no spaces in it
27         - roles specified exist
28     '''
29     if newvalues.has_key('address') and ' ' in newvalues['address']:
30         raise ValueError, 'Email address must not contain spaces'
32     if newvalues.has_key('roles'):
33         roles = [x.lower().strip() for x in newvalues['roles'].split(',')]
34         for rolename in roles:
35             if not db.security.role.has_key(rolename):
36                 raise ValueError, 'Role "%s" does not exist'%rolename
39 def init(db):
40     # fire before changes are made
41     db.user.audit('set', audit_user_fields)
42     db.user.audit('create', audit_user_fields)
44 # vim: set filetype=python ts=4 sw=4 et si