From 3b6ebf1b6e22b01bc62a3262f43bf1cd1a468c8a Mon Sep 17 00:00:00 2001 From: wesleybl Date: Mon, 7 Oct 2024 18:29:33 -0300 Subject: [PATCH 1/3] 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. --- src/plone/restapi/serializer/dxcontent.py | 12 ++++--- src/plone/restapi/serializer/site.py | 5 +++ .../services/workingcopy/configure.zcml | 33 +++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/plone/restapi/serializer/dxcontent.py b/src/plone/restapi/serializer/dxcontent.py index eb0fc44c6e..9f0e700bbb 100644 --- a/src/plone/restapi/serializer/dxcontent.py +++ b/src/plone/restapi/serializer/dxcontent.py @@ -42,6 +42,12 @@ WorkingCopyInfo = None +def update_with_working_copy_info(context, result): + if WorkingCopyInfo is not None: + baseline, working_copy = WorkingCopyInfo(context).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. @@ -108,11 +114,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)}) diff --git a/src/plone/restapi/serializer/site.py b/src/plone/restapi/serializer/site.py index 65081fd2ea..bb08759c77 100644 --- a/src/plone/restapi/serializer/site.py +++ b/src/plone/restapi/serializer/site.py @@ -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 @@ -26,6 +27,7 @@ from zope.schema import getFields from zope.security.interfaces import IPermission + import json @@ -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 diff --git a/src/plone/restapi/services/workingcopy/configure.zcml b/src/plone/restapi/services/workingcopy/configure.zcml index 431b6df84b..8b55b902e8 100644 --- a/src/plone/restapi/services/workingcopy/configure.zcml +++ b/src/plone/restapi/services/workingcopy/configure.zcml @@ -39,4 +39,37 @@ name="@workingcopy" /> + + + + + + + + + From 504fbb19992be7289eb739bec42705aa3368edb9 Mon Sep 17 00:00:00 2001 From: wesleybl Date: Tue, 8 Oct 2024 09:38:02 -0300 Subject: [PATCH 2/3] Add Changes --- news/1823.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/1823.feature diff --git a/news/1823.feature b/news/1823.feature new file mode 100644 index 0000000000..ac278585a4 --- /dev/null +++ b/news/1823.feature @@ -0,0 +1 @@ +Allows working copy of the Portal. @wesleybl From 88ca99e60b23b7449e68e9457274b54bf8af3d42 Mon Sep 17 00:00:00 2001 From: wesleybl Date: Tue, 8 Oct 2024 19:08:18 -0300 Subject: [PATCH 3/3] Does not return working copy information when serializing Portal in Plone 5.2 --- src/plone/restapi/serializer/dxcontent.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/plone/restapi/serializer/dxcontent.py b/src/plone/restapi/serializer/dxcontent.py index 9f0e700bbb..d801a29fdc 100644 --- a/src/plone/restapi/serializer/dxcontent.py +++ b/src/plone/restapi/serializer/dxcontent.py @@ -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 @@ -43,9 +44,16 @@ def update_with_working_copy_info(context, result): - if WorkingCopyInfo is not None: - baseline, working_copy = WorkingCopyInfo(context).get_working_copy_info() - result.update({"working_copy": working_copy, "working_copy_of": baseline}) + 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):