From efe6c53faffafd77527caf89833e6139cae6963b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Mon, 17 Oct 2022 13:04:42 +0200
Subject: [PATCH] misc: remove redirection to /category/formdef, handled by
 w.c.s. (#69546)

---
 auquotidien/modules/root.py | 67 +------------------------------------
 tests/test_user_pages.py    | 47 --------------------------
 2 files changed, 1 insertion(+), 113 deletions(-)

diff --git a/auquotidien/modules/root.py b/auquotidien/modules/root.py
index 945354e..0af59e9 100644
--- a/auquotidien/modules/root.py
+++ b/auquotidien/modules/root.py
@@ -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()
diff --git a/tests/test_user_pages.py b/tests/test_user_pages.py
index b7e6783..2f7eb48 100644
--- a/tests/test_user_pages.py
+++ b/tests/test_user_pages.py
@@ -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
-- 
2.37.2

