merge c48523 from 1.x branch

svn path=/plone.app.discussion/trunk/; revision=48527
This commit is contained in:
David Glick 2011-04-07 21:31:56 +00:00
parent 42edf85dc5
commit 6d11fa6d5e
4 changed files with 42 additions and 7 deletions

View File

@ -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)
------------------

View File

@ -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:

View File

@ -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",

View File

@ -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