"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")
@ -128,3 +132,30 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
if mailhost and email:
return False
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

@ -44,6 +44,22 @@ class IDiscussionSettings(Interface):
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",
default="Comment text transform"),

View File

@ -88,4 +88,14 @@
</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__)