misc: don't get into category path if a formdef exists with the slug (#25450)

This commit is contained in:
Frédéric Péters 2018-07-24 10:13:45 +02:00
parent f16a818697
commit f45129a759
2 changed files with 17 additions and 1 deletions

View File

@ -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

View File

@ -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)