Skip to content

Commit

Permalink
[fc] Repository: plone.api
Browse files Browse the repository at this point in the history
Branch: refs/heads/main
Date: 2024-12-20T06:52:47+01:00
Author: Philip Bauer (pbauer) <[email protected]>
Commit: plone/plone.api@0da4d70

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
Repository: plone.api

Branch: refs/heads/main
Date: 2024-12-20T08:19:24+01:00
Author: Philip Bauer (pbauer) <[email protected]>
Commit: plone/plone.api@c6cfdb4

add test

Files changed:
M src/plone/api/tests/test_content.py
Repository: plone.api

Branch: refs/heads/main
Date: 2024-12-21T21:52:17+01:00
Author: Philip Bauer (pbauer) <[email protected]>
Commit: plone/plone.api@ef01287

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
  • Loading branch information
pbauer committed Dec 21, 2024
1 parent 6bcd9c3 commit 95632ad
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions last_commit.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
Repository: Products.CMFPlone
Repository: plone.api


Branch: refs/heads/6.0.x
Date: 2024-12-20T01:56:35+01:00
Author: Maurits van Rees (mauritsvanrees) <[email protected]>
Commit: https://github.com/plone/Products.CMFPlone/commit/1ef49167b1c159ef836a65f9fed9a4256d352b2c
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

Updated metadata version to 6026.
Fix api.content.get when a item in the path is not accessible to the user (#549)

Files changed:
A news/6026.internal
M Products/CMFPlone/profiles/default/metadata.xml
A news/549.bugfix
M src/plone/api/content.py

b'diff --git a/Products/CMFPlone/profiles/default/metadata.xml b/Products/CMFPlone/profiles/default/metadata.xml\nindex 53c3c71ba3..2a66007b60 100644\n--- a/Products/CMFPlone/profiles/default/metadata.xml\n+++ b/Products/CMFPlone/profiles/default/metadata.xml\n@@ -1,4 +1,4 @@\n <?xml version="1.0" encoding="utf-8"?>\n <metadata>\n- <version>6025</version>\n+ <version>6026</version>\n </metadata>\ndiff --git a/news/6026.internal b/news/6026.internal\nnew file mode 100644\nindex 0000000000..dee2568bab\n--- /dev/null\n+++ b/news/6026.internal\n@@ -0,0 +1,2 @@\n+Updated metadata version to 6026.\n+[maurits]\n'
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'

0 comments on commit 95632ad

Please sign in to comment.