Skip to content

Commit

Permalink
Allows working copy of the Portal (#1823)
Browse files Browse the repository at this point in the history
* Allows working copy of the Portal

Allows working copy services to be accessed in the Portal. Also returns
working copy data in the Portal serialization.

* Add Changes

* Does not return working copy information when serializing Portal in
Plone 5.2

* better check for working copy support: test for feature instead of testing for version

* Update news/1823.feature

---------

Co-authored-by: David Glick <david@glicksoftware.com>
  • Loading branch information
wesleybl and davisagli authored Jan 28, 2025
1 parent 0a2f821 commit 259d969
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/1823.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support working copies of the Plone Site. This feature is available when using `plone.app.iterate` 6.1.0 or later. @wesleybl
19 changes: 14 additions & 5 deletions src/plone/restapi/serializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
WorkingCopyInfo = None


def update_with_working_copy_info(context, result):
if WorkingCopyInfo is None:
return

working_copy_info = WorkingCopyInfo(context)
try:
baseline, working_copy = working_copy_info.get_working_copy_info()
except TypeError:
# not supported for this content type
return
result.update({"working_copy": working_copy, "working_copy_of": baseline})


def get_allow_discussion_value(context, request, result):
# This test is to handle the situation of plone.app.discussion not being installed
# or not being activated.
Expand Down Expand Up @@ -108,11 +121,7 @@ def __call__(self, version=None, include_items=True):
result.update({"previous_item": {}, "next_item": {}})

# Insert working copy information
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})
update_with_working_copy_info(self.context, result)

# Insert locking information
result.update({"lock": lock_info(obj)})
Expand Down
5 changes: 5 additions & 0 deletions src/plone/restapi/serializer/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.serializer.converters import json_compatible
from plone.restapi.serializer.dxcontent import get_allow_discussion_value
from plone.restapi.serializer.dxcontent import update_with_working_copy_info
from plone.restapi.serializer.expansion import expandable_elements
from plone.restapi.serializer.utils import get_portal_type_title
from plone.restapi.services.locking import lock_info
Expand All @@ -26,6 +27,7 @@
from zope.schema import getFields
from zope.security.interfaces import IPermission


import json


Expand Down Expand Up @@ -74,6 +76,9 @@ def __call__(self, version=None):
"description": self.context.description,
}

# Insert working copy information
update_with_working_copy_info(self.context, result)

if HAS_PLONE_6:
result["UID"] = self.context.UID()
# Insert review_state
Expand Down
33 changes: 33 additions & 0 deletions src/plone/restapi/services/workingcopy/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,37 @@
name="@workingcopy"
/>

<plone:service
method="GET"
factory=".get.GetWorkingCopy"
for="Products.CMFCore.interfaces.ISiteRoot"
permission="zope2.View"
name="@workingcopy"
/>

<plone:service
method="POST"
factory=".create.CreateWorkingCopy"
for="Products.CMFCore.interfaces.ISiteRoot"
permission="plone.app.iterate.CheckOutContent"
name="@workingcopy"
/>


<plone:service
method="PATCH"
factory=".update.UpdateWorkingCopy"
for="Products.CMFCore.interfaces.ISiteRoot"
permission="plone.app.iterate.CheckInContent"
name="@workingcopy"
/>

<plone:service
method="DELETE"
factory=".delete.DeleteWorkingCopy"
for="Products.CMFCore.interfaces.ISiteRoot"
permission="zope2.DeleteObjects"
name="@workingcopy"
/>

</configure>

0 comments on commit 259d969

Please sign in to comment.