Skip to content

Commit

Permalink
fix: plone.restapi must work without dependency on only Products.CMFP…
Browse files Browse the repository at this point in the history
…lone

currently it depends on plone.app.itertae. The assumption, that it is always there is wrong, it is an internal addon, only installed when dependening on 'Plone'.
  • Loading branch information
jensens committed Jul 20, 2022
1 parent ac0907b commit be9eb11
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions news/1461.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Do not hard depend on `plone.app.iterate`. It is not an direct core package and might not be available.
[jensens]
13 changes: 10 additions & 3 deletions src/plone/restapi/serializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from plone.restapi.serializer.converters import json_compatible
from plone.restapi.serializer.expansion import expandable_elements
from plone.restapi.serializer.nextprev import NextPrevious
from plone.restapi.serializer.working_copy import WorkingCopyInfo
from plone.restapi.services.locking import lock_info
from plone.rfc822.interfaces import IPrimaryFieldInfo
from plone.supermodel.utils import mergedTaggedValueDict
Expand All @@ -30,6 +29,13 @@
from zope.schema import getFields
from zope.security.interfaces import IPermission

try:
# plone.app.iterate is by intend not part of Products.CMFPlone dependencies
# so we can not rely on having it
from plone.restapi.serializer.working_copy import WorkingCopyInfo
except ImportError:
WorkingCopyInfo = None


@implementer(ISerializeToJson)
@adapter(IDexterityContent, Interface)
Expand Down Expand Up @@ -77,8 +83,9 @@ def __call__(self, version=None, include_items=True):
)

# Insert working copy information
baseline, working_copy = WorkingCopyInfo(self.context).get_working_copy_info()
result.update({"working_copy": working_copy, "working_copy_of": baseline})
if WorkingCopyInfo is not None:
baseline, working_copy = WorkingCopyInfo(self.context).get_working_copy_info()
result.update({"working_copy": working_copy, "working_copy_of": baseline})

# Insert locking information
result.update({"lock": lock_info(obj)})
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/services/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<include package=".workflow" />
<include
package=".workingcopy"
zcml:condition="have plone-5"
zcml:condition="installed plone.app.iterate"
/>
<include
package=".multilingual"
Expand Down

0 comments on commit be9eb11

Please sign in to comment.