-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
last_commit.txt
50 lines (31 loc) · 5.12 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Repository: plone.api
Branch: refs/heads/main
Date: 2024-12-20T06:52:47+01:00
Author: Philip Bauer (pbauer) <[email protected]>
Commit: https://github.com/plone/plone.api/commit/0da4d7050953c7b513e1787dad05c64b09bdd556
Fix api.content.get when a item in the path is not accessible to the user (#549)
Files changed:
A news/549.bugfix
M src/plone/api/content.py
b'diff --git a/news/549.bugfix b/news/549.bugfix\nnew file mode 100644\nindex 00000000..2d2d3666\n--- /dev/null\n+++ b/news/549.bugfix\n@@ -0,0 +1,2 @@\n+Fix api.content.get(path=path) when a item in the path is not accessible to the user.\n+[pbauer]\ndiff --git a/src/plone/api/content.py b/src/plone/api/content.py\nindex 95515de9..f0a9c850 100644\n--- a/src/plone/api/content.py\n+++ b/src/plone/api/content.py\n@@ -133,7 +133,12 @@ def get(path=None, UID=None):\n relative_path=path,\n )\n try:\n- content = site.restrictedTraverse(path)\n+ path = path.split("/")\n+ if len(path) > 1:\n+ parent = site.unrestrictedTraverse(path[:-1])\n+ content = parent.restrictedTraverse(path[-1])\n+ else:\n+ content = site.restrictedTraverse(path[-1])\n except (KeyError, AttributeError):\n return None # When no object is found don\'t raise an error\n else:\n'
Repository: plone.api
Branch: refs/heads/main
Date: 2024-12-20T08:19:24+01:00
Author: Philip Bauer (pbauer) <[email protected]>
Commit: https://github.com/plone/plone.api/commit/c6cfdb41b5e7bc9f1ca518f1e3449059d4820aae
add test
Files changed:
M src/plone/api/tests/test_content.py
b'diff --git a/src/plone/api/tests/test_content.py b/src/plone/api/tests/test_content.py\nindex 41caebc0..4e9b701b 100644\n--- a/src/plone/api/tests/test_content.py\n+++ b/src/plone/api/tests/test_content.py\n@@ -478,6 +478,16 @@ def test_get(self):\n # title is an attribute\n self.assertIsNone(api.content.get("/about/team/title"))\n \n+ def test_get_of_content_in_inaccessible_container(self):\n+ """Test getting items in a inaccessible container.\n+ Worked in Plone 5.1 but raised Unauthorized since 5.2."""\n+ api.content.transition(obj=self.team, transition="publish")\n+ with api.env.adopt_roles(["Member"]):\n+ team_by_path = api.content.get("/about/team")\n+ self.assertEqual(self.team, team_by_path)\n+ team_by_uid = api.content.get(UID=self.team.UID())\n+ self.assertEqual(self.team, team_by_uid)\n+\n def test_move_constraints(self):\n """Test the constraints for moving content."""\n from plone.api.exc import MissingParameterError\n'
Repository: plone.api
Branch: refs/heads/main
Date: 2024-12-21T21:52:17+01:00
Author: Philip Bauer (pbauer) <[email protected]>
Commit: https://github.com/plone/plone.api/commit/ef012878006d89efc37321082610be85c1d162be
Merge pull request #550 from plone/fix_getting_content_in_inaccessible_containers
Fix api.content.get when a item in the path is not acccessible
Files changed:
A news/549.bugfix
M src/plone/api/content.py
M src/plone/api/tests/test_content.py
b'diff --git a/news/549.bugfix b/news/549.bugfix\nnew file mode 100644\nindex 00000000..2d2d3666\n--- /dev/null\n+++ b/news/549.bugfix\n@@ -0,0 +1,2 @@\n+Fix api.content.get(path=path) when a item in the path is not accessible to the user.\n+[pbauer]\ndiff --git a/src/plone/api/content.py b/src/plone/api/content.py\nindex 95515de9..f0a9c850 100644\n--- a/src/plone/api/content.py\n+++ b/src/plone/api/content.py\n@@ -133,7 +133,12 @@ def get(path=None, UID=None):\n relative_path=path,\n )\n try:\n- content = site.restrictedTraverse(path)\n+ path = path.split("/")\n+ if len(path) > 1:\n+ parent = site.unrestrictedTraverse(path[:-1])\n+ content = parent.restrictedTraverse(path[-1])\n+ else:\n+ content = site.restrictedTraverse(path[-1])\n except (KeyError, AttributeError):\n return None # When no object is found don\'t raise an error\n else:\ndiff --git a/src/plone/api/tests/test_content.py b/src/plone/api/tests/test_content.py\nindex 41caebc0..4e9b701b 100644\n--- a/src/plone/api/tests/test_content.py\n+++ b/src/plone/api/tests/test_content.py\n@@ -478,6 +478,16 @@ def test_get(self):\n # title is an attribute\n self.assertIsNone(api.content.get("/about/team/title"))\n \n+ def test_get_of_content_in_inaccessible_container(self):\n+ """Test getting items in a inaccessible container.\n+ Worked in Plone 5.1 but raised Unauthorized since 5.2."""\n+ api.content.transition(obj=self.team, transition="publish")\n+ with api.env.adopt_roles(["Member"]):\n+ team_by_path = api.content.get("/about/team")\n+ self.assertEqual(self.team, team_by_path)\n+ team_by_uid = api.content.get(UID=self.team.UID())\n+ self.assertEqual(self.team, team_by_uid)\n+\n def test_move_constraints(self):\n """Test the constraints for moving content."""\n from plone.api.exc import MissingParameterError\n'