Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows working copy of the Portal #1823

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1823.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allows working copy of the Portal. @wesleybl
20 changes: 15 additions & 5 deletions src/plone/restapi/serializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from plone.dexterity.interfaces import IDexterityContainer
from plone.dexterity.interfaces import IDexterityContent
from plone.dexterity.utils import iterSchemata
from plone.restapi import HAS_PLONE_6
from plone.restapi.batching import HypermediaBatch
from plone.restapi.deserializer import boolean_value
from plone.restapi.interfaces import IFieldSerializer
Expand Down Expand Up @@ -42,6 +43,19 @@
WorkingCopyInfo = None


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

# Does not return working copy information when serializing Portal in Plone 5.2.
if not HAS_PLONE_6 and context.portal_type == "Plone Site":
return

working_copy_info = WorkingCopyInfo(context)
baseline, working_copy = working_copy_info.get_working_copy_info()
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 +122,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>
Loading