From f8482e8d5ca4cbcfe26ed788f877f1b1396bbe78 Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Thu, 2 Feb 2023 10:19:15 +0100 Subject: [PATCH 1/3] Fix editing modal property when editing an action --- Products/CMFPlone/controlpanel/browser/actions.py | 10 ++++++++++ news/3709.bugfix | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 news/3709.bugfix diff --git a/Products/CMFPlone/controlpanel/browser/actions.py b/Products/CMFPlone/controlpanel/browser/actions.py index 4f66ab1e0a..dff7f3648c 100644 --- a/Products/CMFPlone/controlpanel/browser/actions.py +++ b/Products/CMFPlone/controlpanel/browser/actions.py @@ -14,6 +14,8 @@ from zope.interface import implementer from zope.lifecycleevent import ObjectCreatedEvent +import json + class ActionListControlPanel(BrowserView): """Control panel for the portal actions.""" @@ -163,6 +165,14 @@ def set_position(self, value): position = property(get_position, set_position) + def get_modal(self): + return json.loads(self.context.modal) + + def set_modal(self, value): + self.context.modal = json.dumps(value) + + modal = property(get_modal, set_modal) + class ActionControlPanel(AutoExtensibleForm, form.EditForm): """A form to edit a portal action.""" diff --git a/news/3709.bugfix b/news/3709.bugfix new file mode 100644 index 0000000000..b820562c53 --- /dev/null +++ b/news/3709.bugfix @@ -0,0 +1,2 @@ +Fix editing `modal` property of an action in `@@actions-controlpanel`. +[petschki] From cd095abc3a5921f292147f4b6b2d407ca73e47e4 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 3 Feb 2023 13:02:40 +0100 Subject: [PATCH 2/3] Get/set action modal: do not use json dumps/loads. This actually does the wrong thing. --- Products/CMFPlone/controlpanel/browser/actions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Products/CMFPlone/controlpanel/browser/actions.py b/Products/CMFPlone/controlpanel/browser/actions.py index dff7f3648c..8b105155e9 100644 --- a/Products/CMFPlone/controlpanel/browser/actions.py +++ b/Products/CMFPlone/controlpanel/browser/actions.py @@ -166,10 +166,10 @@ def set_position(self, value): position = property(get_position, set_position) def get_modal(self): - return json.loads(self.context.modal) + return self.context.modal def set_modal(self, value): - self.context.modal = json.dumps(value) + self.context.modal = value modal = property(get_modal, set_modal) From 9d4c402c8e2b97033e717de189b15ef520093a05 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 3 Feb 2023 13:17:47 +0100 Subject: [PATCH 3/3] When modal property does not yet exist, create it. --- Products/CMFPlone/controlpanel/browser/actions.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Products/CMFPlone/controlpanel/browser/actions.py b/Products/CMFPlone/controlpanel/browser/actions.py index 8b105155e9..f8bd8cd049 100644 --- a/Products/CMFPlone/controlpanel/browser/actions.py +++ b/Products/CMFPlone/controlpanel/browser/actions.py @@ -1,6 +1,7 @@ from plone.autoform.form import AutoExtensibleForm from plone.base.interfaces import IActionSchema from plone.base.interfaces import INewActionSchema +from plone.base.utils import base_hasattr from Products.CMFCore.ActionInformation import Action from Products.CMFCore.interfaces import IAction from Products.CMFCore.interfaces import IActionCategory @@ -169,7 +170,15 @@ def get_modal(self): return self.context.modal def set_modal(self, value): - self.context.modal = value + # This property may not exist yet on the context. + if not self.context.hasProperty("modal"): + if base_hasattr(self.context, "modal"): + # We cannot define a property when an attribute with the same + # name already exists. + delattr(self.context, "modal") + self.context._setProperty('modal', value, 'string') + else: + self.context._setPropValue('modal', value) modal = property(get_modal, set_modal)