2010-07-13 12:41:26 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-06-02 23:20:53 +02:00
|
|
|
|
2010-12-09 09:07:15 +01:00
|
|
|
from Acquisition import aq_base, aq_inner
|
|
|
|
|
2010-12-03 00:20:10 +01:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
|
2010-12-02 19:15:47 +01:00
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
|
|
|
|
2010-11-30 10:06:46 +01:00
|
|
|
from Products.statusmessages.interfaces import IStatusMessage
|
|
|
|
|
2010-12-11 22:30:18 +01:00
|
|
|
from plone.app.controlpanel.interfaces import IConfigurationChangedEvent
|
|
|
|
|
2009-06-02 23:20:53 +02:00
|
|
|
from plone.app.registry.browser import controlpanel
|
|
|
|
|
2010-12-02 19:15:47 +01:00
|
|
|
from plone.registry.interfaces import IRegistry
|
2010-12-11 22:30:18 +01:00
|
|
|
from plone.registry.interfaces import IRecordModifiedEvent
|
|
|
|
|
|
|
|
from zope.app.component.hooks import getSite
|
2009-06-02 23:20:53 +02:00
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
from zope.component import getMultiAdapter, queryUtility
|
2010-12-02 22:07:58 +01:00
|
|
|
|
2010-11-30 10:06:46 +01:00
|
|
|
from z3c.form import button
|
2009-11-19 22:40:08 +01:00
|
|
|
from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-02 19:15:47 +01:00
|
|
|
from plone.app.discussion.interfaces import IDiscussionSettings, _
|
|
|
|
|
2009-06-02 23:20:53 +02:00
|
|
|
|
|
|
|
class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
|
2010-12-09 09:07:15 +01:00
|
|
|
"""Discussion settings form.
|
|
|
|
"""
|
2009-06-02 23:20:53 +02:00
|
|
|
schema = IDiscussionSettings
|
2011-07-15 10:23:08 +02:00
|
|
|
id = "DiscussionSettingsEditForm"
|
2009-06-02 23:20:53 +02:00
|
|
|
label = _(u"Discussion settings")
|
2010-01-24 14:47:39 +01:00
|
|
|
description = _(u"help_discussion_settings_editform",
|
|
|
|
default=u"Some discussion related settings are not located "
|
|
|
|
"in the Discussion Control Panel.\n"
|
2010-12-16 00:52:56 +01:00
|
|
|
"To enable comments for a specific content type, "
|
2010-01-24 14:47:39 +01:00
|
|
|
"go to the Types Control Panel of this type and "
|
2010-08-06 12:01:52 +02:00
|
|
|
"choose \"Allow comments\".\n"
|
2010-01-24 14:47:39 +01:00
|
|
|
"To enable the moderation workflow for comments, "
|
2010-08-31 19:31:27 +02:00
|
|
|
"go to the Types Control Panel, choose "
|
|
|
|
"\"Comment\" and set workflow to "
|
|
|
|
"\"Comment Review Workflow\".")
|
2009-06-02 23:20:53 +02:00
|
|
|
|
|
|
|
def updateFields(self):
|
|
|
|
super(DiscussionSettingsEditForm, self).updateFields()
|
2010-08-31 19:31:27 +02:00
|
|
|
self.fields['globally_enabled'].widgetFactory = \
|
|
|
|
SingleCheckBoxFieldWidget
|
2010-12-11 18:18:14 +01:00
|
|
|
self.fields['moderation_enabled'].widgetFactory = \
|
|
|
|
SingleCheckBoxFieldWidget
|
2010-08-31 19:31:27 +02:00
|
|
|
self.fields['anonymous_comments'].widgetFactory = \
|
|
|
|
SingleCheckBoxFieldWidget
|
|
|
|
self.fields['show_commenter_image'].widgetFactory = \
|
|
|
|
SingleCheckBoxFieldWidget
|
|
|
|
self.fields['moderator_notification_enabled'].widgetFactory = \
|
|
|
|
SingleCheckBoxFieldWidget
|
2010-10-30 17:02:05 +02:00
|
|
|
self.fields['user_notification_enabled'].widgetFactory = \
|
|
|
|
SingleCheckBoxFieldWidget
|
2009-06-02 23:20:53 +02:00
|
|
|
|
|
|
|
def updateWidgets(self):
|
|
|
|
super(DiscussionSettingsEditForm, self).updateWidgets()
|
2010-01-24 14:47:39 +01:00
|
|
|
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")
|
2010-08-31 19:31:27 +02:00
|
|
|
self.widgets['moderator_notification_enabled'].label = \
|
|
|
|
_(u"Moderator Email Notification")
|
2010-10-30 17:02:05 +02:00
|
|
|
self.widgets['user_notification_enabled'].label = \
|
|
|
|
_(u"User Email Notification")
|
2011-07-15 10:23:08 +02:00
|
|
|
|
|
|
|
@button.buttonAndHandler(_('Save'), name=None)
|
2010-11-30 10:06:46 +01:00
|
|
|
def handleSave(self, action):
|
|
|
|
data, errors = self.extractData()
|
|
|
|
if errors:
|
|
|
|
self.status = self.formErrorsMessage
|
|
|
|
return
|
|
|
|
changes = self.applyChanges(data)
|
2010-12-16 00:52:56 +01:00
|
|
|
IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"),
|
2010-11-30 10:06:46 +01:00
|
|
|
"info")
|
|
|
|
self.context.REQUEST.RESPONSE.redirect("@@discussion-settings")
|
|
|
|
|
|
|
|
@button.buttonAndHandler(_('Cancel'), name='cancel')
|
|
|
|
def handleCancel(self, action):
|
2010-12-16 00:52:56 +01:00
|
|
|
IStatusMessage(self.request).addStatusMessage(_(u"Edit cancelled"),
|
2010-11-30 10:06:46 +01:00
|
|
|
"info")
|
2010-12-16 00:52:56 +01:00
|
|
|
self.request.response.redirect("%s/%s" % (self.context.absolute_url(),
|
2010-11-30 10:06:46 +01:00
|
|
|
self.control_panel_view))
|
2010-12-02 22:07:58 +01:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-02 22:07:58 +01:00
|
|
|
class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
|
2010-12-09 09:07:15 +01:00
|
|
|
"""Discussion settings control panel.
|
|
|
|
"""
|
2010-12-02 22:07:58 +01:00
|
|
|
form = DiscussionSettingsEditForm
|
|
|
|
index = ViewPageTemplateFile('controlpanel.pt')
|
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
def settings(self):
|
|
|
|
"""Compose a string that contains all registry settings that are
|
|
|
|
needed for the discussion control panel.
|
2010-12-02 22:07:58 +01:00
|
|
|
"""
|
2010-12-02 19:15:47 +01:00
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings, check=False)
|
2010-12-11 22:30:18 +01:00
|
|
|
wftool = getToolByName(self.context, "portal_workflow", None)
|
|
|
|
wf = wftool.getChainForPortalType('Discussion Item')
|
2010-12-03 00:02:00 +01:00
|
|
|
output = []
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-03 00:20:10 +01:00
|
|
|
# Globally enabled
|
2010-12-03 00:02:00 +01:00
|
|
|
if settings.globally_enabled:
|
|
|
|
output.append("globally_enabled")
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-11 18:18:14 +01:00
|
|
|
# Comment moderation
|
2010-12-11 22:30:18 +01:00
|
|
|
if 'one_state_workflow' not in wf and \
|
|
|
|
'comment_review_workflow' not in wf:
|
2010-12-16 00:52:56 +01:00
|
|
|
output.append("moderation_custom")
|
2010-12-11 22:30:18 +01:00
|
|
|
elif settings.moderation_enabled:
|
|
|
|
output.append("moderation_enabled")
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-03 00:20:10 +01:00
|
|
|
# Anonymous comments
|
2010-12-03 00:02:00 +01:00
|
|
|
if settings.anonymous_comments:
|
|
|
|
output.append("anonymous_comments")
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-03 00:20:10 +01:00
|
|
|
# Invalid mail setting
|
2010-12-02 22:07:58 +01:00
|
|
|
ctrlOverview = getMultiAdapter((self.context, self.request),
|
|
|
|
name='overview-controlpanel')
|
2010-12-03 00:02:00 +01:00
|
|
|
if ctrlOverview.mailhost_warning():
|
|
|
|
output.append("invalid_mail_setup")
|
|
|
|
|
2010-12-03 00:20:10 +01:00
|
|
|
# Workflow
|
|
|
|
wftool = getToolByName(self.context, 'portal_workflow', None)
|
|
|
|
discussion_workflow = wftool.getChainForPortalType('Discussion Item')[0]
|
|
|
|
if discussion_workflow:
|
|
|
|
output.append(discussion_workflow)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-03 00:20:10 +01:00
|
|
|
# Merge all settings into one string
|
2010-12-03 00:02:00 +01:00
|
|
|
return ' '.join(output)
|
2010-12-09 09:07:15 +01:00
|
|
|
|
|
|
|
def mailhost_warning(self):
|
|
|
|
"""Returns true if mailhost is not configured properly.
|
|
|
|
"""
|
|
|
|
# Copied from plone.app.controlpanel/plone/app/controlpanel/overview.py
|
|
|
|
mailhost = getToolByName(aq_inner(self.context), 'MailHost', None)
|
|
|
|
if mailhost is None:
|
|
|
|
return True
|
|
|
|
mailhost = getattr(aq_base(mailhost), 'smtp_host', None)
|
|
|
|
email = getattr(aq_inner(self.context), 'email_from_address', None)
|
|
|
|
if mailhost and email:
|
|
|
|
return False
|
2010-12-11 18:18:14 +01:00
|
|
|
return True
|
|
|
|
|
2010-12-11 22:30:18 +01:00
|
|
|
def custom_comment_workflow_warning(self):
|
|
|
|
"""Returns a warning string if a custom comment workflow is enabled.
|
|
|
|
"""
|
|
|
|
wftool = getToolByName(self.context, "portal_workflow", None)
|
|
|
|
wf = wftool.getChainForPortalType('Discussion Item')
|
|
|
|
if 'one_state_workflow' in wf or 'comment_review_workflow' in wf:
|
|
|
|
return
|
|
|
|
return True
|
2010-12-16 00:52:56 +01:00
|
|
|
|
|
|
|
|
2010-12-11 18:18:14 +01:00
|
|
|
def notify_configuration_changed(event):
|
|
|
|
"""Event subscriber that is called every time the configuration changed.
|
|
|
|
"""
|
|
|
|
portal = getSite()
|
|
|
|
wftool = getToolByName(portal, 'portal_workflow', None)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-11 18:18:14 +01:00
|
|
|
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
|
2010-12-16 00:52:56 +01:00
|
|
|
wftool.setChainForPortalTypes(('Discussion Item',),
|
|
|
|
'comment_review_workflow')
|
2010-12-11 18:18:14 +01:00
|
|
|
else:
|
|
|
|
# Disable moderation workflow
|
2010-12-16 00:52:56 +01:00
|
|
|
wftool.setChainForPortalTypes(('Discussion Item',),
|
2010-12-11 18:18:14 +01:00
|
|
|
'one_state_workflow')
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-11 18:18:14 +01:00
|
|
|
if IConfigurationChangedEvent.providedBy(event):
|
|
|
|
# Types control panel setting changed
|
2010-12-11 22:30:18 +01:00
|
|
|
if 'workflow' in event.data:
|
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings, check=False)
|
|
|
|
wf = wftool.getChainForPortalType('Discussion Item')[0]
|
|
|
|
if wf == 'one_state_workflow':
|
|
|
|
settings.moderation_enabled = False
|
|
|
|
elif wf == 'comment_review_workflow':
|
|
|
|
settings.moderation_enabled = True
|
|
|
|
else:
|
|
|
|
# Custom workflow
|
|
|
|
pass
|