"Enable comment moderation" setting added to the discussion control panel. Just a proof of concept so far. Not fully implemented yet. No tests.

svn path=/plone.app.discussion/trunk/; revision=46249
This commit is contained in:
Timo Stollenwerk 2010-12-11 17:18:14 +00:00
parent 09a804aa88
commit 0475376ed0
4 changed files with 76 additions and 3 deletions

View File

@ -40,6 +40,8 @@ class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
super(DiscussionSettingsEditForm, self).updateFields()
self.fields['globally_enabled'].widgetFactory = \
SingleCheckBoxFieldWidget
self.fields['moderation_enabled'].widgetFactory = \
SingleCheckBoxFieldWidget
self.fields['anonymous_comments'].widgetFactory = \
SingleCheckBoxFieldWidget
self.fields['show_commenter_image'].widgetFactory = \
@ -97,6 +99,8 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
if settings.globally_enabled:
output.append("globally_enabled")
# Comment moderation
# Anonymous comments
if settings.anonymous_comments:
output.append("anonymous_comments")
@ -127,4 +131,31 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
email = getattr(aq_inner(self.context), 'email_from_address', None)
if mailhost and email:
return False
return True
return True
def notify_configuration_changed(event):
"""Event subscriber that is called every time the configuration changed.
"""
from zope.app.component.hooks import getSite
portal = getSite()
wftool = getToolByName(portal, 'portal_workflow', None)
from plone.registry.interfaces import IRecordModifiedEvent
if IRecordModifiedEvent.providedBy(event):
# Discussion control panel setting changed
if event.record.fieldName == 'moderation_enabled':
# Moderation enabled has changed
if event.record.value == True:
# Enable moderation workflow
wftool.setChainForPortalTypes(('Discussion Item',),
'comment_review_workflow')
else:
# Disable moderation workflow
wftool.setChainForPortalTypes(('Discussion Item',),
'one_state_workflow')
from plone.app.controlpanel.interfaces import IConfigurationChangedEvent
if IConfigurationChangedEvent.providedBy(event):
# Types control panel setting changed
# XXX: Todo!!!
pass

View File

@ -31,7 +31,7 @@ class IDiscussionSettings(Interface):
required=False,
default=True,
)
anonymous_comments = schema.Bool(
title=_(u"label_anonymous_comments",
default="Enable anonymous comments"),
@ -43,6 +43,22 @@ class IDiscussionSettings(Interface):
required=False,
default=False,
)
moderation_enabled = schema.Bool(
title=_(u"label_moderation_enabled",
default="Enable comment moderation"),
description=_(u"help_moderation_enabled",
default=u"If selected, comments will enter a 'Pending' state "
"in which they are invisible to the public. A user "
"with the 'Review comments' permission ('Reviewer' or "
"'Manager') can approve comments to make them visible "
"to the public. If you want to enable a custom "
"comment workflow, you have to go to the types "
"control panel."),
required=False,
default=False,
)
text_transform = schema.Choice(
title=_(u"label_text_transform",

View File

@ -85,7 +85,17 @@
zope.app.container.interfaces.IObjectRemovedEvent"
handler=".comment.notify_content_object_deleted"
/>
</configure>
<subscriber
for="plone.app.controlpanel.interfaces.IConfigurationChangedEvent"
handler=".browser.controlpanel.notify_configuration_changed"
/>
<subscriber
for="plone.registry.interfaces.IRecordModifiedEvent"
handler=".browser.controlpanel.notify_configuration_changed"
/>
</configure>

View File

@ -90,5 +90,21 @@ class RegistryTest(PloneTestCase):
# self.assertEquals(self.registry['plone.app.discussion.interfaces.' +
# 'IDiscussionSettings.user_notification_enabled'], False)
class ConfigurationChangedSubscriberTest(PloneTestCase):
layer = DiscussionLayer
def afterSetUp(self):
self.loginAsPortalOwner()
# Set up the registry
self.registry = Registry()
self.registry.registerInterface(IDiscussionSettings)
def todo(self):
# XXX: Todo!!!
pass
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)