From db8da22f6a0187d448548f7064178fe200da68fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 14 May 2017 20:20:01 +0200 Subject: [PATCH] backoffice: keep displaying tracking code to agent for 30 minutes (#14898) --- tests/test_backoffice_pages.py | 52 ++++++++++++++++++++++++++++++++++++++++++ wcs/backoffice/management.py | 9 ++++++++ 2 files changed, 61 insertions(+) diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py index 3ddbd89f..48d48c3c 100644 --- a/tests/test_backoffice_pages.py +++ b/tests/test_backoffice_pages.py @@ -1293,6 +1293,58 @@ def test_backoffice_submission(pub): resp = resp.form.submit('cancel') assert resp.location == 'http://example.net/backoffice/submission/' +def test_backoffice_submission_with_tracking_code(pub): + user = create_user(pub) + create_environment(pub) + + formdef = FormDef.get_by_urlname('form-title') + formdef.backoffice_submission_roles = user.roles[:] + formdef.enable_tracking_codes = True + formdef.store() + + app = login(get_app(pub)) + resp = app.get('/backoffice/submission/') + + resp = resp.click(formdef.name) + resp.form['f1'] = 'test submission' + resp.form['f2'] = 'baz' + resp.form['f3'] = 'C' + resp = resp.form.submit('submit') + assert 'Check values then click submit.' in resp.body + # final submit + validation_resp_body = resp.body + resp = resp.form.submit('submit') + + formdata_no = resp.location.split('/')[-2] + data_class = formdef.data_class() + formdata = data_class.get(formdata_no) + assert formdata.tracking_code in validation_resp_body + + formdata_location = resp.location + resp = resp.follow() # get to the formdata page + # check tracking code is still displayed in formdata page + assert 'test submission' in resp.body + assert formdata.tracking_code in resp.body + + # check access by different user + formdata.submission_context = {'agent_id': '10000'} + formdata.store() + resp = app.get(formdata_location) + assert 'test submission' in resp.body + assert not formdata.tracking_code in resp.body + + # restore user + formdata.submission_context = {'agent_id': user.id} + formdata.store() + resp = app.get(formdata_location) + assert formdata.tracking_code in resp.body + + # check access at a later time + formdata.receipt_time = time.localtime(time.time() - 3600) + formdata.store() + resp = app.get(formdata_location) + assert not formdata.tracking_code in resp.body + def test_backoffice_submission_welco(pub, welco_url): user = create_user(pub) create_environment(pub) diff --git a/wcs/backoffice/management.py b/wcs/backoffice/management.py index 212be849..079b13d8 100644 --- a/wcs/backoffice/management.py +++ b/wcs/backoffice/management.py @@ -1878,6 +1878,15 @@ class FormBackOfficeStatusPage(FormStatusPage): if not formdata.is_draft(): r += htmltext('
') + if (formdata.backoffice_submission and formdata.submission_context and + formdata.submission_context.get('agent_id') == get_request().user.id and + formdata.tracking_code and + time.time() - time.mktime(formdata.receipt_time) < 30*60): + # keep displaying tracking code to submission agent for 30 + # minutes after submission + r += htmltext('

%s

') % _('Tracking Code') + r += htmltext('

%s

') % formdata.tracking_code + r += htmltext('

%s

') % _('General Information') r += htmltext('

') tm = misc.localstrftime(formdata.receipt_time) -- 2.11.0