From 6f3fa11f10cad4163ed37a4f13ae638244cadf9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Andrei?= Date: Wed, 8 Sep 2021 13:02:34 +0200 Subject: [PATCH] Implement events for Comment (ICommentModifiedEvent) and Reply(IReplyModifiedEvent) modification --- news/183.feature | 1 + plone/app/discussion/comment.py | 12 +++++ plone/app/discussion/events.py | 14 ++++++ plone/app/discussion/interfaces.py | 10 ++++ plone/app/discussion/subscribers.zcml | 6 +++ plone/app/discussion/tests/test_events.py | 56 +++++++++++++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 news/183.feature diff --git a/news/183.feature b/news/183.feature new file mode 100644 index 0000000..013640b --- /dev/null +++ b/news/183.feature @@ -0,0 +1 @@ +Implement events for Comment (ICommentModifiedEvent) and Reply(IReplyModifiedEvent) modification [ericof] \ No newline at end of file diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 41d430f..cc1099f 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -13,8 +13,10 @@ from OFS.Traversable import Traversable from persistent import Persistent from plone.app.discussion import _ from plone.app.discussion.events import CommentAddedEvent +from plone.app.discussion.events import CommentModifiedEvent from plone.app.discussion.events import CommentRemovedEvent from plone.app.discussion.events import ReplyAddedEvent +from plone.app.discussion.events import ReplyModifiedEvent from plone.app.discussion.events import ReplyRemovedEvent from plone.app.discussion.interfaces import IComment from plone.app.discussion.interfaces import IConversation @@ -258,6 +260,16 @@ def notify_comment_added(obj, event): return notify(CommentAddedEvent(context, obj)) +def notify_comment_modified(obj, event): + """ Notify custom discussion events when a comment, or a reply, is modified + """ + conversation = aq_parent(obj) + context = aq_parent(conversation) + if getattr(obj, 'in_reply_to', None): + return notify(ReplyModifiedEvent(context, obj)) + return notify(CommentModifiedEvent(context, obj)) + + def notify_comment_removed(obj, event): """ Notify custom discussion events when a comment or reply is removed """ diff --git a/plone/app/discussion/events.py b/plone/app/discussion/events.py index 08925bb..e2ecc02 100644 --- a/plone/app/discussion/events.py +++ b/plone/app/discussion/events.py @@ -2,12 +2,14 @@ """ Custom discussion events """ from plone.app.discussion.interfaces import ICommentAddedEvent +from plone.app.discussion.interfaces import ICommentModifiedEvent from plone.app.discussion.interfaces import ICommentRemovedEvent from plone.app.discussion.interfaces import IDiscussionEvent from plone.app.discussion.interfaces import ICommentDeletedEvent from plone.app.discussion.interfaces import ICommentPublishedEvent from plone.app.discussion.interfaces import ICommentTransitionEvent from plone.app.discussion.interfaces import IReplyAddedEvent +from plone.app.discussion.interfaces import IReplyModifiedEvent from plone.app.discussion.interfaces import IReplyRemovedEvent from zope.interface import implementer @@ -35,6 +37,12 @@ class CommentAddedEvent(DiscussionEvent): """ +@implementer(ICommentModifiedEvent) +class CommentModifiedEvent(DiscussionEvent): + """ Event to be triggered when a Comment is modified + """ + + @implementer(ICommentRemovedEvent) class CommentRemovedEvent(DiscussionEvent): """ Event to be triggered when a Comment is removed @@ -47,6 +55,12 @@ class ReplyAddedEvent(DiscussionEvent): """ +@implementer(IReplyModifiedEvent) +class ReplyModifiedEvent(DiscussionEvent): + """ Event to be triggered when a Comment reply is modified + """ + + @implementer(IReplyRemovedEvent) class ReplyRemovedEvent(DiscussionEvent): """ Event to be triggered when a Comment reply is removed diff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py index c03c0bb..76a0cee 100644 --- a/plone/app/discussion/interfaces.py +++ b/plone/app/discussion/interfaces.py @@ -399,6 +399,11 @@ class ICommentAddedEvent(IDiscussionEvent): """ +class ICommentModifiedEvent(IDiscussionEvent): + """ Comment modified + """ + + class ICommentRemovedEvent(IDiscussionEvent): """ Comment removed """ @@ -409,6 +414,11 @@ class IReplyAddedEvent(IDiscussionEvent): """ +class IReplyModifiedEvent(IDiscussionEvent): + """ Comment reply modified + """ + + class IReplyRemovedEvent(IDiscussionEvent): """ Comment reply removed """ diff --git a/plone/app/discussion/subscribers.zcml b/plone/app/discussion/subscribers.zcml index 20e1b7f..85e74e2 100644 --- a/plone/app/discussion/subscribers.zcml +++ b/plone/app/discussion/subscribers.zcml @@ -9,6 +9,12 @@ handler=".comment.notify_workflow" /> + + + + + +