From da8fa6f91c1d89969f839c0765f237369149760a Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 10 Sep 2017 20:31:38 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20resolved=20link=20class=20URL=20mangling?= =?UTF-8?q?=20when=20the=20keep=5Fquery=20argument=20is=20used.=20Fixes=20?= =?UTF-8?q?source=20navigation=20on=20the=20document=20upload=20wizard.=20?= =?UTF-8?q?Thanks=20to=20Nick=20Douma=E2=80=82(LordGaav)=20for=20the=20rep?= =?UTF-8?q?ort=20and=20diagnostic=20information.=20GitLab=20issue=20#436.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roberto Rosario --- HISTORY.rst | 3 ++ docs/releases/2.7.3.rst | 6 ++++ mayan/apps/navigation/classes.py | 5 ++- mayan/apps/navigation/tests/literals.py | 3 ++ mayan/apps/navigation/tests/test_classes.py | 40 ++++++++++++++++++++- 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index e4fa62aef7..cd8f05297c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,9 @@ ================== - Fix task manager queue list view. Thanks to LeVon Smoker for the report. +- Fix resolved link class URL mangling when the keep_query argument is + used. Thanks to Nick Douma (LordGaav) for the report and diagnostic + information. Fixes source navigation on the document upload wizard. 2.7.2 (2017-09-06) ================== diff --git a/docs/releases/2.7.3.rst b/docs/releases/2.7.3.rst index fb5249ee1c..c91e569d7b 100644 --- a/docs/releases/2.7.3.rst +++ b/docs/releases/2.7.3.rst @@ -9,6 +9,10 @@ What's new - Fix task manager queue list view. Thanks to LeVon Smoker for the report. +- Fix resolved link class URL mangling when the keep_query argument is + used. Fixes source navigation on the document upload wizard. Thanks to + Nick Douma (LordGaav) for the report and diagnostic information. GitLab + issue #436. Removals -------- @@ -64,5 +68,7 @@ Bugs fixed or issues closed =========================== * `GitLab issue #431 `_ can't create new mailer +* `GitLab issue #436 `_ New document source menu does not contain source_ids + .. _PyPI: https://pypi.python.org/pypi/mayan-edms/ diff --git a/mayan/apps/navigation/classes.py b/mayan/apps/navigation/classes.py index c02c9d1554..424b1a8e64 100644 --- a/mayan/apps/navigation/classes.py +++ b/mayan/apps/navigation/classes.py @@ -363,7 +363,10 @@ class Link(object): except KeyError: pass - resolved_link.url = parsed_url.url + # Use the link's URL but with the previous URL querystring + new_url = furl(resolved_link.url) + new_url.args = parsed_url.querystr + resolved_link.url = new_url.url resolved_link.context = context return resolved_link diff --git a/mayan/apps/navigation/tests/literals.py b/mayan/apps/navigation/tests/literals.py index 3a1059190d..28faabfb90 100644 --- a/mayan/apps/navigation/tests/literals.py +++ b/mayan/apps/navigation/tests/literals.py @@ -7,5 +7,8 @@ TEST_PERMISSION_NAME = 'test permission name' TEST_PERMISSION_LABEL = 'test permission label' TEST_LINK_TEXT = 'test link text' TEST_MENU_NAME = 'menu test' +TEST_QUERYSTRING_ONE_KEY = 'key1=value1' +TEST_QUERYSTRING_TWO_KEYS = 'key1=value1&key2=value2' TEST_SUBMENU_NAME = 'submenu test' TEST_UNICODE_STRING = 'úñí©óðé' +TEST_URL = 'test-URL' diff --git a/mayan/apps/navigation/tests/test_classes.py b/mayan/apps/navigation/tests/test_classes.py index 9825f98766..a626ae76ee 100644 --- a/mayan/apps/navigation/tests/test_classes.py +++ b/mayan/apps/navigation/tests/test_classes.py @@ -15,7 +15,8 @@ from ..classes import Link, Menu from .literals import ( TEST_PERMISSION_NAMESPACE_NAME, TEST_PERMISSION_NAMESPACE_TEXT, TEST_PERMISSION_NAME, TEST_PERMISSION_LABEL, TEST_LINK_TEXT, - TEST_MENU_NAME, TEST_SUBMENU_NAME, TEST_UNICODE_STRING + TEST_MENU_NAME, TEST_QUERYSTRING_ONE_KEY, TEST_QUERYSTRING_TWO_KEYS, + TEST_SUBMENU_NAME, TEST_UNICODE_STRING, TEST_URL ) @@ -115,6 +116,43 @@ class LinkClassTestCase(GenericViewTestCase): self.assertEqual(resolved_link.url, url.url) + def test_link_with_querystring_preservation(self): + previous_url = '{}?{}'.format( + reverse(TEST_VIEW_NAME), TEST_QUERYSTRING_TWO_KEYS + ) + self.link.keep_query = True + self.link.url = TEST_URL + self.link.view = None + response = self.get(path=previous_url) + + context = Context({'request': response.wsgi_request}) + + resolved_link = self.link.resolve(context=context) + + self.assertEqual( + resolved_link.url, + '{}?{}'.format(TEST_URL, TEST_QUERYSTRING_TWO_KEYS) + ) + + def test_link_with_querystring_preservation_with_key_removal(self): + previous_url = '{}?{}'.format( + reverse(TEST_VIEW_NAME), TEST_QUERYSTRING_TWO_KEYS + ) + self.link.keep_query = True + self.link.url = TEST_URL + self.link.view = None + self.link.remove_from_query = ['key2'] + response = self.get(path=previous_url) + + context = Context({'request': response.wsgi_request}) + + resolved_link = self.link.resolve(context=context) + self.assertEqual( + resolved_link.url, + '{}?{}'.format(TEST_URL, TEST_QUERYSTRING_ONE_KEY) + ) + + class MenuClassTestCase(GenericViewTestCase): def setUp(self): super(MenuClassTestCase, self).setUp()