From c97e9e84c02085b525e822aefa6c07b82fe751c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 24 Jul 2018 10:13:45 +0200 Subject: [PATCH] misc: don't get into category path if a formdef exists with the slug (#25450) --- tests/test_form_pages.py | 11 +++++++++++ wcs/root.py | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index 1a8145b8..1121782e 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -4992,3 +4992,14 @@ def test_manager_public_access(pub): formdata.store() resp = app.get(formdata.get_url()) assert 'The form has been recorded' in resp.body + +def test_form_and_category_same_slug(pub): + FormDef.wipe() + formdef = FormDef() + formdef.name = 'foobar' + formdef.fields = [] + formdef.store() + + # check we get to the form, not the category + resp = get_app(pub).get('/foobar/') + assert resp.form diff --git a/wcs/root.py b/wcs/root.py index a59cc490..d7481180 100644 --- a/wcs/root.py +++ b/wcs/root.py @@ -39,6 +39,7 @@ import qommon.pages from qommon.afterjobs import AfterJobStatusDirectory from categories import Category +from formdef import FormDef from data_sources import NamedDataSource from wscalls import NamedWsCall from wcs.api import ApiDirectory @@ -342,7 +343,11 @@ class RootDirectory(Directory): except KeyError: pass else: - return forms.root.RootDirectory(category) + # redirect to category if there's not a formdef with same slug + try: + formdef = FormDef.get_by_urlname(component) + except KeyError: + return forms.root.RootDirectory(category) # or a form ? return forms.root.RootDirectory()._q_lookup(component) -- 2.18.0