From d026c7c114b4fda8300946e0f5ac4b9dd9053654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 7 Jan 2016 19:00:24 +0100 Subject: [PATCH] forms: keep access to roles that are mentioned in formdef functions (#9545) --- tests/test_backoffice_pages.py | 35 +++++++++++++++++++++++++++++++++-- wcs/formdef.py | 19 +++++++++++++++---- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py index ce61dd3..098b8c8 100644 --- a/tests/test_backoffice_pages.py +++ b/tests/test_backoffice_pages.py @@ -784,9 +784,40 @@ def test_backoffice_submission_dispatch(pub): resp.form['f3'] = 'C' resp = resp.form.submit('submit') # to validation screen resp = resp.form.submit('submit') # final submit - # should go the submission screen + # should go to the formdata because the formdef is defined as is + assert resp.location.startswith('http://example.net/backoffice/management/form-title/') + + # remove function from formdef + formdef.workflow_roles = {} + formdef.store() + + 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') # to validation screen + resp = resp.form.submit('submit') # final submit + # should NOT go to the formdata assert resp.location == 'http://example.net/backoffice/submission/' - resp = resp.follow() + + # if there's no function but the dispatch sets the right function, should + # go to the formdata screen + dispatch.role_id = '1' + wf.store() + + 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') # to validation screen + resp = resp.form.submit('submit') # final submit + # should go to the formdata because the formdata was dispatched to the + # right role + assert resp.location.startswith('http://example.net/backoffice/management/form-title/') def test_backoffice_submission_tracking_code(pub): user = create_user(pub) diff --git a/wcs/formdef.py b/wcs/formdef.py index 18a43b9..2fcb207 100644 --- a/wcs/formdef.py +++ b/wcs/formdef.py @@ -935,17 +935,28 @@ class FormDef(StorableObject): def is_of_concern_for_user(self, user, formdata=None): if not self.workflow_roles: self.workflow_roles = {} - workflow_roles = self.workflow_roles.copy() - if formdata and formdata.workflow_roles: - workflow_roles.update(formdata.workflow_roles) - for role_id in workflow_roles.values(): + + # if the formdef itself has some function attributed to the user, grant + # access. + for role_id in self.workflow_roles.values(): if role_id in (user.roles or []): return True + + # if there was some redispatching of function, values will be different + # in formdata, check them. + if formdata and formdata.workflow_roles: + for role_id in formdata.workflow_roles.values(): + if role_id in (user.roles or []): + return True + + # if no formdata was given, lookup if there are some existing formdata + # where the user has access. if not formdata: data_class = self.data_class() for role_id in user.roles or []: if data_class.get_ids_with_indexed_value('workflow_roles', role_id): return True + return False def is_user_allowed_read(self, user, formdata=None): -- 2.7.0.rc3