Skip to content

Commit c1fbe45

Browse files
author
Justus Pendleton
committed
Fix [SF#738470]. Validate timezone setting in userauditor
The timezone setting is just a plain string, which was being stored blindly. The problem is that certain parts of the roundup web UI (notably the user details page) try to use, assuming that it is valid. If a user enters garbage then they cannot access their details page (and possibly other parts of roundup) until an admin fixes their timezone for them. During userauditor, we attempt to use the new timezone value and catch any exceptions that may be raised. I posted this patch to roundup-users several days ago and no one screamed. Now that I have commit access I'll check it in. I also noticed that the classic and minimal template userauditors were slightly different in their check for 'roles'. I couldn't discern a reason for the difference so I made them the same. I can change it back if need be.
1 parent 47aa7fc commit c1fbe45

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

templates/classic/detectors/userauditor.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020
#
21-
#$Id: userauditor.py,v 1.3 2006-09-18 03:24:38 tobias-herp Exp $
21+
#$Id: userauditor.py,v 1.4 2007-08-30 00:31:15 jpend Exp $
2222

2323
def audit_user_fields(db, cl, nodeid, newvalues):
2424
''' Make sure user properties are valid.
@@ -35,10 +35,23 @@ def audit_user_fields(db, cl, nodeid, newvalues):
3535
if not db.security.role.has_key(rolename):
3636
raise ValueError, 'Role "%s" does not exist'%rolename
3737

38+
if newvalues.has_key('timezone'):
39+
# validate the timezone by attempting to use it
40+
# before we store it to the db.
41+
import roundup.date
42+
import datetime
43+
try:
44+
tz = newvalues['timezone']
45+
TZ = roundup.date.get_timezone(tz)
46+
dt = datetime.datetime.now()
47+
local = TZ.localize(dt).utctimetuple()
48+
except IOError:
49+
raise ValueError, 'Timezone "%s" does not exist' % tz
50+
except ValueError:
51+
raise ValueError, 'Timezone "%s" exceeds valid range [-23...23]' % tz
3852

3953
def init(db):
4054
# fire before changes are made
4155
db.user.audit('set', audit_user_fields)
42-
db.user.audit('create', audit_user_fields)
43-
56+
db.user.audit('create', audit_user_fields)
4457
# vim: set filetype=python ts=4 sw=4 et si

templates/minimal/detectors/userauditor.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020
#
21-
#$Id: userauditor.py,v 1.2 2003-11-11 22:25:37 richard Exp $
21+
#$Id: userauditor.py,v 1.3 2007-08-30 00:31:16 jpend Exp $
2222

2323
def audit_user_fields(db, cl, nodeid, newvalues):
2424
''' Make sure user properties are valid.
@@ -29,12 +29,26 @@ def audit_user_fields(db, cl, nodeid, newvalues):
2929
if newvalues.has_key('address') and ' ' in newvalues['address']:
3030
raise ValueError, 'Email address must not contain spaces'
3131

32-
if newvalues.has_key('roles'):
32+
if newvalues.has_key('roles') and newvalues['roles']:
3333
roles = [x.lower().strip() for x in newvalues['roles'].split(',')]
3434
for rolename in roles:
3535
if not db.security.role.has_key(rolename):
3636
raise ValueError, 'Role "%s" does not exist'%rolename
3737

38+
if newvalues.has_key('timezone'):
39+
# validate the timezone by attempting to use it
40+
# before we store it to the db
41+
import roundup.date
42+
import datetime
43+
try:
44+
tz = newvalues['timezone']
45+
TZ = roundup.date.get_timezone(tz)
46+
dt = datetime.datetime.now()
47+
local = TZ.localize(dt).utctimetuple()
48+
except IOError:
49+
raise ValueError, 'Timezone "%s" does not exist' % tz
50+
except ValueError:
51+
raise ValueError, 'Timezone "%s" exceeds valid range [-23...23]' % tz
3852

3953
def init(db):
4054
# fire before changes are made

0 commit comments

Comments
 (0)