-
-
Notifications
You must be signed in to change notification settings - Fork 13
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 #47 from plone/versioning_action_4_0_x
Versioning action 4 0 x
- Loading branch information
Showing
5 changed files
with
202 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add new action `Version object`. | ||
[gbastien] |
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,95 @@ | ||
# -*- coding: utf-8 -*- | ||
from OFS.SimpleItem import SimpleItem | ||
from plone.app.contentrules import PloneMessageFactory as _ | ||
from plone.app.contentrules.actions import ActionAddForm | ||
from plone.app.contentrules.actions import ActionEditForm | ||
from plone.app.contentrules.browser.formhelper import ContentRuleFormWrapper | ||
from plone.contentrules.rule.interfaces import IExecutable | ||
from plone.contentrules.rule.interfaces import IRuleElementData | ||
from Products.CMFCore.utils import getToolByName | ||
from zope import schema | ||
from zope.component import adapter | ||
from zope.interface import implementer | ||
from zope.interface import Interface | ||
|
||
|
||
class IVersioningAction(Interface): | ||
"""Interface for the configurable aspects of a versioning action. | ||
This is also used to create add and edit forms, below. | ||
""" | ||
|
||
comment = schema.TextLine( | ||
title=_(u'Comment'), | ||
description=_( | ||
u'The comment added to the history while versioning the content.'), | ||
required=False, | ||
) | ||
|
||
|
||
@implementer(IVersioningAction, IRuleElementData) | ||
class VersioningAction(SimpleItem): | ||
"""The actual persistent implementation of the versioning action element. | ||
""" | ||
|
||
comment = '' | ||
|
||
element = 'plone.actions.Versioning' | ||
|
||
@property | ||
def summary(self): | ||
return _( | ||
u'Versioning with comment ${comment}', | ||
mapping=dict(comment=self.comment), | ||
) | ||
|
||
|
||
@adapter(Interface, IVersioningAction, Interface) | ||
@implementer(IExecutable) | ||
class VersioningActionExecutor(object): | ||
"""The executor for this action. | ||
This is registered as an adapter in configure.zcml | ||
""" | ||
|
||
def __init__(self, context, element, event): | ||
self.context = context | ||
self.element = element | ||
self.event = event | ||
|
||
def __call__(self): | ||
comment = _(self.element.comment) | ||
pr = getToolByName(self.context, 'portal_repository') | ||
pr.save(obj=self.event.object, comment=comment) | ||
return True | ||
|
||
|
||
class VersioningAddForm(ActionAddForm): | ||
"""An add form for versioning rule actions. | ||
""" | ||
schema = IVersioningAction | ||
label = _(u'Add Versioning Action') | ||
description = _(u'A versioning action will store a version of a content ' | ||
u'no matter versioning is enabled for it or not.') | ||
form_name = _(u'Configure element') | ||
Type = VersioningAction | ||
|
||
|
||
class VersioningAddFormView(ContentRuleFormWrapper): | ||
form = VersioningAddForm | ||
|
||
|
||
class VersioningEditForm(ActionEditForm): | ||
"""An edit form for versioning rule actions. | ||
z3c.form does all the magic here. | ||
""" | ||
schema = IVersioningAction | ||
label = _(u'Edit Versioning Action') | ||
description = _(u'A versioning action will store a version of a content ' | ||
u'no matter versioning is enabled for it or not.') | ||
form_name = _(u'Configure element') | ||
|
||
|
||
class VersioningEditFormView(ContentRuleFormWrapper): | ||
form = VersioningEditForm |
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,74 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.app.contentrules.actions.versioning import VersioningAction | ||
from plone.app.contentrules.actions.versioning import VersioningEditFormView | ||
from plone.app.contentrules.rule import Rule | ||
from plone.app.contentrules.tests.base import ContentRulesTestCase | ||
from plone.contentrules.engine.interfaces import IRuleStorage | ||
from plone.contentrules.rule.interfaces import IExecutable | ||
from plone.contentrules.rule.interfaces import IRuleAction | ||
from zope.component import getMultiAdapter | ||
from zope.component import getUtility | ||
from zope.interface import implementer | ||
from zope.interface import Interface | ||
|
||
|
||
@implementer(Interface) | ||
class DummyEvent(object): | ||
|
||
def __init__(self, object): | ||
self.object = object | ||
|
||
|
||
class TestVersioningAction(ContentRulesTestCase): | ||
|
||
def afterSetUp(self): | ||
self.request = self.layer['request'] | ||
|
||
def testRegistered(self): | ||
element = getUtility(IRuleAction, name='plone.actions.Versioning') | ||
self.assertEqual('plone.actions.Versioning', element.addview) | ||
self.assertEqual('edit', element.editview) | ||
self.assertEqual(None, element.for_) | ||
self.assertEqual(None, element.event) | ||
|
||
def testInvokeAddView(self): | ||
element = getUtility(IRuleAction, name='plone.actions.Versioning') | ||
storage = getUtility(IRuleStorage) | ||
storage[u'foo'] = Rule() | ||
rule = self.portal.restrictedTraverse('++rule++foo') | ||
|
||
adding = getMultiAdapter((rule, self.request), name='+action') | ||
addview = getMultiAdapter((adding, self.request), name=element.addview) | ||
|
||
addview.form_instance.update() | ||
content = addview.form_instance.create(data={'comment': 'Hello world'}) | ||
addview.form_instance.add(content) | ||
|
||
e = rule.actions[0] | ||
self.assertTrue(isinstance(e, VersioningAction)) | ||
self.assertEqual('Hello world', e.comment) | ||
|
||
def testInvokeEditView(self): | ||
element = getUtility(IRuleAction, name='plone.actions.Versioning') | ||
e = VersioningAction() | ||
editview = getMultiAdapter((e, self.request), name=element.editview) | ||
self.assertTrue(isinstance(editview, VersioningEditFormView)) | ||
|
||
def testExecute(self): | ||
e = VersioningAction() | ||
e.comment = 'Hello world' | ||
|
||
ex = getMultiAdapter( | ||
(self.folder, e, DummyEvent(self.folder)), IExecutable) | ||
# not version for now | ||
pr = self.portal.portal_repository | ||
self.assertEqual(pr.getHistoryMetadata(self.folder), []) | ||
|
||
# action will create first version | ||
self.assertEqual(True, ex()) | ||
self.assertEqual( | ||
pr.getHistoryMetadata(self.folder).getLength(countPurged=False), 1) | ||
# calling action again will create a second version | ||
ex() | ||
self.assertEqual( | ||
pr.getHistoryMetadata(self.folder).getLength(countPurged=False), 2) |
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
025ae14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jensens Jenkins CI reporting about code analysis
See the full report here: https://jenkins.plone.org/job/package-plone.app.contentrules/91/violations
Follow these instructions to reproduce it locally.