Ensure workflow is initialised when the comment is added. Also ensure that we won't get an error on unindex if the local utility can't be found.
svn path=/plone.app.discussion/trunk/; revision=27070
This commit is contained in:
parent
fba5d3f752
commit
8ffca9009c
@ -12,6 +12,7 @@ from AccessControl.Owned import Owned
|
|||||||
from plone.app.discussion.interfaces import IComment
|
from plone.app.discussion.interfaces import IComment
|
||||||
|
|
||||||
from Products.CMFCore.DynamicType import DynamicType
|
from Products.CMFCore.DynamicType import DynamicType
|
||||||
|
from Products.CMFCore.utils import getToolByName
|
||||||
|
|
||||||
class Comment(DynamicType, Traversable, RoleManager, Owned, Explicit):
|
class Comment(DynamicType, Traversable, RoleManager, Owned, Explicit):
|
||||||
"""A comment.
|
"""A comment.
|
||||||
@ -85,4 +86,11 @@ class Comment(DynamicType, Traversable, RoleManager, Owned, Explicit):
|
|||||||
def opaqueValues(self):
|
def opaqueValues(self):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
CommentFactory = Factory(Comment)
|
CommentFactory = Factory(Comment)
|
||||||
|
|
||||||
|
def notify_workflow(obj, event):
|
||||||
|
"""Tell the workflow tool when a comment is added
|
||||||
|
"""
|
||||||
|
tool = getToolByName(obj, 'portal_workflow', None)
|
||||||
|
if tool is not None:
|
||||||
|
tool.notifyCreated(obj)
|
@ -26,7 +26,7 @@
|
|||||||
component=".comment.CommentFactory"
|
component=".comment.CommentFactory"
|
||||||
name="plone.Comment"
|
name="plone.Comment"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Conversations -->
|
<!-- Conversations -->
|
||||||
<class class=".conversation.Conversation">
|
<class class=".conversation.Conversation">
|
||||||
<require interface=".interfaces.IConversation" permission="zope2.View" />
|
<require interface=".interfaces.IConversation" permission="zope2.View" />
|
||||||
@ -38,16 +38,23 @@
|
|||||||
<adapter factory=".conversation.CommentReplies" />
|
<adapter factory=".conversation.CommentReplies" />
|
||||||
|
|
||||||
<!-- Event subscribers -->
|
<!-- Event subscribers -->
|
||||||
|
|
||||||
<subscriber
|
<subscriber
|
||||||
for="plone.app.discussion.interfaces.IComment
|
for="plone.app.discussion.interfaces.IComment
|
||||||
zope.app.container.contained.IObjectAddedEvent"
|
zope.app.container.contained.IObjectAddedEvent"
|
||||||
handler=".tool.object_added_handler"
|
handler=".comment.notify_workflow"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<subscriber
|
||||||
|
for="plone.app.discussion.interfaces.IComment
|
||||||
|
zope.app.container.contained.IObjectAddedEvent"
|
||||||
|
handler=".tool.index_object"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<subscriber
|
<subscriber
|
||||||
for="plone.app.discussion.interfaces.IComment
|
for="plone.app.discussion.interfaces.IComment
|
||||||
zope.app.container.contained.IObjectRemovedEvent"
|
zope.app.container.contained.IObjectRemovedEvent"
|
||||||
handler=".tool.object_removed_handler"
|
handler=".tool.unindex_object"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
@ -57,9 +57,22 @@ class CommentTest(PloneTestCase):
|
|||||||
self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault/' + str(new_comment1_id), comment.absolute_url())
|
self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault/' + str(new_comment1_id), comment.absolute_url())
|
||||||
|
|
||||||
def test_workflow(self):
|
def test_workflow(self):
|
||||||
# ensure that we can assign a workflow to the comment type and perform
|
self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('simple_publication_workflow,'))
|
||||||
# workflow operations
|
|
||||||
pass
|
conversation = IConversation(self.portal.doc1).__of__(self.portal.doc1)
|
||||||
|
comment1 = createObject('plone.Comment')
|
||||||
|
new_comment1_id = conversation.addComment(comment1)
|
||||||
|
|
||||||
|
comment = conversation[new_comment1_id]
|
||||||
|
|
||||||
|
chain = self.portal.portal_workflow.getChainFor(comment)
|
||||||
|
self.assertEquals(('simple_publication_workflow',), chain)
|
||||||
|
|
||||||
|
# ensure the initial state was entered and recorded
|
||||||
|
self.assertEquals(1, len(comment.workflow_history['simple_publication_workflow']))
|
||||||
|
self.assertEquals(None, comment.workflow_history['simple_publication_workflow'][0]['action'])
|
||||||
|
|
||||||
|
self.assertEquals('private', self.portal.portal_workflow.getInfoFor(comment, 'review_state'))
|
||||||
|
|
||||||
def test_fti(self):
|
def test_fti(self):
|
||||||
# test that we can look up an FTI for Discussion Item
|
# test that we can look up an FTI for Discussion Item
|
||||||
|
@ -6,7 +6,7 @@ BBB support for the old portal_discussion is provided in the bbb package.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from zope import interface
|
from zope import interface
|
||||||
from zope.component import getUtility
|
from zope.component import queryUtility
|
||||||
|
|
||||||
from interfaces import ICommentingTool, IComment
|
from interfaces import ICommentingTool, IComment
|
||||||
|
|
||||||
@ -65,10 +65,16 @@ class CommentingTool(UniqueObject, SimpleItem):
|
|||||||
kw['object_provides'] = object_provides
|
kw['object_provides'] = object_provides
|
||||||
return catalog.searchResults(REQUEST, **kw)
|
return catalog.searchResults(REQUEST, **kw)
|
||||||
|
|
||||||
def object_added_handler(obj, event):
|
def index_object(obj, event):
|
||||||
tool = getUtility(ICommentingTool)
|
"""Index the object when added to the conversation
|
||||||
tool.indexObject(obj)
|
"""
|
||||||
|
tool = queryUtility(ICommentingTool)
|
||||||
|
if tool is not None:
|
||||||
|
tool.indexObject(obj)
|
||||||
|
|
||||||
def object_removed_handler(obj, event):
|
def unindex_object(obj, event):
|
||||||
tool = getUtility(ICommentingTool)
|
"""Unindex the object when removed
|
||||||
tool.unindexObject(obj)
|
"""
|
||||||
|
tool = queryUtility(ICommentingTool)
|
||||||
|
if tool is not None:
|
||||||
|
tool.unindexObject(obj)
|
||||||
|
Loading…
Reference in New Issue
Block a user