Skip to content

Commit

Permalink
Update with the fixes introduced in #876, in order to get rid of the …
Browse files Browse the repository at this point in the history
…string checks
  • Loading branch information
sneridagh committed Mar 30, 2020
1 parent 2881dce commit 2381091
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/plone/restapi/services/content/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,19 @@ def get_object(self, key):
).portal()
catalog = getToolByName(self.context, "portal_catalog")

if isinstance(key, six.string_types):
if key.startswith(portal.absolute_url()):
# Resolve by URL
key = key[len(portal.absolute_url()) + 1 :]
if six.PY2:
key = key.encode("utf8")
return portal.restrictedTraverse(key, None)
elif key.startswith("/"):
if six.PY2:
key = key.encode("utf8")
# Resolve by path
return portal.restrictedTraverse(key.lstrip("/"), None)
else:
# Resolve by UID
brain = catalog(UID=key)
if brain:
return brain[0].getObject()
if key.startswith(portal.absolute_url()):
# Resolve by URL
key = key[len(portal.absolute_url()) + 1 :]
if six.PY2:
key = key.encode("utf8")
return portal.restrictedTraverse(key, None)
elif key.startswith("/"):
if six.PY2:
key = key.encode("utf8")
# Resolve by path
return portal.restrictedTraverse(key.lstrip("/"), None)
else:
# Resolve by UID
brain = catalog(UID=key)
if brain:
return brain[0].getObject()

0 comments on commit 2381091

Please sign in to comment.