Add links to delete/approve a comment in the moderator notification email.

Remove the unnecessary workflow_action parameter from the PublishComments request.

svn path=/plone.app.discussion/trunk/; revision=49045
This commit is contained in:
Timo Stollenwerk
2011-04-22 17:09:09 +00:00
parent 521ea78ce3
commit e75685d5c0
5 changed files with 144 additions and 126 deletions
+68 -53
View File
@@ -43,83 +43,95 @@ from Products.CMFCore.CMFCatalogAware import WorkflowAware
from OFS.role import RoleManager
COMMENT_TITLE = _(u"comment_title",
COMMENT_TITLE = _(
u"comment_title",
default=u"${creator} on ${content}")
MAIL_NOTIFICATION_MESSAGE = _(u"mail_notification_message",
MAIL_NOTIFICATION_MESSAGE = _(
u"mail_notification_message",
default=u"A comment on '${title}' "
"has been posted here: ${link}\n\n"
"---\n\n"
"${text}"
"---\n"
"${text}\n"
"---\n")
MAIL_NOTIFICATION_MESSAGE_MODERATOR = _(
u"mail_notification_message_moderator",
default=u"A comment on '${title}' "
"has been posted here: ${link}\n\n"
"---\n"
"${text}\n"
"---\n\n"
"Approve comment:\n${link_approve}\n\n"
"Delete comment:\n${link_delete}\n")
logger = logging.getLogger("plone.app.discussion")
class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
RoleManager, Owned, Implicit, Persistent):
"""A comment.
This object attempts to be as lightweight as possible. We implement a
number of standard methods instead of subclassing, to have total control
over what goes into the object.
"""
implements(IComment)
meta_type = portal_type = 'Discussion Item'
# This needs to be kept in sync with types/Discussion_Item.xml title
fti_title = 'Comment'
__parent__ = None
comment_id = None # long
in_reply_to = None # long
title = u""
mime_type = None
text = u""
creator = None
creation_date = None
modification_date = None
author_username = None
author_name = None
author_email = None
user_notification = None
# Note: we want to use zope.component.createObject() to instantiate
# comments as far as possible. comment_id and __parent__ are set via
# IConversation.addComment().
def __init__(self):
self.creation_date = self.modification_date = datetime.utcnow()
@property
def __name__(self):
return self.comment_id and unicode(self.comment_id) or None
@property
def id(self):
return self.comment_id and str(self.comment_id) or None
def getId(self):
"""The id of the comment, as a string.
"""
return self.id
def getText(self, targetMimetype=None):
"""The body text of a comment.
"""
transforms = getToolByName(self, 'portal_transforms')
if targetMimetype is None:
targetMimetype = 'text/x-html-safe'
sourceMimetype = getattr(self, 'mime_type', None)
if sourceMimetype is None:
registry = queryUtility(IRegistry)
@@ -132,7 +144,7 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
text,
context=self,
mimetype=sourceMimetype).getData()
def Title(self):
"""The title of the comment.
"""
@@ -146,7 +158,7 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
else:
creator = self.creator
creator = creator
# Fetch the content object (the parent of the comment is the
# conversation, the parent of the conversation is the content object).
content = aq_base(self.__parent__.__parent__)
@@ -155,30 +167,31 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
mapping={'creator': creator,
'content': safe_unicode(content.Title())}))
return title
def Creator(self):
"""The name of the person who wrote the comment.
"""
return self.creator
def Type(self):
"""The Discussion Item content type.
"""
return self.fti_title
# CMF's event handlers assume any IDynamicType has these :(
def opaqueItems(self): # pragma: no cover
return []
def opaqueIds(self): # pragma: no cover
return []
def opaqueValues(self): # pragma: no cover
return []
CommentFactory = Factory(Comment)
def notify_workflow(obj, event):
"""Tell the workflow tool when a comment is added
"""
@@ -186,6 +199,7 @@ def notify_workflow(obj, event):
if tool is not None:
tool.notifyCreated(obj)
def notify_content_object(obj, event):
"""Tell the content object when a comment is added
"""
@@ -207,20 +221,20 @@ def notify_content_object_deleted(obj, event):
def notify_user(obj, event):
"""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 user notification is enabled
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)
if not settings.user_notification_enabled:
return
# Get informations that are necessary to send an email
mail_host = getToolByName(obj, 'MailHost')
portal_url = getToolByName(obj, 'portal_url')
@@ -273,24 +287,23 @@ 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 moderator 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 a new
comment has been added that needs to be approved.
The moderator_notification setting has to be enabled in the discussion
control panel.
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
content type.
"""
# Check if moderator notification is enabled
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)
if not settings.moderator_notification_enabled:
return
# Get informations that are necessary to send an email
mail_host = getToolByName(obj, 'MailHost')
portal_url = getToolByName(obj, 'portal_url')
@@ -301,24 +314,26 @@ def notify_moderator(obj, event):
mto = settings.moderator_email
else:
mto = sender
# Check if a sender address is available
if not sender:
return
conversation = aq_parent(obj)
content_object = aq_parent(conversation)
# Compose email
#comment = conversation.getComments().next()
subject = translate(_(u"A comment has been posted."), context=obj.REQUEST)
message = translate(Message(MAIL_NOTIFICATION_MESSAGE,
mapping={'title': safe_unicode(content_object.title),
'link': content_object.absolute_url() +
'/view#' + obj.id,
'text': obj.text}),
message = translate(Message(MAIL_NOTIFICATION_MESSAGE_MODERATOR,
mapping={
'title': safe_unicode(content_object.title),
'link': content_object.absolute_url() + '/view#' + obj.id,
'text': obj.text,
'link_approve': obj.absolute_url() + '/@@moderate-publish-comment',
'link_delete': obj.absolute_url() + '/@@moderate-delete-comment',
}),
context=obj.REQUEST)
# Send email
try:
mail_host.send(message, mto, sender, subject, charset='utf-8')