misc: add a URL path to go from form in front to the backoffice (#67873)

This commit is contained in:
Frédéric Péters 2022-08-02 11:26:38 +02:00
parent ef4caf1d1e
commit 9a34833f01
3 changed files with 12 additions and 0 deletions

View File

@ -9720,3 +9720,10 @@ def test_user_filter_auto_custom_view(pub):
app = login(get_app(pub), username='foo', password='foo')
resp = app.get(formdef.get_url())
assert [x[2] for x in resp.form['f0'].options] == ['bar', 'foo']
def test_go_to_backoffice(pub):
formdef = create_formdef()
app = get_app(pub)
resp = app.get('/test/go-to-backoffice')
assert resp.location.endswith('/backoffice/forms/%s/' % formdef.id)

View File

@ -94,6 +94,7 @@ class FormFillPage(PublicFormFillPage):
('remove', 'remove_draft'),
'live',
('lateral-block', 'lateral_block'),
('go-to-backoffice', 'go_to_backoffice'),
]
filling_templates = ['wcs/formdata_filling.html']

View File

@ -269,6 +269,7 @@ class FormPage(Directory, FormTemplateMixin):
'code',
'removedraft',
'live',
('go-to-backoffice', 'go_to_backoffice'),
]
do_not_call_in_templates = True
@ -308,6 +309,9 @@ class FormPage(Directory, FormTemplateMixin):
return ApiFormdefDirectory(self.formdef).schema()
def go_to_backoffice(self):
return redirect(self.formdef.get_admin_url())
def check_role(self):
if self.formdef.roles:
if not self.user: