-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from eea/develop
Feature: Add content rule to unset publication date when private [dobri1408 - refs #147278]
- Loading branch information
Showing
9 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
""" Content rules | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:browser="http://namespaces.zope.org/browser" | ||
xmlns:plone="http://namespaces.plone.org/plone"> | ||
|
||
<include package="plone.contentrules" file="meta.zcml" /> | ||
<include package="plone.app.contentrules" /> | ||
|
||
<adapter factory=".actions.SetPublicationDateToNullExecutor" /> | ||
|
||
<browser:page | ||
for="plone.app.contentrules.browser.interfaces.IRuleActionAdding" | ||
name="eea.volto.policy.set_publication_date_to_null" | ||
class=".actions.SetPublicationDateToNullAddForm" | ||
permission="plone.app.contentrules.ManageContentRules" | ||
/> | ||
|
||
<plone:ruleAction | ||
name="eea.volto.policy.set_publication_date_to_null" | ||
title="Set Publication Date to null" | ||
description="Set Publication Date to null" | ||
for="zope.interface.Interface" | ||
event="zope.interface.Interface" | ||
addview="eea.volto.policy.set_publication_date_to_null" | ||
schema=".actions.ISetPublicationDateToNullAction" | ||
factory=".actions.SetPublicationDateToNullAction" | ||
/> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<contentrules> | ||
<rule name="rule-1" title="Unset Publication Date When Private" cascading="False" description="" | ||
enabled="True" event="Products.CMFCore.interfaces.IActionSucceededEvent" | ||
stop-after="False"> | ||
<conditions> | ||
<condition type="plone.conditions.WorkflowState"> | ||
<property name="wf_states"> | ||
<element>private</element> | ||
</property> | ||
</condition> | ||
</conditions> | ||
<actions> | ||
<action type="eea.volto.policy.set_publication_date_to_null"/> | ||
</actions> | ||
</rule> | ||
<assignment name="rule-1" bubbles="True" enabled="True" location=""/> | ||
</contentrules> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.0 | ||
3.1 |