Roundup Tracker - Issues

Issue 2551128

classification
Impossible to validate a user with unknown timezone
Type: crash Severity: major
Components: Web interface Versions: 2.0.0
process
Status: fixed fixed
:
: rouilj : ced, rouilj
Priority: normal : patch

Created on 2021-04-16 07:13 by ced, last changed 2021-04-18 21:53 by rouilj.

Files
File name Uploaded Description Edit Remove
roundup-pytz-keyerror.patch ced, 2021-04-16 07:13
Messages
msg7198 Author: [hidden] (ced) Date: 2021-04-16 07:13
We got this problem reported by a user: https://discuss.tryton.org/t/unable-to-activate-account-on-roundup/4068

We have pytz installed so I found that date.get_timezone raise UnknownTimeZoneError when pytz is called with unknown timezone but Database.getUserTimezone catch only KeyError.

Here is a patch that makes it raise KeyError as expected.
msg7202 Author: [hidden] (rouilj) Date: 2021-04-18 21:53
Hi Cedric:

Thanks for the patch I created  test and applied it in
rev 6380:d76291836523.

You might want to consider using a select box for setting the
timezone.

This tal uses a couple of utility functions utils.UsingPytz and 
utils.GetCommonTZ to provide a text entry box if not using Pytz
or to provide a select input with a list of all recognized
timezones.

    <tal:block tal:condition="python:(context.is_edit_ok() or
                              context.timezone) and
                              not utils.UsingPytz()">
      <input name="timezone" metal:use-macro="normal_input">
    </tal:block>
    <tal:subif condition="python:utils.UsingPytz()">
      <tal:span tal:condition="python: not context.is_edit_ok()"
                tal:content="context/timezone"></tal:span>
      <select tal:condition="python:context.is_edit_ok()"
              id="timezone" name="timezone">
        <option value="0">- no selection -</option>
        <tal:block tal:repeat="tz python:utils.GetCommonTz()">
          <option tal:attributes="value tz; selected python:tz == 
context.timezone"
                  tal:content="tz"></option>
        </tal:block>
      </select>
    </tal:subif>

and the helper functions:

def using_pytz():
    try:
        import pytz
        return True
    except:
        return False

def get_common_tz():
    if using_pytz():
        import pytz
        return pytz.common_timezones


instance.registerUtil('UsingPytz', using_pytz)
instance.registerUtil('GetCommonTz', get_common_tz)

You can see it in context at:

  https://rouilj.dynamic-dns.net/fossil/roundup_sysadmin/file?
name=extensions/time.py&ci=tip

and

   https://rouilj.dynamic-dns.net/fossil/roundup_sysadmin/file?
ci=tip&name=html/user.item.html&txt=1&ln=119-144
History
Date User Action Args
2021-04-18 21:53:08rouiljsetstatus: new -> fixed
title: Impossible to validate a user with unknonw timezone -> Impossible to validate a user with unknown timezone
nosy: + rouilj
messages: + msg7202
assignee: rouilj
resolution: fixed
2021-04-16 07:13:50cedcreate