From bf2f4b9117339d2f592480f026c742f919eea795 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Thu, 19 Sep 2024 22:14:44 +0200 Subject: [PATCH 1/7] fix show_excluded_items in @navigation api --- src/plone/restapi/services/navigation/get.py | 2 +- .../restapi/tests/test_services_navigation.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/plone/restapi/services/navigation/get.py b/src/plone/restapi/services/navigation/get.py index 665f22da01..8ee67df037 100644 --- a/src/plone/restapi/services/navigation/get.py +++ b/src/plone/restapi/services/navigation/get.py @@ -135,7 +135,7 @@ def navtree(self): if brain_parent_path == navtree_path: # This should be already provided by the portal_tabs_view continue - if brain.exclude_from_nav and not context_path.startswith(brain_path): + if brain.exclude_from_nav and not f"{brain_path}/".startswith(f"{context_path}/"): # skip excluded items if they're not in our context path continue url = brain.getURL() diff --git a/src/plone/restapi/tests/test_services_navigation.py b/src/plone/restapi/tests/test_services_navigation.py index dc466bc38e..2a877695c2 100644 --- a/src/plone/restapi/tests/test_services_navigation.py +++ b/src/plone/restapi/tests/test_services_navigation.py @@ -124,6 +124,29 @@ def test_dont_broke_with_contents_without_review_state(self): ) self.assertIsNone(response.json()["items"][1]["items"][3]["review_state"]) + def test_show_exclude_items(self): + createContentInContainer( + self.folder, + "Folder", + id="excluded-subfolder", + title="Excluded SubFolder", + exclude_from_nav=True, + ) + transaction.commit() + response = self.api_session.get( + "/folder/@navigation", params={"expand.navigation.depth": 2} + ) + self.assertNotIn("Excluded SubFolder", [item["title"] for item in response.json()["items"][1]["items"]]) + + registry = getUtility(IRegistry) + settings = registry.forInterface(INavigationSchema, prefix="plone") + settings.show_excluded_items = True + transaction.commit() + response = self.api_session.get( + "/folder/@navigation", params={"expand.navigation.depth": 2} + ) + self.assertIn("Excluded SubFolder", [item["title"] for item in response.json()["items"][1]["items"]]) + def test_navigation_sorting(self): registry = getUtility(IRegistry) registry["plone.displayed_types"] = ( From ec92261573999f34171b0e1fe3c63becc890f4eb Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Thu, 19 Sep 2024 22:22:50 +0200 Subject: [PATCH 2/7] changelog --- news/1816.bugfix | 2 ++ src/plone/restapi/tests/test_services_navigation.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 news/1816.bugfix diff --git a/news/1816.bugfix b/news/1816.bugfix new file mode 100644 index 0000000000..59c24e9c61 --- /dev/null +++ b/news/1816.bugfix @@ -0,0 +1,2 @@ +Fix incorrect condition for show_ecluded_items setting in the @navigation API. +[mamico] diff --git a/src/plone/restapi/tests/test_services_navigation.py b/src/plone/restapi/tests/test_services_navigation.py index 2a877695c2..d45d04a1a2 100644 --- a/src/plone/restapi/tests/test_services_navigation.py +++ b/src/plone/restapi/tests/test_services_navigation.py @@ -136,8 +136,11 @@ def test_show_exclude_items(self): response = self.api_session.get( "/folder/@navigation", params={"expand.navigation.depth": 2} ) - self.assertNotIn("Excluded SubFolder", [item["title"] for item in response.json()["items"][1]["items"]]) - + self.assertNotIn( + "Excluded SubFolder", + [item["title"] for item in response.json()["items"][1]["items"]], + ) + registry = getUtility(IRegistry) settings = registry.forInterface(INavigationSchema, prefix="plone") settings.show_excluded_items = True @@ -145,7 +148,10 @@ def test_show_exclude_items(self): response = self.api_session.get( "/folder/@navigation", params={"expand.navigation.depth": 2} ) - self.assertIn("Excluded SubFolder", [item["title"] for item in response.json()["items"][1]["items"]]) + self.assertIn( + "Excluded SubFolder", + [item["title"] for item in response.json()["items"][1]["items"]], + ) def test_navigation_sorting(self): registry = getUtility(IRegistry) From e2838b009d774f57583031f59c4c297731d113cd Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Thu, 19 Sep 2024 22:36:00 +0200 Subject: [PATCH 3/7] black --- .python-version | 2 +- src/plone/restapi/services/navigation/get.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.python-version b/.python-version index e4fba21835..cc1923a40b 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.12 +3.8 diff --git a/src/plone/restapi/services/navigation/get.py b/src/plone/restapi/services/navigation/get.py index 8ee67df037..a21a52abe4 100644 --- a/src/plone/restapi/services/navigation/get.py +++ b/src/plone/restapi/services/navigation/get.py @@ -135,7 +135,9 @@ def navtree(self): if brain_parent_path == navtree_path: # This should be already provided by the portal_tabs_view continue - if brain.exclude_from_nav and not f"{brain_path}/".startswith(f"{context_path}/"): + if brain.exclude_from_nav and not f"{brain_path}/".startswith( + f"{context_path}/" + ): # skip excluded items if they're not in our context path continue url = brain.getURL() From 7230c82160b8f7a21e3885944f12111049233a61 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Thu, 19 Sep 2024 22:39:58 +0200 Subject: [PATCH 4/7] revert pyenv --- .python-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.python-version b/.python-version index cc1923a40b..e4fba21835 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.8 +3.12 From 0d267e1bfeb8fe035c34ac85ddda2600f1f2f647 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Fri, 20 Sep 2024 08:19:41 +0200 Subject: [PATCH 5/7] typo Co-authored-by: Steve Piercy --- src/plone/restapi/tests/test_services_navigation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plone/restapi/tests/test_services_navigation.py b/src/plone/restapi/tests/test_services_navigation.py index d45d04a1a2..8a4d743798 100644 --- a/src/plone/restapi/tests/test_services_navigation.py +++ b/src/plone/restapi/tests/test_services_navigation.py @@ -124,7 +124,7 @@ def test_dont_broke_with_contents_without_review_state(self): ) self.assertIsNone(response.json()["items"][1]["items"][3]["review_state"]) - def test_show_exclude_items(self): + def test_show_excluded_items(self): createContentInContainer( self.folder, "Folder", From b8dafc9162c9397e35f935e4fad4bde4cd8bafef Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Fri, 20 Sep 2024 08:20:04 +0200 Subject: [PATCH 6/7] Update 1816.bugfix Co-authored-by: Steve Piercy --- news/1816.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/1816.bugfix b/news/1816.bugfix index 59c24e9c61..2bb52fc581 100644 --- a/news/1816.bugfix +++ b/news/1816.bugfix @@ -1,2 +1,2 @@ -Fix incorrect condition for show_ecluded_items setting in the @navigation API. +Fix incorrect condition for ``show_excluded_items`` setting in the ``@navigation`` API. [mamico] From 6dcf4fe01bbd6a984a6553c58f7fbceb1a311f6b Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Fri, 20 Sep 2024 12:56:44 +0200 Subject: [PATCH 7/7] fix tests --- src/plone/restapi/tests/test_services_navigation.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/plone/restapi/tests/test_services_navigation.py b/src/plone/restapi/tests/test_services_navigation.py index 8a4d743798..890c5c1220 100644 --- a/src/plone/restapi/tests/test_services_navigation.py +++ b/src/plone/restapi/tests/test_services_navigation.py @@ -125,6 +125,13 @@ def test_dont_broke_with_contents_without_review_state(self): self.assertIsNone(response.json()["items"][1]["items"][3]["review_state"]) def test_show_excluded_items(self): + registry = getUtility(IRegistry) + settings = registry.forInterface(INavigationSchema, prefix="plone") + + # Plone 5.2 and Plone 6.0 have different default values: + # False for Plone 6.0 and True for Plone 5.2 + # explicitly set the value to False to avoid test failures + settings.show_excluded_items = False createContentInContainer( self.folder, "Folder", @@ -141,6 +148,7 @@ def test_show_excluded_items(self): [item["title"] for item in response.json()["items"][1]["items"]], ) + # change setting to show excluded items registry = getUtility(IRegistry) settings = registry.forInterface(INavigationSchema, prefix="plone") settings.show_excluded_items = True