-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathlast_commit.txt
27 lines (16 loc) · 3.74 KB
/
last_commit.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Repository: plone.restapi
Branch: refs/heads/main
Date: 2025-01-21T19:14:39-08:00
Author: Mauro Amico (mamico) <mauro.amico@gmail.com>
Commit: https://github.com/plone/plone.restapi/commit/5a120c416db8bbd6168fc8c10fdf1ef75e5eac62
fix: contextnavigation when a file has an unknown type (#1864)
* fix: contextnavigation when a file has an unknown type
* changelog
* Update news/1864.bugfix
---------
Co-authored-by: David Glick <david@glicksoftware.com>
Files changed:
A news/1864.bugfix
M src/plone/restapi/services/contextnavigation/get.py
M src/plone/restapi/tests/test_services_contextnavigation.py
b'diff --git a/news/1864.bugfix b/news/1864.bugfix\nnew file mode 100644\nindex 0000000000..9e63a64abd\n--- /dev/null\n+++ b/news/1864.bugfix\n@@ -0,0 +1 @@\n+In the `@contextnavigation` endpoint, return `"icon": null` for Files with a mimetype not found in the `content_type_registry`, instead of raising `TypeError`. @mamico\ndiff --git a/src/plone/restapi/services/contextnavigation/get.py b/src/plone/restapi/services/contextnavigation/get.py\nindex 0fe0d7a054..3f22602222 100644\n--- a/src/plone/restapi/services/contextnavigation/get.py\n+++ b/src/plone/restapi/services/contextnavigation/get.py\n@@ -357,7 +357,8 @@ def getMimeTypeIcon(self, node):\n mtt = getToolByName(self.context, "mimetypes_registry")\n if fileo.contentType:\n ctype = mtt.lookup(fileo.contentType)\n- return os.path.join(portal_url, guess_icon_path(ctype[0]))\n+ if ctype:\n+ return os.path.join(portal_url, guess_icon_path(ctype[0]))\n except AttributeError:\n pass\n \ndiff --git a/src/plone/restapi/tests/test_services_contextnavigation.py b/src/plone/restapi/tests/test_services_contextnavigation.py\nindex 9f8405e95a..05fe3c037e 100644\n--- a/src/plone/restapi/tests/test_services_contextnavigation.py\n+++ b/src/plone/restapi/tests/test_services_contextnavigation.py\n@@ -3,6 +3,7 @@\n from plone.app.testing import SITE_OWNER_NAME\n from plone.app.testing import SITE_OWNER_PASSWORD\n from plone.app.testing import TEST_USER_ID\n+from plone.namedfile.file import NamedBlobFile\n from plone.registry.interfaces import IRegistry\n from plone.restapi.services.contextnavigation.get import ContextNavigation\n from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING\n@@ -99,6 +100,9 @@ def populateSite(self):\n folder2.invokeFactory("Document", "doc22")\n folder2.invokeFactory("Document", "doc23")\n folder2.invokeFactory("File", "file21")\n+ folder2.file21.file = NamedBlobFile(\n+ data="Hello World", contentType="text/plain", filename="file.txt"\n+ )\n folder2.invokeFactory("Folder", "folder21")\n folder21 = getattr(folder2, "folder21")\n folder21.invokeFactory("Document", "doc211")\n@@ -996,3 +1000,28 @@ def testContextNavigation(self):\n "/plone/folder1/doc11",\n )\n )\n+\n+ def testIcon(self):\n+ view = self.renderer(\n+ self.portal.folder2.file21,\n+ opts(root_path="/folder2", topLevel=0),\n+ )\n+ tree = view.getNavTree()\n+ self.assertTrue(tree)\n+ self.assertEqual(\n+ tree["items"][0]["icon"],\n+ "/plone/++resource++mimetype.icons/txt.png",\n+ )\n+\n+ def testIconNotRegisteredMimetype(self):\n+ self.portal.folder2.file21.file.contentType = "plain/x-text"\n+ view = self.renderer(\n+ self.portal.folder2.file21,\n+ opts(root_path="/folder2", topLevel=0),\n+ )\n+ tree = view.getNavTree()\n+ self.assertTrue(tree)\n+ self.assertEqual(\n+ tree["items"][0]["icon"],\n+ None,\n+ )\n'