diff --git a/plone/app/discussion/browser/controlpanel.py b/plone/app/discussion/browser/controlpanel.py
index 7f1e01d..ec4bc20 100644
--- a/plone/app/discussion/browser/controlpanel.py
+++ b/plone/app/discussion/browser/controlpanel.py
@@ -30,7 +30,7 @@ class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
self.fields['anonymous_comments'].widgetFactory = SingleCheckBoxFieldWidget
self.fields['show_commenter_image'].widgetFactory = SingleCheckBoxFieldWidget
self.fields['moderator_notification_enabled'].widgetFactory = SingleCheckBoxFieldWidget
- self.fields['notification_enabled'].widgetFactory = SingleCheckBoxFieldWidget
+ self.fields['user_notification_enabled'].widgetFactory = SingleCheckBoxFieldWidget
def updateWidgets(self):
super(DiscussionSettingsEditForm, self).updateWidgets()
@@ -38,7 +38,7 @@ class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
self.widgets['anonymous_comments'].label = _(u"Anonymous Comments")
self.widgets['show_commenter_image'].label = _(u"Commenter Image")
self.widgets['moderator_notification_enabled'].label = _(u"Moderator Email Notification")
- self.widgets['notification_enabled'].label = _(u"Email Notification")
+ self.widgets['user_notification_enabled'].label = _(u"User Email Notification")
class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py
index 1f7ac35..311143e 100644
--- a/plone/app/discussion/comment.py
+++ b/plone/app/discussion/comment.py
@@ -140,24 +140,33 @@ def notify_content_object(obj, event):
def notify_user(obj, event):
"""Tell the user when a comment is added
"""
- conversation = aq_parent(obj)
- content_object = aq_parent(conversation)
+
+ # check if notification is enabled
+ registry = queryUtility(IRegistry)
+ settings = registry.forInterface(IDiscussionSettings)
+ if not settings.user_notification_enabled:
+ return
+
mail_host = getToolByName(obj, 'MailHost')
portal_url = getToolByName(obj, 'portal_url')
-
portal = portal_url.getPortalObject()
sender = portal.getProperty('email_from_address')
if not sender:
return
+
+ conversation = aq_parent(obj)
+ content_object = aq_parent(conversation)
for comment in conversation.getComments():
- if comment.author_notification and comment.author_email:
- subject = "A comment has been posted."
- message = "A comment with the title '%s' has been posted here: %s" \
- % (obj.title,
- content_object.absolute_url(),)
- mail_host.send(message, comment.author_email, sender, subject)
+ if obj != comment and \
+ comment.author_notification and \
+ comment.author_email:
+ subject = "A comment has been posted."
+ message = "A comment with the title '%s' has been posted here: %s" \
+ % (obj.title,
+ content_object.absolute_url(),)
+ mail_host.send(message, comment.author_email, sender, subject)
def notify_moderator(obj, index):
"""Tell the moderator when a comment needs attention
diff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py
index 9740270..00354bf 100644
--- a/plone/app/discussion/interfaces.py
+++ b/plone/app/discussion/interfaces.py
@@ -68,17 +68,18 @@ class IDiscussionSettings(Interface):
required=False,
default=False)
- notification_enabled = schema.Bool(
- title=_(u"label_notification_enabled",
- default=u"Enable email notification"),
- description=_(u"help_notification_enabled",
+ user_notification_enabled = schema.Bool(
+ title=_(u"label_user_notification_enabled",
+ default=u"Enable user email notification"),
+ description=_(u"help_user_notification_enabled",
default=u"If selected, users can "
"choose to be notified "
"of new comments by "
"email."),
required=False,
default=False)
-
+
+
class IConversation(IIterableMapping):
"""A conversation about a content object.
diff --git a/plone/app/discussion/subscribers.zcml b/plone/app/discussion/subscribers.zcml
index 8b23638..8b50424 100644
--- a/plone/app/discussion/subscribers.zcml
+++ b/plone/app/discussion/subscribers.zcml
@@ -37,6 +37,12 @@
handler=".tool.unindex_object"
/>
+
+
+
+
>> 'Subject: =?utf-8?q?Some_t=C3=A4st_subject=2E?=' in msg
+ #True
+
+ #The output should be encoded in a reasonable manner (in this case quoted-printable):
+ #>>> msg
+ #'...Another t=C3=A4st message...You are receiving this mail because T=C3=A4st user\ntest@plone.test...is sending feedback about the site you administer at...
+
+ def test_do_not_notify_user_when_notification_is_disabled(self):
+ # Disable user notification and make sure no email is send to the user.
+ registry = queryUtility(IRegistry)
+ settings = registry.forInterface(IDiscussionSettings)
+ registry['plone.app.discussion.interfaces.IDiscussionSettings.user_notification_enabled'] = False
+
+ comment = createObject('plone.Comment')
+ comment.title = 'Comment 1'
+ comment.text = 'Comment text'
+ comment.author_notification = True
+ comment.author_email = "john@plone.test"
+ self.conversation.addComment(comment)
+
+ comment = createObject('plone.Comment')
+ comment.title = 'Comment 2'
+ comment.text = 'Comment text'
+ self.conversation.addComment(comment)
+
+ self.assertEquals(len(self.mailhost.messages), 0)
+
+ def test_do_not_notify_user_when_email_address_is_given(self):
+ comment = createObject('plone.Comment')
+ comment.title = 'Comment 1'
+ comment.text = 'Comment text'
+ comment.author_notification = True
+ self.conversation.addComment(comment)
+
+ comment = createObject('plone.Comment')
+ comment.title = 'Comment 2'
+ comment.text = 'Comment text'
+ self.conversation.addComment(comment)
+
+ self.assertEquals(len(self.mailhost.messages), 0)
+
+
class TestModeratorNotificationUnit(PloneTestCase):
layer = DiscussionLayer
@@ -49,6 +146,7 @@ class TestModeratorNotificationUnit(PloneTestCase):
settings = registry.forInterface(IDiscussionSettings)
registry['plone.app.discussion.interfaces.IDiscussionSettings.moderator_notification_enabled'] = True
+ # Create test content
self.loginAsPortalOwner()
self.portal.invokeFactory('Document', 'doc1')
self.portal_discussion = self.portal.portal_discussion
@@ -121,4 +219,3 @@ class TestModeratorNotificationUnit(PloneTestCase):
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
-