diff --git a/CHANGES.txt b/CHANGES.txt index a0c55a6..6905074 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,17 @@ Changelog 1.0b4 (unreleased) ------------------ +* New feature: As a moderator, I am notified when new comments require my + attention. + [timo] + +* New feature: As a commenter, I can enable/disable email notification of + additional comments on this object + [timo] + +* Make p.a.d. work with the recent version of plone.z3cform (0.5.10) + [timo] + * Make p.a.d. styles less generic. This fixes #10253. [timo] diff --git a/plone/app/discussion/browser/comments.pt b/plone/app/discussion/browser/comments.pt index 9521c57..974d8e8 100644 --- a/plone/app/discussion/browser/comments.pt +++ b/plone/app/discussion/browser/comments.pt @@ -150,7 +150,7 @@ formatting.
- + diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 3b0fa84..e73dfcd 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -18,7 +18,9 @@ from zope.interface import Interface, implements from zope.viewlet.interfaces import IViewlet from z3c.form import form, field, button, interfaces, widget +from z3c.form.interfaces import IFormLayer from z3c.form.browser.textarea import TextAreaWidget +from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget from Products.Five.browser import BrowserView from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile @@ -55,19 +57,29 @@ class CommentForm(extensible.ExtensibleForm, form.Form): 'modification_date', 'author_username') + def updateFields(self): + super(CommentForm, self).updateFields() + self.fields['author_notification'].widgetFactory = SingleCheckBoxFieldWidget + def updateWidgets(self): super(CommentForm, self).updateWidgets() + + # Widgets self.widgets['in_reply_to'].mode = interfaces.HIDDEN_MODE - portal_membership = getToolByName(self.context, 'portal_membership') self.widgets['text'].addClass("autoresize") + self.widgets['author_notification'].label = _(u"") + + # Anonymous / Logged-in + portal_membership = getToolByName(self.context, 'portal_membership') if not portal_membership.isAnonymousUser(): self.widgets['author_name'].mode = interfaces.HIDDEN_MODE self.widgets['author_email'].mode = interfaces.HIDDEN_MODE - # XXX: Since we are not using the author_email field in the - # current state, we hide it by default. But we keep the field for - # integrators or later use. - self.widgets['author_email'].mode = interfaces.HIDDEN_MODE + # Notification enabled + registry = queryUtility(IRegistry) + settings = registry.forInterface(IDiscussionSettings) + if not settings.user_notification_enabled: + self.widgets['author_notification'].mode = interfaces.HIDDEN_MODE def updateActions(self): super(CommentForm, self).updateActions() @@ -86,6 +98,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form): author_name = u"" author_username = u"" author_email = u"" + author_notification = None # Captcha check for anonymous users (if Captcha is enabled) registry = queryUtility(IRegistry) @@ -110,7 +123,9 @@ class CommentForm(extensible.ExtensibleForm, form.Form): author_username = data['author_username'] if 'author_email' in data: author_email = data['author_email'] - + if 'author_notification' in data: + author_notification = data['author_notification'] + # The add-comment view is called on the conversation object conversation = IConversation(self.__parent__) @@ -130,6 +145,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form): comment.creator = author_name comment.author_name = author_name comment.author_email = author_email + comment.author_notification = author_notification comment.creation_date = comment.modification_date = datetime.now() else: member = portal_membership.getAuthenticatedMember() @@ -141,6 +157,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form): comment.author_username = member.getUserName() comment.author_name = member.getProperty('fullname') comment.author_email = member.getProperty('email') + comment.author_notification = comment.author_notification comment.creation_date = comment.modification_date = datetime.now() # Check if the added comment is a reply to an existing comment @@ -174,25 +191,16 @@ class CommentForm(extensible.ExtensibleForm, form.Form): pass -class CommentsViewlet(ViewletBase, layout.FormWrapper): +class CommentsViewlet(ViewletBase): form = CommentForm - index = ViewPageTemplateFile('comments.pt') - def __init__(self, context, request, view, manager): - super(CommentsViewlet, self).__init__(context, request, view, manager) - if self.form is not None: - self.form_instance = self.form(self.context.aq_inner, self.request) - self.form_instance.__name__ = self.__name__ - - self.portal_discussion = getToolByName(self.context, 'portal_discussion', None) - self.portal_membership = getToolByName(self.context, 'portal_membership', None) - - def render_form(self): - z2.switch_on(self, request_layer=self.request_layer) - self.form.update(self.form_instance) - return self.form.render(self.form_instance) + def update(self): + super(CommentsViewlet, self).update() + z2.switch_on(self, request_layer=IFormLayer) + self.form = CommentForm(aq_inner(self.context), self.request) + self.form.update() # view methods @@ -291,7 +299,8 @@ class CommentsViewlet(ViewletBase, layout.FormWrapper): return settings.show_commenter_image def is_anonymous(self): - return self.portal_membership.isAnonymousUser() + portal_membership = getToolByName(self.context, 'portal_membership', None) + return portal_membership.isAnonymousUser() def login_action(self): return '%s/login_form?came_from=%s' % (self.navigation_root_url, url_quote(self.request.get('URL', '')),) diff --git a/plone/app/discussion/browser/controlpanel.py b/plone/app/discussion/browser/controlpanel.py index b7d0c91..ec4bc20 100644 --- a/plone/app/discussion/browser/controlpanel.py +++ b/plone/app/discussion/browser/controlpanel.py @@ -29,12 +29,16 @@ class DiscussionSettingsEditForm(controlpanel.RegistryEditForm): self.fields['globally_enabled'].widgetFactory = SingleCheckBoxFieldWidget self.fields['anonymous_comments'].widgetFactory = SingleCheckBoxFieldWidget self.fields['show_commenter_image'].widgetFactory = SingleCheckBoxFieldWidget + self.fields['moderator_notification_enabled'].widgetFactory = SingleCheckBoxFieldWidget + self.fields['user_notification_enabled'].widgetFactory = SingleCheckBoxFieldWidget def updateWidgets(self): super(DiscussionSettingsEditForm, self).updateWidgets() self.widgets['globally_enabled'].label = _(u"Enable Comments") self.widgets['anonymous_comments'].label = _(u"Anonymous Comments") self.widgets['show_commenter_image'].label = _(u"Commenter Image") + self.widgets['moderator_notification_enabled'].label = _(u"Moderator Email Notification") + self.widgets['user_notification_enabled'].label = _(u"User Email Notification") class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper): diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 7a39a8c..311143e 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -1,10 +1,14 @@ """The default comment class and factory. """ from datetime import datetime + from zope.interface import implements + from zope.component.factory import Factory +from zope.component import queryUtility from Acquisition import aq_parent, Implicit + from AccessControl.Role import RoleManager from AccessControl.Owned import Owned @@ -15,7 +19,9 @@ from Products.CMFCore.utils import getToolByName from OFS.Traversable import Traversable -from plone.app.discussion.interfaces import IComment +from plone.registry.interfaces import IRegistry + +from plone.app.discussion.interfaces import IComment, IDiscussionSettings try: # Plone 4: @@ -61,6 +67,8 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable, author_name = None author_email = None + + author_notification = None # Note: we want to use zope.component.createObject() to instantiate # comments as far as possible. comment_id and __parent__ are set via @@ -125,4 +133,73 @@ def notify_content_object(obj, event): """Tell the content object when a comment is added """ content_obj = aq_parent(aq_parent(obj)) - content_obj.reindexObject(idxs=('total_comments', 'last_comment_date', 'commentators',)) + content_obj.reindexObject(idxs=('total_comments', + 'last_comment_date', + 'commentators',)) + +def notify_user(obj, event): + """Tell the user when a comment is added + """ + + # check if notification is enabled + registry = queryUtility(IRegistry) + settings = registry.forInterface(IDiscussionSettings) + if not settings.user_notification_enabled: + return + + mail_host = getToolByName(obj, 'MailHost') + portal_url = getToolByName(obj, 'portal_url') + portal = portal_url.getPortalObject() + sender = portal.getProperty('email_from_address') + + if not sender: + return + + conversation = aq_parent(obj) + content_object = aq_parent(conversation) + + for comment in conversation.getComments(): + if obj != comment and \ + comment.author_notification and \ + comment.author_email: + subject = "A comment has been posted." + message = "A comment with the title '%s' has been posted here: %s" \ + % (obj.title, + content_object.absolute_url(),) + mail_host.send(message, comment.author_email, sender, subject) + +def notify_moderator(obj, index): + """Tell the moderator when a comment needs attention + """ + + # check if notification is enabled + registry = queryUtility(IRegistry) + settings = registry.forInterface(IDiscussionSettings) + if not settings.moderator_notification_enabled: + return + + # check if comment review workflow is enabled + wf = getToolByName(obj, 'portal_workflow') + if wf.getChainForPortalType('Discussion Item') != \ + ('comment_review_workflow',): + return + + mail_host = getToolByName(obj, 'MailHost') + portal_url = getToolByName(obj, 'portal_url') + portal = portal_url.getPortalObject() + sender = portal.getProperty('email_from_address') + mto = portal.getProperty('email_from_address') + + # check if a sender address is available + if not sender: + return + + conversation = aq_parent(obj) + content_object = aq_parent(conversation) + + comment = conversation.getComments().next() + subject = "A comment has been posted." + message = "A comment with the title '%s' has been posted here: %s" \ + % (obj.title, + content_object.absolute_url(),) + mail_host.send(message, mto, sender, subject) diff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py index 08f7b73..00354bf 100644 --- a/plone/app/discussion/interfaces.py +++ b/plone/app/discussion/interfaces.py @@ -55,6 +55,31 @@ class IDiscussionSettings(Interface): required=False, default=True) + moderator_notification_enabled = schema.Bool( + title=_(u"label_moderator_notification_enabled", + default=u"Enable moderator email notification"), + description=_(u"help_moderator_notification_enabled", + default=u"If selected, " + "the moderator " + "is notified " + "if a comment " + "needs " + "attention."), + required=False, + default=False) + + user_notification_enabled = schema.Bool( + title=_(u"label_user_notification_enabled", + default=u"Enable user email notification"), + description=_(u"help_user_notification_enabled", + default=u"If selected, users can " + "choose to be notified " + "of new comments by " + "email."), + required=False, + default=False) + + class IConversation(IIterableMapping): """A conversation about a content object. @@ -157,7 +182,8 @@ class IComment(Interface): Comments are indexed in the catalog and subject to workflow and security. """ - portal_type = schema.ASCIILine(title=_(u"Portal type"), default="Discussion Item") + portal_type = schema.ASCIILine(title=_(u"Portal type"), + default="Discussion Item") __parent__ = schema.Object(title=_(u"Conversation"), schema=Interface) __name__ = schema.TextLine(title=_(u"Name")) @@ -171,12 +197,16 @@ class IComment(Interface): # for anonymous comments only, set to None for logged in comments author_name = schema.TextLine(title=_(u"Name"), required=False) author_email = schema.TextLine(title=_(u"Email"), required=False) - + title = schema.TextLine(title=_(u"Subject")) mime_type = schema.ASCIILine(title=_(u"MIME type"), default="text/plain") text = schema.Text(title=_(u"Comment")) + author_notification = schema.Bool(title=_(u"Notify me of new comments via " + "email."), + required=False) + creator = schema.TextLine(title=_(u"Author name (for display)")) creation_date = schema.Date(title=_(u"Creation date")) modification_date = schema.Date(title=_(u"Modification date")) diff --git a/plone/app/discussion/subscribers.zcml b/plone/app/discussion/subscribers.zcml index 1be80e1..8b50424 100644 --- a/plone/app/discussion/subscribers.zcml +++ b/plone/app/discussion/subscribers.zcml @@ -37,6 +37,18 @@ handler=".tool.unindex_object" /> +