misc: allow lowercase letters in tracking codes (#26429)

This commit is contained in:
Frédéric Péters 2018-09-22 12:28:02 +02:00
parent 9a57fd3dab
commit fde53b65d6
3 changed files with 18 additions and 0 deletions

View File

@ -1297,6 +1297,16 @@ def test_form_tracking_code(pub):
resp = resp.forms[0].submit()
assert formdef.data_class().get(formdata_id).evolution[-1].comment == 'hello world'
# check we can also use it with lowercase letters.
# check we can still go back to it
app = get_app(pub)
resp = app.get('/')
resp.forms[0]['code'] = tracking_code.lower()
resp = resp.forms[0].submit()
assert resp.location == 'http://example.net/code/%s/load' % tracking_code.lower()
resp = resp.follow()
assert resp.location == 'http://example.net/test/%s' % formdata_id
def test_form_tracking_code_as_user(pub):
user = create_user(pub)
formdef = create_formdef()

View File

@ -1880,6 +1880,10 @@ class TrackingCode(SqlMixin, wcs.tracking_code.TrackingCode):
id = None
@classmethod
def get(cls, id, **kwargs):
return super(TrackingCode, cls).get(id.upper(), **kwargs)
@guard_postgres
@invalidate_substitution_cache
def store(self):

View File

@ -34,6 +34,10 @@ class TrackingCode(StorableObject):
# self.id set at this point.
pass
@classmethod
def get(cls, id, **kwargs):
return super(TrackingCode, cls).get(id.upper(), **kwargs)
@classmethod
def get_new_id(cls, create=False):
r = random.SystemRandom()