Skip to content

Commit

Permalink
Merge pull request #140 from RedTurtle/filippo_moderation_js
Browse files Browse the repository at this point in the history
Notify on comments moderation
  • Loading branch information
jensens authored Oct 25, 2018
2 parents 069b0c4 + 63e5b43 commit 25e85a9
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Breaking changes:

New features:

- *add item here*
- Added notification about the publishing or elimination of a comment.
[eikichi18]

Bug fixes:

Expand Down
8 changes: 7 additions & 1 deletion plone/app/discussion/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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
Expand All @@ -17,6 +16,13 @@
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


class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
"""Discussion settings form.
Expand Down
7 changes: 7 additions & 0 deletions plone/app/discussion/browser/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from AccessControl import Unauthorized
from Acquisition import aq_inner
from Acquisition import aq_parent
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
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):
Expand Down Expand Up @@ -100,6 +103,7 @@ def __call__(self):
if self.can_delete(comment):
del conversation[comment.id]
content_object.reindexObject()
notify(CommentDeletedEvent(self.context, comment))
IStatusMessage(self.context.REQUEST).addStatusMessage(
_('Comment deleted.'),
type='info')
Expand Down Expand Up @@ -183,6 +187,7 @@ def __call__(self):
workflowTool.doActionFor(comment, workflow_action)
comment.reindexObject()
content_object.reindexObject(idxs=['total_comments'])
notify(CommentPublishedEvent(self.context, comment))
IStatusMessage(self.context.REQUEST).addStatusMessage(
_('Comment approved.'),
type='info')
Expand Down Expand Up @@ -258,6 +263,7 @@ def publish(self):
workflowTool.doActionFor(comment, 'publish')
comment.reindexObject()
content_object.reindexObject(idxs=['total_comments'])
notify(CommentPublishedEvent(content_object, comment))

def mark_as_spam(self):
raise NotImplementedError
Expand All @@ -277,3 +283,4 @@ def delete(self):
content_object = aq_parent(conversation)
del conversation[comment.id]
content_object.reindexObject(idxs=['total_comments'])
notify(CommentDeletedEvent(content_object, comment))
22 changes: 22 additions & 0 deletions plone/app/discussion/contentrules.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
type="plone.contentrules.rule.interfaces.IRuleEventType"
name="Comment reply removed"
/>

<interface
interface="plone.app.discussion.interfaces.ICommentPublishedEvent"
type="plone.contentrules.rule.interfaces.IRuleEventType"
name="Notify user on comment publication"
/>

<interface
interface="plone.app.discussion.interfaces.ICommentDeletedEvent"
type="plone.contentrules.rule.interfaces.IRuleEventType"
name="Notify user on comment delete"
/>

</configure>

Expand All @@ -54,6 +66,16 @@
for="plone.app.discussion.interfaces.IReplyRemovedEvent"
handler=".contentrules.execute_comment"
/>

<subscriber
for="plone.app.discussion.interfaces.ICommentDeletedEvent"
handler=".contentrules.execute_comment"
/>

<subscriber
for="plone.app.discussion.interfaces.ICommentPublishedEvent"
handler=".contentrules.execute_comment"
/>

</configure>

Expand Down
14 changes: 14 additions & 0 deletions plone/app/discussion/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down Expand Up @@ -48,3 +50,15 @@ class ReplyAddedEvent(DiscussionEvent):
class ReplyRemovedEvent(DiscussionEvent):
""" Event to be triggered when a Comment reply is removed
"""


@implementer(ICommentDeletedEvent)
class CommentDeletedEvent(DiscussionEvent):
""" Event to be triggered when a Comment is deleted
"""


@implementer(ICommentPublishedEvent)
class CommentPublishedEvent(DiscussionEvent):
""" Event to be triggered when a Comment is publicated
"""
10 changes: 10 additions & 0 deletions plone/app/discussion/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,13 @@ class IReplyAddedEvent(IDiscussionEvent):
class IReplyRemovedEvent(IDiscussionEvent):
""" Comment reply removed
"""


class ICommentPublishedEvent(IDiscussionEvent):
""" Notify user on comment publication
"""


class ICommentDeletedEvent(IDiscussionEvent):
""" Notify user on comment delete
"""

1 comment on commit 25e85a9

@jenkins-plone-org
Copy link

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.discussion/106/violations

plone/app/discussion/catalog.py:17:1: I003 isort expected 1 blank line in imports, found 0
plone/app/discussion/events.py:7:1: I001 isort found an import in the wrong position
plone/app/discussion/events.py:8:1: I001 isort found an import in the wrong position
plone/app/discussion/browser/comment.py:17:1: F811 redefinition of unused 'CommentForm' from line 2
plone/app/discussion/browser/comment.py:17:1: I001 isort found an import in the wrong position
plone/app/discussion/browser/controlpanel.py:18:1: I003 isort expected 1 blank line in imports, found 0
plone/app/discussion/browser/moderation.py:7:1: I001 isort found an import in the wrong position
plone/app/discussion/tests/test_functional.py:34:18: C812 missing trailing comma
plone/app/discussion/tests/test_indexers.py:5:1: I001 isort found an import in the wrong position

Follow these instructions to reproduce it locally.

Please sign in to comment.