0001-backoffice-add-support-for-a-return-URL-after-submis.patch
tests/test_backoffice_pages.py | ||
---|---|---|
1633 | 1633 |
assert pq('#steps li.current .label').text() == '1st PAGE' |
1634 | 1634 |
assert 'Field on 1st page' in resp.body # and in fields |
1635 | 1635 | |
1636 |
def test_backoffice_submission_with_return_url(pub): |
|
1637 |
user = create_user(pub) |
|
1638 |
create_environment(pub) |
|
1639 | ||
1640 |
formdef = FormDef.get_by_urlname('form-title') |
|
1641 |
formdef.backoffice_submission_roles = user.roles[:] |
|
1642 |
formdef.enable_tracking_codes = True |
|
1643 |
formdef.store() |
|
1644 | ||
1645 |
app = login(get_app(pub)) |
|
1646 |
resp = app.get('/backoffice/submission/form-title/?ReturnURL=https://example.org') |
|
1647 |
resp = resp.follow().follow() |
|
1648 |
resp = resp.form.submit('cancel') |
|
1649 |
assert resp.location == 'https://example.org' |
|
1650 | ||
1651 |
resp = app.get('/backoffice/submission/form-title/?ReturnURL=https://example.org') |
|
1652 |
resp = resp.follow().follow() |
|
1653 |
resp.form['f1'] = 'test submission' |
|
1654 |
resp.form['f2'] = 'baz' |
|
1655 |
resp.form['f3'] = 'C' |
|
1656 |
resp = resp.form.submit('submit') # -> to validation |
|
1657 |
resp = resp.form.submit('submit') # -> to submit |
|
1658 |
assert resp.location.startswith('http://example.net/backoffice/management/form-title/') |
|
1659 | ||
1660 |
# test submission when agent is not receiver |
|
1661 |
formdef.workflow_roles = {} |
|
1662 |
formdef.store() |
|
1663 |
resp = app.get('/backoffice/submission/form-title/?ReturnURL=https://example.org') |
|
1664 |
resp = resp.follow().follow() |
|
1665 |
resp.form['f1'] = 'test submission' |
|
1666 |
resp.form['f2'] = 'baz' |
|
1667 |
resp.form['f3'] = 'C' |
|
1668 |
resp = resp.form.submit('submit') # -> to validation |
|
1669 |
resp = resp.form.submit('submit') # -> to submit |
|
1670 |
assert resp.location == 'https://example.org' |
|
1671 | ||
1636 | 1672 |
def test_backoffice_parallel_submission(pub): |
1637 | 1673 |
user = create_user(pub) |
1638 | 1674 |
create_environment(pub) |
wcs/backoffice/submission.py | ||
---|---|---|
87 | 87 |
self.remove_draft = RemoveDraftDirectory(self) |
88 | 88 | |
89 | 89 |
def _q_index(self, *args, **kwargs): |
90 |
# if NameID or channel are in query string, create a new draft with
|
|
91 |
# these parameters, and redirect to it |
|
90 |
# if NameID, return URL or submission channel are in query string,
|
|
91 |
# create a new draft with these parameters, and redirect to it
|
|
92 | 92 |
submission_channel = get_request().form.get('channel') |
93 | 93 |
name_id = get_request().form.get('NameID') |
94 |
if name_id or submission_channel: |
|
94 |
return_url = get_request().form.get('ReturnURL') |
|
95 |
if name_id or submission_channel or return_url: |
|
95 | 96 |
formdata = self.formdef.data_class()() |
96 | 97 |
formdata.data = {} |
97 | 98 |
formdata.backoffice_submission = True |
... | ... | |
103 | 104 |
users = list(get_publisher().user_class.get_users_with_name_identifier(name_id)) |
104 | 105 |
if users: |
105 | 106 |
formdata.user_id = users[0].id |
107 |
if return_url: |
|
108 |
formdata.submission_context['return_url'] = return_url |
|
106 | 109 |
formdata.store() |
107 | 110 |
self.set_tracking_code(formdata) |
108 | 111 |
return redirect('%s' % formdata.id) |
... | ... | |
220 | 223 | |
221 | 224 |
if not self.formdef.is_of_concern_for_user(self.user, filled): |
222 | 225 |
# if the agent is not allowed to see the submitted formdef, |
223 |
# redirect to the submission homepage |
|
224 |
return redirect(get_publisher().get_backoffice_url() + '/submission/') |
|
226 |
# redirect to the defined return URL or to the submission |
|
227 |
# homepage |
|
228 |
if filled.submission_context.get('return_url'): |
|
229 |
url = filled.submission_context['return_url'] |
|
230 |
else: |
|
231 |
url = get_publisher().get_backoffice_url() + '/submission/' |
|
232 | ||
233 |
return redirect(url) |
|
225 | 234 | |
235 |
def cancelled(self): |
|
236 |
url = get_publisher().get_backoffice_url() + '/submission/' |
|
237 |
formdata = self.get_current_draft() or self.formdef.data_class()() |
|
238 |
if formdata.submission_context and formdata.submission_context.get('return_url'): |
|
239 |
url = formdata.submission_context.get('return_url') |
|
240 |
if formdata.id: |
|
241 |
formdata.remove_self() |
|
226 | 242 |
return redirect(url) |
227 | 243 | |
228 | 244 |
def save_draft(self, data, page_no): |
wcs/forms/root.py | ||
---|---|---|
686 | 686 |
return redirect(cancelurl) |
687 | 687 |
except KeyError: |
688 | 688 |
pass |
689 |
if get_request().is_in_backoffice(): |
|
690 |
return redirect(get_publisher().get_backoffice_url() + '/submission/') |
|
691 |
return redirect(get_publisher().get_root_url()) |
|
689 |
return self.cancelled() |
|
692 | 690 | |
693 | 691 |
try: |
694 | 692 |
step = int(form.get_widget('step').parse()) |
... | ... | |
1127 | 1125 |
url = filled.get_url() |
1128 | 1126 |
return redirect(url) |
1129 | 1127 | |
1128 |
def cancelled(self): |
|
1129 |
return redirect(get_publisher().get_root_url()) |
|
1130 | ||
1130 | 1131 |
def set_tracking_code(self, formdata, magictoken_data=None): |
1131 | 1132 |
if not self.has_draft_support(): |
1132 | 1133 |
return |
1133 |
- |