From 6d11fa6d5e0367ec24c895432aec18e7247dada3 Mon Sep 17 00:00:00 2001 From: David Glick Date: Thu, 7 Apr 2011 21:31:56 +0000 Subject: [PATCH] merge c48523 from 1.x branch svn path=/plone.app.discussion/trunk/; revision=48527 --- CHANGES.txt | 4 ++++ plone/app/discussion/comment.py | 15 ++++++++++---- plone/app/discussion/interfaces.py | 10 ++++++++++ .../discussion/tests/test_notifications.py | 20 ++++++++++++++++--- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index fd1a27f..e7e84f9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,10 @@ Changelog 2.0b2 (Unreleased) ------------------ +- Add a moderator_email setting to control where moderator notifications are + sent. + [davisagli] + 2.0b1 (2011-04-06) ------------------ diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 9aa016c..98d8d39 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -271,9 +271,12 @@ def notify_user(obj, event): def notify_moderator(obj, event): """Tell the moderator when a comment needs attention. - This method sends an email to the site admin (mail control panel setting) - if comment moderation is enabled and a new comment has been added that - needs to be approved. + This method sends an email to the moderator if comment moderation is + enabled and a new comment has been added that needs to be approved. + + Configure the moderator e-mail address in the discussion control panel. + If no moderator is configured but moderator notifications are turned on, + the site admin email (from the mail control panel) will be used. This requires the moderator_notification to be enabled in the discussion control panel and the comment_review_workflow enabled for the comment @@ -291,7 +294,11 @@ def notify_moderator(obj, event): portal_url = getToolByName(obj, 'portal_url') portal = portal_url.getPortalObject() sender = portal.getProperty('email_from_address') - mto = portal.getProperty('email_from_address') + + if settings.moderator_email: + mto = settings.moderator_email + else: + mto = sender # Check if a sender address is available if not sender: diff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py index bfdf1a7..794e6f9 100644 --- a/plone/app/discussion/interfaces.py +++ b/plone/app/discussion/interfaces.py @@ -112,6 +112,16 @@ class IDiscussionSettings(Interface): required=False, default=False, ) + + moderator_email = schema.ASCIILine( + title = _(u'label_moderator_email', default=u'Moderator Email Address'), + description = _(u'help_moderator_email', + default=u"Address to which moderator notifications " + u"will be sent. If not specified, the Site " + u"'From' Address from the mail control panel " + u"will be used."), + required = False, + ) user_notification_enabled = schema.Bool( title=_(u"label_user_notification_enabled", diff --git a/plone/app/discussion/tests/test_notifications.py b/plone/app/discussion/tests/test_notifications.py index afd1c81..b78e86a 100644 --- a/plone/app/discussion/tests/test_notifications.py +++ b/plone/app/discussion/tests/test_notifications.py @@ -16,7 +16,6 @@ from Products.CMFPlone.tests.utils import MockMailHost from plone.registry.interfaces import IRegistry from plone.app.discussion.interfaces import IConversation -from plone.app.discussion.interfaces import IDiscussionSettings from plone.app.discussion.tests.layer import DiscussionLayer @@ -38,7 +37,6 @@ class TestUserNotificationUnit(PloneTestCase): # Enable user notification setting registry = queryUtility(IRegistry) - settings = registry.forInterface(IDiscussionSettings) registry['plone.app.discussion.interfaces.IDiscussionSettings' + '.user_notification_enabled'] = True @@ -89,7 +87,6 @@ class TestUserNotificationUnit(PloneTestCase): 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 @@ -235,6 +232,23 @@ class TestModeratorNotificationUnit(PloneTestCase): #'...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_notify_moderator_specific_address(self): + # A moderator email address can be specified in the control panel. + registry = queryUtility(IRegistry) + registry['plone.app.discussion.interfaces.IDiscussionSettings' + + '.moderator_email'] = 'test@example.com' + + comment = createObject('plone.Comment') + comment.text = 'Comment text' + self.conversation.addComment(comment) + + self.assertEquals(len(self.mailhost.messages), 1) + msg = self.mailhost.messages[0] + if not isinstance(msg, str): + self.failUnless('test@example.com' in msg.mto) + else: + self.failUnless('To: test@example.com' in msg) def test_do_not_notify_moderator_when_no_sender_is_available(self): # Set sender mail address to nonw and make sure no email is send to the