[dev] added event for comment delete, comment publication + notify for events
This commit is contained in:
parent
3648c3345f
commit
36f0e03805
@ -3,6 +3,8 @@ from AccessControl import getSecurityManager
|
||||
from AccessControl import Unauthorized
|
||||
from Acquisition import aq_inner
|
||||
from Acquisition import aq_parent
|
||||
from plone.app.discussion.events import NotifyOnPublish
|
||||
from plone.app.discussion.events import NotifyOnDelete
|
||||
from plone.app.discussion.interfaces import _
|
||||
from plone.app.discussion.interfaces import IComment
|
||||
from plone.app.discussion.interfaces import IReplies
|
||||
@ -10,6 +12,7 @@ from Products.CMFCore.utils import getToolByName
|
||||
from Products.Five.browser import BrowserView
|
||||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
||||
from Products.statusmessages.interfaces import IStatusMessage
|
||||
from zope.event import notify
|
||||
|
||||
|
||||
class View(BrowserView):
|
||||
@ -100,6 +103,7 @@ class DeleteComment(BrowserView):
|
||||
if self.can_delete(comment):
|
||||
del conversation[comment.id]
|
||||
content_object.reindexObject()
|
||||
notify(NotifyOnDelete(self.context, comment))
|
||||
IStatusMessage(self.context.REQUEST).addStatusMessage(
|
||||
_('Comment deleted.'),
|
||||
type='info')
|
||||
@ -183,6 +187,7 @@ class PublishComment(BrowserView):
|
||||
workflowTool.doActionFor(comment, workflow_action)
|
||||
comment.reindexObject()
|
||||
content_object.reindexObject(idxs=['total_comments'])
|
||||
notify(NotifyOnPublish(self.context, comment))
|
||||
IStatusMessage(self.context.REQUEST).addStatusMessage(
|
||||
_('Comment approved.'),
|
||||
type='info')
|
||||
@ -258,6 +263,7 @@ class BulkActionsView(BrowserView):
|
||||
workflowTool.doActionFor(comment, 'publish')
|
||||
comment.reindexObject()
|
||||
content_object.reindexObject(idxs=['total_comments'])
|
||||
notify(NotifyOnPublish(content_object, comment))
|
||||
|
||||
def mark_as_spam(self):
|
||||
raise NotImplementedError
|
||||
@ -277,3 +283,4 @@ class BulkActionsView(BrowserView):
|
||||
content_object = aq_parent(conversation)
|
||||
del conversation[comment.id]
|
||||
content_object.reindexObject(idxs=['total_comments'])
|
||||
notify(NotifyOnDelete(content_object, comment))
|
||||
|
@ -28,6 +28,18 @@
|
||||
type="plone.contentrules.rule.interfaces.IRuleEventType"
|
||||
name="Comment reply removed"
|
||||
/>
|
||||
|
||||
<interface
|
||||
interface="plone.app.discussion.interfaces.INotifyOnPublish"
|
||||
type="plone.contentrules.rule.interfaces.IRuleEventType"
|
||||
name="Notify user on comment publication"
|
||||
/>
|
||||
|
||||
<interface
|
||||
interface="plone.app.discussion.interfaces.INotifyOnDelete"
|
||||
type="plone.contentrules.rule.interfaces.IRuleEventType"
|
||||
name="Notify user on comment delete"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
||||
@ -54,6 +66,16 @@
|
||||
for="plone.app.discussion.interfaces.IReplyRemovedEvent"
|
||||
handler=".contentrules.execute_comment"
|
||||
/>
|
||||
|
||||
<subscriber
|
||||
for="plone.app.discussion.interfaces.INotifyOnDelete"
|
||||
handler=".contentrules.execute_comment"
|
||||
/>
|
||||
|
||||
<subscriber
|
||||
for="plone.app.discussion.interfaces.INotifyOnPublish"
|
||||
handler=".contentrules.execute_comment"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
from plone.app.discussion.interfaces import ICommentAddedEvent
|
||||
from plone.app.discussion.interfaces import ICommentRemovedEvent
|
||||
from plone.app.discussion.interfaces import IDiscussionEvent
|
||||
from plone.app.discussion.interfaces import INotifyOnDelete
|
||||
from plone.app.discussion.interfaces import INotifyOnPublish
|
||||
from plone.app.discussion.interfaces import IReplyAddedEvent
|
||||
from plone.app.discussion.interfaces import IReplyRemovedEvent
|
||||
from zope.interface import implementer
|
||||
@ -48,3 +50,15 @@ class ReplyAddedEvent(DiscussionEvent):
|
||||
class ReplyRemovedEvent(DiscussionEvent):
|
||||
""" Event to be triggered when a Comment reply is removed
|
||||
"""
|
||||
|
||||
|
||||
@implementer(INotifyOnDelete)
|
||||
class NotifyOnDelete(DiscussionEvent):
|
||||
""" Event to be triggered when a Comment is deleted
|
||||
"""
|
||||
|
||||
|
||||
@implementer(INotifyOnPublish)
|
||||
class NotifyOnPublish(DiscussionEvent):
|
||||
""" Event to be triggered when a Comment is publicated
|
||||
"""
|
||||
|
@ -412,3 +412,13 @@ class IReplyAddedEvent(IDiscussionEvent):
|
||||
class IReplyRemovedEvent(IDiscussionEvent):
|
||||
""" Comment reply removed
|
||||
"""
|
||||
|
||||
|
||||
class INotifyOnPublish(IDiscussionEvent):
|
||||
""" Notify user on comment publication
|
||||
"""
|
||||
|
||||
|
||||
class INotifyOnDelete(IDiscussionEvent):
|
||||
""" Notify user on comment delete
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user