From dfc6d0620b19399a280695b0f187b0a58a007fad Mon Sep 17 00:00:00 2001 From: Filippo Campi Date: Wed, 27 Jun 2018 15:31:07 +0200 Subject: [PATCH 1/8] [fix] fix load of js in moderation.js --- plone/app/discussion/browser/javascripts/moderation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plone/app/discussion/browser/javascripts/moderation.js b/plone/app/discussion/browser/javascripts/moderation.js index d2a2b9d..55c7972 100644 --- a/plone/app/discussion/browser/javascripts/moderation.js +++ b/plone/app/discussion/browser/javascripts/moderation.js @@ -24,10 +24,10 @@ require([ // jshint ignore:line //#JSCOVERAGE_IF 0 /************************************************************************** - * Window Load Function: Executes when complete page is fully loaded, + * Document Ready Function: Executes when complete page is fully loaded, * including all frames, **************************************************************************/ - $(window).load(function () { + $(document).ready(function () { /********************************************************************** * Delete a single comment. From 36f0e03805c863108d0428a24de9ef85ebf34276 Mon Sep 17 00:00:00 2001 From: Filippo Campi Date: Thu, 27 Sep 2018 11:26:41 +0200 Subject: [PATCH 2/8] [dev] added event for comment delete, comment publication + notify for events --- plone/app/discussion/browser/moderation.py | 7 +++++++ plone/app/discussion/contentrules.zcml | 22 ++++++++++++++++++++++ plone/app/discussion/events.py | 14 ++++++++++++++ plone/app/discussion/interfaces.py | 10 ++++++++++ 4 files changed, 53 insertions(+) diff --git a/plone/app/discussion/browser/moderation.py b/plone/app/discussion/browser/moderation.py index f1623ea..a5f32fd 100644 --- a/plone/app/discussion/browser/moderation.py +++ b/plone/app/discussion/browser/moderation.py @@ -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)) diff --git a/plone/app/discussion/contentrules.zcml b/plone/app/discussion/contentrules.zcml index 5dd222a..a98d47c 100644 --- a/plone/app/discussion/contentrules.zcml +++ b/plone/app/discussion/contentrules.zcml @@ -28,6 +28,18 @@ type="plone.contentrules.rule.interfaces.IRuleEventType" name="Comment reply removed" /> + + + + @@ -54,6 +66,16 @@ for="plone.app.discussion.interfaces.IReplyRemovedEvent" handler=".contentrules.execute_comment" /> + + + + diff --git a/plone/app/discussion/events.py b/plone/app/discussion/events.py index c2cb52d..a38889c 100644 --- a/plone/app/discussion/events.py +++ b/plone/app/discussion/events.py @@ -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 + """ diff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py index 98ce435..10e5f78 100644 --- a/plone/app/discussion/interfaces.py +++ b/plone/app/discussion/interfaces.py @@ -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 + """ From 9b9143df6de0d9cb97a0e9e4f54bc57fe49fabb6 Mon Sep 17 00:00:00 2001 From: Filippo Campi Date: Thu, 27 Sep 2018 23:52:57 +0200 Subject: [PATCH 3/8] [doc] updated CHANGES --- CHANGES.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 74f80da..2bffbb0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,10 +10,14 @@ Breaking changes: New features: -- *add item here* +- Added notification about the publishing or elimination of a comment. + [eikichi18] Bug fixes: +- Changed method that check when the page is fully loaded in moderation.js + [eikichi18] + - Fix location of controlpanel events. [jensens] From 6fed2ad76041064857954992bbaa1c0fd7e9b306 Mon Sep 17 00:00:00 2001 From: Filippo Campi Date: Fri, 28 Sep 2018 16:51:52 +0200 Subject: [PATCH 4/8] [dev] added conditional import for some version of Products.CMFPlone --- plone/app/discussion/browser/controlpanel.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plone/app/discussion/browser/controlpanel.py b/plone/app/discussion/browser/controlpanel.py index 5e904d8..8c88039 100644 --- a/plone/app/discussion/browser/controlpanel.py +++ b/plone/app/discussion/browser/controlpanel.py @@ -6,7 +6,6 @@ from plone.app.registry.browser import controlpanel from plone.registry.interfaces import IRecordModifiedEvent from plone.registry.interfaces import IRegistry from Products.CMFCore.utils import getToolByName -from Products.CMFPlone.interfaces.controlpanel import IConfigurationChangedEvent # noqa: E501 from Products.CMFPlone.interfaces.controlpanel import IMailSchema from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.statusmessages.interfaces import IStatusMessage @@ -17,6 +16,11 @@ from zope.component import getUtility from zope.component import queryUtility from zope.component.hooks import getSite +try: + from Products.CMFPlone.interfaces.controlpanel import IConfigurationChangedEvent # noqa: E501 +except ImportError: + from Products.CMFPlone.interfaces import IConfigurationChangedEvent # noqa: E501 + class DiscussionSettingsEditForm(controlpanel.RegistryEditForm): """Discussion settings form. From 671f0cc796610139bc372239d8a0a7dc51db5d9a Mon Sep 17 00:00:00 2001 From: Filippo Campi Date: Wed, 24 Oct 2018 16:43:38 +0200 Subject: [PATCH 5/8] Removed change from .load to .ready, I'll create another PR --- plone/app/discussion/browser/javascripts/moderation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plone/app/discussion/browser/javascripts/moderation.js b/plone/app/discussion/browser/javascripts/moderation.js index 55c7972..d2a2b9d 100644 --- a/plone/app/discussion/browser/javascripts/moderation.js +++ b/plone/app/discussion/browser/javascripts/moderation.js @@ -24,10 +24,10 @@ require([ // jshint ignore:line //#JSCOVERAGE_IF 0 /************************************************************************** - * Document Ready Function: Executes when complete page is fully loaded, + * Window Load Function: Executes when complete page is fully loaded, * including all frames, **************************************************************************/ - $(document).ready(function () { + $(window).load(function () { /********************************************************************** * Delete a single comment. From 65b187ea536d57d9c276005f49498729c1b9ac1b Mon Sep 17 00:00:00 2001 From: Filippo Campi Date: Wed, 24 Oct 2018 16:46:50 +0200 Subject: [PATCH 6/8] Added comment to try/except on import of IConfigurationChangedEvent --- plone/app/discussion/browser/controlpanel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plone/app/discussion/browser/controlpanel.py b/plone/app/discussion/browser/controlpanel.py index 8c88039..a8ffe95 100644 --- a/plone/app/discussion/browser/controlpanel.py +++ b/plone/app/discussion/browser/controlpanel.py @@ -16,10 +16,12 @@ from zope.component import getUtility from zope.component import queryUtility from zope.component.hooks import getSite +# try/except was added because Configuration Changed Event was moved inside the +# controlpanel file in the PR #2495 on Products.CMFPlone try: from Products.CMFPlone.interfaces.controlpanel import IConfigurationChangedEvent # noqa: E501 except ImportError: - from Products.CMFPlone.interfaces import IConfigurationChangedEvent # noqa: E501 + from Products.CMFPlone.interfaces import IConfigurationChangedEvent class DiscussionSettingsEditForm(controlpanel.RegistryEditForm): From 7bd62fa1cb957fe847dc6f5f4bad4bc7a4f8156e Mon Sep 17 00:00:00 2001 From: Filippo Campi Date: Wed, 24 Oct 2018 16:49:22 +0200 Subject: [PATCH 7/8] Changes NotifyOnDelete to CommentDeletedEvent and NotifyOnPublish to CommentPublishedEvent for respect naming of event and interface --- plone/app/discussion/browser/moderation.py | 12 ++++++------ plone/app/discussion/contentrules.zcml | 8 ++++---- plone/app/discussion/events.py | 12 ++++++------ plone/app/discussion/interfaces.py | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/plone/app/discussion/browser/moderation.py b/plone/app/discussion/browser/moderation.py index a5f32fd..c18be49 100644 --- a/plone/app/discussion/browser/moderation.py +++ b/plone/app/discussion/browser/moderation.py @@ -3,8 +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.events import CommentPublishedEvent +from plone.app.discussion.events import CommentDeletedEvent from plone.app.discussion.interfaces import _ from plone.app.discussion.interfaces import IComment from plone.app.discussion.interfaces import IReplies @@ -103,7 +103,7 @@ class DeleteComment(BrowserView): if self.can_delete(comment): del conversation[comment.id] content_object.reindexObject() - notify(NotifyOnDelete(self.context, comment)) + notify(CommentDeletedEvent(self.context, comment)) IStatusMessage(self.context.REQUEST).addStatusMessage( _('Comment deleted.'), type='info') @@ -187,7 +187,7 @@ class PublishComment(BrowserView): workflowTool.doActionFor(comment, workflow_action) comment.reindexObject() content_object.reindexObject(idxs=['total_comments']) - notify(NotifyOnPublish(self.context, comment)) + notify(CommentPublishedEvent(self.context, comment)) IStatusMessage(self.context.REQUEST).addStatusMessage( _('Comment approved.'), type='info') @@ -263,7 +263,7 @@ class BulkActionsView(BrowserView): workflowTool.doActionFor(comment, 'publish') comment.reindexObject() content_object.reindexObject(idxs=['total_comments']) - notify(NotifyOnPublish(content_object, comment)) + notify(CommentPublishedEvent(content_object, comment)) def mark_as_spam(self): raise NotImplementedError @@ -283,4 +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)) + notify(CommentDeletedEvent(content_object, comment)) diff --git a/plone/app/discussion/contentrules.zcml b/plone/app/discussion/contentrules.zcml index a98d47c..8216946 100644 --- a/plone/app/discussion/contentrules.zcml +++ b/plone/app/discussion/contentrules.zcml @@ -30,13 +30,13 @@ /> @@ -68,12 +68,12 @@ /> diff --git a/plone/app/discussion/events.py b/plone/app/discussion/events.py index a38889c..61d50c4 100644 --- a/plone/app/discussion/events.py +++ b/plone/app/discussion/events.py @@ -4,8 +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 ICommentDeletedEvent +from plone.app.discussion.interfaces import ICommentPublishedEvent from plone.app.discussion.interfaces import IReplyAddedEvent from plone.app.discussion.interfaces import IReplyRemovedEvent from zope.interface import implementer @@ -52,13 +52,13 @@ class ReplyRemovedEvent(DiscussionEvent): """ -@implementer(INotifyOnDelete) -class NotifyOnDelete(DiscussionEvent): +@implementer(ICommentDeletedEvent) +class CommentDeletedEvent(DiscussionEvent): """ Event to be triggered when a Comment is deleted """ -@implementer(INotifyOnPublish) -class NotifyOnPublish(DiscussionEvent): +@implementer(ICommentPublishedEvent) +class CommentPublishedEvent(DiscussionEvent): """ Event to be triggered when a Comment is publicated """ diff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py index 10e5f78..c7f343e 100644 --- a/plone/app/discussion/interfaces.py +++ b/plone/app/discussion/interfaces.py @@ -414,11 +414,11 @@ class IReplyRemovedEvent(IDiscussionEvent): """ -class INotifyOnPublish(IDiscussionEvent): +class ICommentPublishedEvent(IDiscussionEvent): """ Notify user on comment publication """ -class INotifyOnDelete(IDiscussionEvent): +class ICommentDeletedEvent(IDiscussionEvent): """ Notify user on comment delete """ From 63e5b43679d24526aa734d21c2ef27a3b21c4200 Mon Sep 17 00:00:00 2001 From: Filippo Campi Date: Thu, 25 Oct 2018 13:01:03 +0200 Subject: [PATCH 8/8] [doc] Remove js modification from CHANGES --- CHANGES.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1cf523d..7220d75 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,9 +15,6 @@ New features: Bug fixes: -- Changed method that check when the page is fully loaded in moderation.js - [eikichi18] - - Fix location of controlpanel events. [jensens]