add moderator email setting

svn path=/plone.app.discussion/branches/1.x/; revision=48523
This commit is contained in:
David Glick 2011-04-07 20:02:27 +00:00
parent 6413096336
commit 9aea1915c1
3 changed files with 38 additions and 7 deletions

View File

@ -269,9 +269,12 @@ def notify_user(obj, event):
def notify_moderator(obj, event): def notify_moderator(obj, event):
"""Tell the moderator when a comment needs attention. """Tell the moderator when a comment needs attention.
This method sends an email to the site admin (mail control panel setting) This method sends an email to the moderator if comment moderation is
if comment moderation is enabled and a new comment has been added that enabled and a new comment has been added that needs to be approved.
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 This requires the moderator_notification to be enabled in the discussion
control panel and the comment_review_workflow enabled for the comment control panel and the comment_review_workflow enabled for the comment
@ -289,7 +292,11 @@ def notify_moderator(obj, event):
portal_url = getToolByName(obj, 'portal_url') portal_url = getToolByName(obj, 'portal_url')
portal = portal_url.getPortalObject() portal = portal_url.getPortalObject()
sender = portal.getProperty('email_from_address') 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 # Check if a sender address is available
if not sender: if not sender:

View File

@ -114,6 +114,16 @@ class IDiscussionSettings(Interface):
default=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( user_notification_enabled = schema.Bool(
title=_(u"label_user_notification_enabled", title=_(u"label_user_notification_enabled",
default=u"Enable user email notification"), default=u"Enable user email notification"),

View File

@ -16,7 +16,6 @@ from Products.CMFPlone.tests.utils import MockMailHost
from plone.registry.interfaces import IRegistry from plone.registry.interfaces import IRegistry
from plone.app.discussion.interfaces import IConversation from plone.app.discussion.interfaces import IConversation
from plone.app.discussion.interfaces import IDiscussionSettings
from plone.app.discussion.tests.layer import DiscussionLayer from plone.app.discussion.tests.layer import DiscussionLayer
@ -38,7 +37,6 @@ class TestUserNotificationUnit(PloneTestCase):
# Enable user notification setting # Enable user notification setting
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings)
registry['plone.app.discussion.interfaces.IDiscussionSettings' + registry['plone.app.discussion.interfaces.IDiscussionSettings' +
'.user_notification_enabled'] = True '.user_notification_enabled'] = True
@ -89,7 +87,6 @@ class TestUserNotificationUnit(PloneTestCase):
def test_do_not_notify_user_when_notification_is_disabled(self): def test_do_not_notify_user_when_notification_is_disabled(self):
# Disable user notification and make sure no email is send to the user. # Disable user notification and make sure no email is send to the user.
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings)
registry['plone.app.discussion.interfaces.IDiscussionSettings.' + registry['plone.app.discussion.interfaces.IDiscussionSettings.' +
'user_notification_enabled'] = False 'user_notification_enabled'] = False
@ -242,6 +239,23 @@ class TestModeratorNotificationUnit(PloneTestCase):
# T=C3=A4st user\ntest@plone.test...is sending feedback about the site # T=C3=A4st user\ntest@plone.test...is sending feedback about the site
# you administer at... # 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): 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 # Set sender mail address to nonw and make sure no email is send to the
# moderator. # moderator.