Comments added to the notification subscriber functions.

svn path=/plone.app.discussion/trunk/; revision=37329
This commit is contained in:
Timo Stollenwerk 2010-06-17 06:57:51 +00:00
parent 3f36e09728
commit 400956e264

View File

@ -155,23 +155,33 @@ def notify_content_object_deleted(obj, event):
del conversation[comment.id] del conversation[comment.id]
def notify_user(obj, event): def notify_user(obj, event):
"""Tell the user when a comment is added """Tell users when a comment has been added.
This method composes and sends emails to all users that have added a
comment to this conversation and enabled user notification.
This requires the user_notification setting to be enabled in the
discussion control panel.
""" """
# check if notification is enabled # Check if user notification is enabled
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings) settings = registry.forInterface(IDiscussionSettings)
if not settings.user_notification_enabled: if not settings.user_notification_enabled:
return return
# Get informations that are necessary to send an email
mail_host = getToolByName(obj, 'MailHost') mail_host = getToolByName(obj, 'MailHost')
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')
# Check if a sender address is available
if not sender: if not sender:
return return
# Compose and send emails to all users that have add a comment to this
# conversation and enabled author_notification.
conversation = aq_parent(obj) conversation = aq_parent(obj)
content_object = aq_parent(conversation) content_object = aq_parent(conversation)
@ -186,39 +196,51 @@ def notify_user(obj, event):
mail_host.send(message, comment.author_email, sender, subject) mail_host.send(message, comment.author_email, sender, subject)
def notify_moderator(obj, index): def notify_moderator(obj, index):
"""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)
if comment moderation is enabled and a new comment has been added that
needs to be approved.
This requires the moderator_notification to be enabled in the discussion
control panel and the comment_review_workflow enabled for the comment
content type.
""" """
# check if notification is enabled # Check if moderator notification is enabled
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings) settings = registry.forInterface(IDiscussionSettings)
if not settings.moderator_notification_enabled: if not settings.moderator_notification_enabled:
return return
# check if comment review workflow is enabled # Check if comment review workflow is enabled
wf = getToolByName(obj, 'portal_workflow') wf = getToolByName(obj, 'portal_workflow')
if wf.getChainForPortalType('Discussion Item') != \ if wf.getChainForPortalType('Discussion Item') != \
('comment_review_workflow',): ('comment_review_workflow',):
return return
# Get informations that are necessary to send an email
mail_host = getToolByName(obj, 'MailHost') mail_host = getToolByName(obj, 'MailHost')
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') mto = portal.getProperty('email_from_address')
# check if a sender address is available # Check if a sender address is available
if not sender: if not sender:
return return
conversation = aq_parent(obj) conversation = aq_parent(obj)
content_object = aq_parent(conversation) content_object = aq_parent(conversation)
# Compose email
comment = conversation.getComments().next() comment = conversation.getComments().next()
subject = "A comment has been posted." subject = "A comment has been posted."
message = "A comment with the title '%s' has been posted here: %s" \ message = "A comment with the title '%s' has been posted here: %s" \
% (obj.title, % (obj.title,
content_object.absolute_url(),) content_object.absolute_url(),)
# Send email
if PLONE_4: if PLONE_4:
mail_host.send(message, mto, sender, subject) mail_host.send(message, mto, sender, subject)
else: else: