Skip to content

Commit

Permalink
Merge pull request #551 from plone/backport_549
Browse files Browse the repository at this point in the history
 backport fix for #549
  • Loading branch information
pbauer authored Dec 21, 2024
2 parents e89ea6d + 8ca6c9e commit 212bb72
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions news/551.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Backport fix for #549
[pbauer]
7 changes: 6 additions & 1 deletion src/plone/api/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ def get(path=None, UID=None):
)

try:
return site.restrictedTraverse(path)
path = path.split('/')
if len(path) > 1:
parent = site.unrestrictedTraverse(path[:-1])
return parent.restrictedTraverse(path[-1])
else:
return site.restrictedTraverse(path[-1])
except (KeyError, AttributeError):
return None # When no object is found don't raise an error

Expand Down
11 changes: 11 additions & 0 deletions src/plone/api/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,17 @@ def test_get(self):
# Test getting a non-existing subfolder by path
self.assertFalse(api.content.get('/about/spam'))

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')
team_by_path = api.content.get(path='/about/team')
with api.env.adopt_roles(['Member']):
team_by_path = api.content.get(path='/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 212bb72

Please sign in to comment.