misc: remove redirection to /category/formdef, handled by w.c.s. (#69546)

This commit is contained in:
Frédéric Péters 2022-10-17 13:04:42 +02:00
parent cacd2bda24
commit efe6c53faf
2 changed files with 1 additions and 113 deletions

View File

@ -288,72 +288,7 @@ class AlternateRootDirectory(OldRootDirectory):
if not self.backoffice:
self.backoffice = get_publisher().backoffice_directory_class()
try:
output = Directory._q_traverse(self, path)
if path and path[0] == 'saml':
return output
return self.automatic_sso(output)
except errors.TraversalError as e:
try:
f = FormDef.get_by_urlname(path[0])
except KeyError:
pass
else:
base_url = get_publisher().get_root_url()
uri_rest = get_request().environ.get('REQUEST_URI')
if not uri_rest:
# REQUEST_URI doesn't exist when using internal HTTP server
# (--http)
uri_rest = urllib.parse.quote(get_request().get_path())
if get_request().get_query():
uri_rest += '?' + get_request().get_query()
if uri_rest.startswith(base_url):
uri_rest = uri_rest[len(base_url) :]
if f.category:
if f.category.url_name == f.url_name:
return FormsRootDirectory(f.category)._q_traverse(path[1:])
return redirect('%s%s/%s' % (base_url, f.category.url_name, uri_rest))
try:
cat = Category.get_by_urlname(path[0])
except KeyError:
pass
else:
if len(path) == 1:
# category with missing trailing slash, redirect.
path = quixote.get_path()
return quixote.redirect(path + "/", permanent=True)
return FormsRootDirectory(cat)._q_traverse(path[1:])
raise e
def _q_lookup(self, component):
# is this a category ?
try:
category = Category.get_by_urlname(component)
except KeyError:
category = None
# is this a formdef ?
try:
formdef = FormDef.get_by_urlname(component)
except KeyError:
if category:
return FormsRootDirectory(category)
else:
# if the form has no category, or the request is a POST, or the
# slug matches both a category and a formdef, directly call
# into FormsRootDirectory.
if formdef.category_id is None or get_request().get_method() == 'POST' or (formdef and category):
get_response().filter['bigdiv'] = 'rub_service'
return FormsRootDirectory()._q_lookup(component)
# if there is category, let it fall back to raise TraversalError,
# it will get caught in _q_traverse that will redirect it to an
# URL embedding the category
return None
return super()._q_traverse(path)
def json(self):
return FormsRootDirectory().json()

View File

@ -159,50 +159,3 @@ def test_form_category_redirection():
assert resp.location.endswith('/baz/')
resp = get_app(pub).get('/baz?test=1')
assert resp.location.endswith('/baz/')
def test_form_and_category_same_slug():
Category.wipe()
cat = Category(name='foobar')
cat.store()
FormDef.wipe()
formdef = FormDef()
formdef.name = 'foobar'
formdef.category_id = cat.id
formdef.fields = []
formdef.store()
# check we get to the form, not the category
resp = get_app(pub).get('/foobar/')
assert resp.form
def test_form_and_category_same_slug2():
Category.wipe()
cat = Category(name='test')
cat.store()
FormDef.wipe()
formdef = FormDef()
formdef.name = 'foobar'
formdef.category_id = cat.id
formdef.fields = []
formdef.store()
formdef = FormDef()
formdef.name = 'test'
formdef.fields = []
formdef.store()
# check we get to the foobar form
resp = get_app(pub).get('/foobar/')
assert resp.location == 'http://example.net/test/foobar/'
resp = resp.follow()
assert resp.form
assert '<h1>foobar</h1>' in resp
# check we get to the test form
resp = get_app(pub).get('/test/')
assert resp.form
assert '<h1>test</h1>' in resp