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 8a6e13b commit ea8dc4c
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions last_commit.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
Repository: Products.CMFPlone
Repository: plone.api


Branch: refs/heads/master
Date: 2024-12-20T01:54:25+01:00
Author: Maurits van Rees (mauritsvanrees) <[email protected]>
Commit: https://github.com/plone/Products.CMFPlone/commit/f352e2f43f6fc6ef4f66242d3c0d54cc05117dd2
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 6107.
Fix api.content.get when a item in the path is not accessible to the user (#549)

This will likely be 6.1.0rc1.
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/6107.internal
M CHANGES.md
M Products/CMFPlone/profiles/default/metadata.xml
M setup.py
A news/549.bugfix
M src/plone/api/content.py
M src/plone/api/tests/test_content.py

b'diff --git a/CHANGES.md b/CHANGES.md\nindex b89c98f321..f2c730dab1 100644\n--- a/CHANGES.md\n+++ b/CHANGES.md\n@@ -469,7 +469,7 @@\n \n ### Bug fixes:\n \n-- Remove unused template send_feedback_confirm.pt. \n+- Remove unused template send_feedback_confirm.pt.\n [jensens] #3122\n - Moved the assignment of Plone Site Setup permissions from zcml to GenericSetup\n rolemap.xml. This assigns the permissions on site creation instead of Zope root\ndiff --git a/Products/CMFPlone/profiles/default/metadata.xml b/Products/CMFPlone/profiles/default/metadata.xml\nindex f021bdc095..74f32b4c08 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>6106</version>\n+ <version>6107</version>\n </metadata>\ndiff --git a/news/6107.internal b/news/6107.internal\nnew file mode 100644\nindex 0000000000..b1c2af6f76\n--- /dev/null\n+++ b/news/6107.internal\n@@ -0,0 +1,2 @@\n+Updated metadata version to 6107.\n+[maurits]\ndiff --git a/setup.py b/setup.py\nindex 7b5227a557..f5c535c6b6 100644\n--- a/setup.py\n+++ b/setup.py\n@@ -2,7 +2,7 @@\n from setuptools import setup\n \n \n-version = "6.1.0b3.dev0"\n+version = "6.1.0rc1.dev0"\n \n \n setup(\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:\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 ea8dc4c

Please sign in to comment.