Skip to content

Commit

Permalink
Merge branch 'main' into rtd-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
stevepiercy authored Jan 7, 2025
2 parents db089b9 + ae38e69 commit c92b7c8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/plone_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]
plone-version: ["6.0"]

steps:
Expand Down
2 changes: 2 additions & 0 deletions news/549.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix api.content.get(path=path) when a item in the path is not accessible to the user.
[pbauer]
7 changes: 6 additions & 1 deletion src/plone/api/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ def get(path=None, UID=None):
relative_path=path,
)
try:
content = site.restrictedTraverse(path)
path = path.split("/")
if len(path) > 1:
parent = site.unrestrictedTraverse(path[:-1])
content = parent.restrictedTraverse(path[-1])
else:
content = site.restrictedTraverse(path[-1])
except (KeyError, AttributeError):
return None # When no object is found don't raise an error
else:
Expand Down
10 changes: 10 additions & 0 deletions src/plone/api/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,16 @@ def test_get(self):
# title is an attribute
self.assertIsNone(api.content.get("/about/team/title"))

def test_get_of_content_in_inaccessible_container(self):
"""Test getting items in a inaccessible container.
Worked in Plone 5.1 but raised Unauthorized since 5.2."""
api.content.transition(obj=self.team, transition="publish")
with api.env.adopt_roles(["Member"]):
team_by_path = api.content.get("/about/team")
self.assertEqual(self.team, team_by_path)
team_by_uid = api.content.get(UID=self.team.UID())
self.assertEqual(self.team, team_by_uid)

def test_move_constraints(self):
"""Test the constraints for moving content."""
from plone.api.exc import MissingParameterError
Expand Down

0 comments on commit c92b7c8

Please sign in to comment.