diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index aa8ccff..220d60a 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -1,6 +1,11 @@ Changelog ========= +3.1 - (2023-08-31) +--------------------------- +* Change: Feature: Add content rule to unset publication date when private [dobri1408 - refs #147278] + [avoinea] + 3.0 - (2023-08-30) --------------------------- * Feature: Add image_scales to catalog and update list of scales to registry diff --git a/eea/volto/policy/configure.zcml b/eea/volto/policy/configure.zcml index 126f8b6..8311e1c 100644 --- a/eea/volto/policy/configure.zcml +++ b/eea/volto/policy/configure.zcml @@ -11,6 +11,7 @@ + diff --git a/eea/volto/policy/contentrules/__init__.py b/eea/volto/policy/contentrules/__init__.py new file mode 100644 index 0000000..837c684 --- /dev/null +++ b/eea/volto/policy/contentrules/__init__.py @@ -0,0 +1,2 @@ +""" Content rules +""" diff --git a/eea/volto/policy/contentrules/actions.py b/eea/volto/policy/contentrules/actions.py new file mode 100644 index 0000000..5d26341 --- /dev/null +++ b/eea/volto/policy/contentrules/actions.py @@ -0,0 +1,66 @@ +""" EEAContentTypes actions for plone.app.contentrules +""" + +import logging +from AccessControl import SpecialUsers, getSecurityManager +from AccessControl.SecurityManagement import ( + newSecurityManager, + setSecurityManager, +) +from OFS.SimpleItem import SimpleItem +from plone.app.contentrules.browser.formhelper import ( + NullAddForm, +) +from plone.contentrules.rule.interfaces import IExecutable, IRuleElementData +from zope.component import adapter +from zope.interface import Interface, implementer + +logger = logging.getLogger("eea.volto.policy") + + +class ISetPublicationDateToNullAction(Interface): + """Set Publication Date to null""" + + +@implementer(ISetPublicationDateToNullAction, IRuleElementData) +class SetPublicationDateToNullAction(SimpleItem): + """Set publication date to null action""" + + element = "eea.volto.policy.set_publication_date_to_null" + summary = ( + "I will set publication date to null" + ) + + +@implementer(IExecutable) +@adapter(Interface, ISetPublicationDateToNullAction, Interface) +class SetPublicationDateToNullExecutor(object): + """Set Publication Date to null executor""" + + def __init__(self, context, element, event): + self.context = context + self.element = element + self.event = event + + def __call__(self): + obj = self.event.object + try: + # Bypass user roles in order to rename old version + oldSecurityManager = getSecurityManager() + newSecurityManager(None, SpecialUsers.system) + obj.setEffectiveDate(None) + + # Switch back to the current user + setSecurityManager(oldSecurityManager) + except Exception as err: + logger.exception(err) + return True + return True + + +class SetPublicationDateToNullAddForm(NullAddForm): + """Set Publication Date to null addform""" + + def create(self): + """Create content-rule""" + return SetPublicationDateToNullAction() diff --git a/eea/volto/policy/contentrules/configure.zcml b/eea/volto/policy/contentrules/configure.zcml new file mode 100644 index 0000000..918e18c --- /dev/null +++ b/eea/volto/policy/contentrules/configure.zcml @@ -0,0 +1,29 @@ + + + + + + + + + + + + diff --git a/eea/volto/policy/profiles/default/contentrules.xml b/eea/volto/policy/profiles/default/contentrules.xml new file mode 100644 index 0000000..90af600 --- /dev/null +++ b/eea/volto/policy/profiles/default/contentrules.xml @@ -0,0 +1,18 @@ + + + + + + + private + + + + + + + + + diff --git a/eea/volto/policy/profiles/default/metadata.xml b/eea/volto/policy/profiles/default/metadata.xml index e4ba0c6..f1d491e 100644 --- a/eea/volto/policy/profiles/default/metadata.xml +++ b/eea/volto/policy/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 3.0 + 3.1 profile-plone.volto:default diff --git a/eea/volto/policy/upgrades/configure.zcml b/eea/volto/policy/upgrades/configure.zcml index f8a59ea..faa8138 100644 --- a/eea/volto/policy/upgrades/configure.zcml +++ b/eea/volto/policy/upgrades/configure.zcml @@ -36,7 +36,17 @@ title="Add image_scales to catalog and update list of scales to registry" import_steps="catalog plone.app.registry" /> - + + + + + diff --git a/eea/volto/policy/version.txt b/eea/volto/policy/version.txt index 9f55b2c..8c50098 100644 --- a/eea/volto/policy/version.txt +++ b/eea/volto/policy/version.txt @@ -1 +1 @@ -3.0 +3.1