Change the comment workflow setting in the discussion control panel if the setting is changed in the types control panel; show warning message and disable the setting if a custom comment workflow is enabled.
svn path=/plone.app.discussion/trunk/; revision=46253
This commit is contained in:
parent
0475376ed0
commit
f2f97c5b38
@ -43,6 +43,27 @@
|
|||||||
to fix this.
|
to fix this.
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
<dl class="portalMessage warning"
|
||||||
|
tal:condition="view/custom_comment_workflow_warning">
|
||||||
|
<dt i18n:translate="">
|
||||||
|
Warning
|
||||||
|
</dt>
|
||||||
|
<dd i18n:translate="text_custom_comment_workflow">
|
||||||
|
You have configured a custom workflow for the 'Discussion Item'
|
||||||
|
content type. You can enable/disable the comment moderation
|
||||||
|
in this control panel only if you use one of the default
|
||||||
|
'Discussion Item' workflows. Go to the
|
||||||
|
<tal:link i18n:name="label_discussion_control_panel_link">
|
||||||
|
<a href=""
|
||||||
|
i18n:translate="text_discussion_type_control_panel_link"
|
||||||
|
tal:attributes="href string:${portal_url}/@@types-controlpanel?type_id=Discussion Item"
|
||||||
|
>Types control panel</a>
|
||||||
|
</tal:link>
|
||||||
|
to choose a workflow for the 'Discussion Item' type.
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
<div metal:use-macro="context/global_statusmessage/macros/portal_message">
|
<div metal:use-macro="context/global_statusmessage/macros/portal_message">
|
||||||
Portal status message
|
Portal status message
|
||||||
</div>
|
</div>
|
||||||
|
@ -8,9 +8,14 @@ from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
|||||||
|
|
||||||
from Products.statusmessages.interfaces import IStatusMessage
|
from Products.statusmessages.interfaces import IStatusMessage
|
||||||
|
|
||||||
|
from plone.app.controlpanel.interfaces import IConfigurationChangedEvent
|
||||||
|
|
||||||
from plone.app.registry.browser import controlpanel
|
from plone.app.registry.browser import controlpanel
|
||||||
|
|
||||||
from plone.registry.interfaces import IRegistry
|
from plone.registry.interfaces import IRegistry
|
||||||
|
from plone.registry.interfaces import IRecordModifiedEvent
|
||||||
|
|
||||||
|
from zope.app.component.hooks import getSite
|
||||||
|
|
||||||
from zope.component import getMultiAdapter, queryUtility
|
from zope.component import getMultiAdapter, queryUtility
|
||||||
|
|
||||||
@ -92,7 +97,8 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
|
|||||||
"""
|
"""
|
||||||
registry = queryUtility(IRegistry)
|
registry = queryUtility(IRegistry)
|
||||||
settings = registry.forInterface(IDiscussionSettings, check=False)
|
settings = registry.forInterface(IDiscussionSettings, check=False)
|
||||||
|
wftool = getToolByName(self.context, "portal_workflow", None)
|
||||||
|
wf = wftool.getChainForPortalType('Discussion Item')
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
# Globally enabled
|
# Globally enabled
|
||||||
@ -100,6 +106,11 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
|
|||||||
output.append("globally_enabled")
|
output.append("globally_enabled")
|
||||||
|
|
||||||
# Comment moderation
|
# Comment moderation
|
||||||
|
if 'one_state_workflow' not in wf and \
|
||||||
|
'comment_review_workflow' not in wf:
|
||||||
|
output.append("moderation_custom")
|
||||||
|
elif settings.moderation_enabled:
|
||||||
|
output.append("moderation_enabled")
|
||||||
|
|
||||||
# Anonymous comments
|
# Anonymous comments
|
||||||
if settings.anonymous_comments:
|
if settings.anonymous_comments:
|
||||||
@ -133,13 +144,22 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def notify_configuration_changed(event):
|
def notify_configuration_changed(event):
|
||||||
"""Event subscriber that is called every time the configuration changed.
|
"""Event subscriber that is called every time the configuration changed.
|
||||||
"""
|
"""
|
||||||
from zope.app.component.hooks import getSite
|
|
||||||
portal = getSite()
|
portal = getSite()
|
||||||
wftool = getToolByName(portal, 'portal_workflow', None)
|
wftool = getToolByName(portal, 'portal_workflow', None)
|
||||||
from plone.registry.interfaces import IRecordModifiedEvent
|
|
||||||
if IRecordModifiedEvent.providedBy(event):
|
if IRecordModifiedEvent.providedBy(event):
|
||||||
# Discussion control panel setting changed
|
# Discussion control panel setting changed
|
||||||
if event.record.fieldName == 'moderation_enabled':
|
if event.record.fieldName == 'moderation_enabled':
|
||||||
@ -153,9 +173,16 @@ def notify_configuration_changed(event):
|
|||||||
wftool.setChainForPortalTypes(('Discussion Item',),
|
wftool.setChainForPortalTypes(('Discussion Item',),
|
||||||
'one_state_workflow')
|
'one_state_workflow')
|
||||||
|
|
||||||
from plone.app.controlpanel.interfaces import IConfigurationChangedEvent
|
|
||||||
if IConfigurationChangedEvent.providedBy(event):
|
if IConfigurationChangedEvent.providedBy(event):
|
||||||
# Types control panel setting changed
|
# Types control panel setting changed
|
||||||
# XXX: Todo!!!
|
if 'workflow' in event.data:
|
||||||
pass
|
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
|
||||||
|
@ -27,46 +27,39 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Update settings */
|
/* Update settings */
|
||||||
$.updateSettings = function () {
|
$.updateSettings = function(){
|
||||||
|
|
||||||
var globally_enabled = $("#content").hasClass("globally_enabled");
|
var globally_enabled = $("#content").hasClass("globally_enabled");
|
||||||
var anonymous_comments = $("#content").hasClass("anonymous_comments");
|
var anonymous_comments = $("#content").hasClass("anonymous_comments");
|
||||||
|
var moderation_enabled = $("#content").hasClass("moderation_enabled");
|
||||||
|
var moderation_custom = $("#content").hasClass("moderation_custom");
|
||||||
var invalid_mail_setup = $("#content").hasClass("invalid_mail_setup");
|
var invalid_mail_setup = $("#content").hasClass("invalid_mail_setup");
|
||||||
|
|
||||||
/* If commenting is globally disabled, disable all settings. */
|
/* If commenting is globally disabled, disable all settings. */
|
||||||
if (globally_enabled === true) {
|
if (globally_enabled === true) {
|
||||||
$.enableSettings([
|
$.enableSettings([$('#formfield-form-widgets-anonymous_comments'), $('#formfield-form-widgets-moderation_enabled'), $('#formfield-form-widgets-text_transform'), $('#formfield-form-widgets-captcha'), $('#formfield-form-widgets-show_commenter_image'), $('#formfield-form-widgets-moderator_notification_enabled'), $('#formfield-form-widgets-user_notification_enabled')]);
|
||||||
$('#formfield-form-widgets-anonymous_comments'),
|
}
|
||||||
$('#formfield-form-widgets-text_transform'),
|
else {
|
||||||
$('#formfield-form-widgets-captcha'),
|
$.disableSettings([$('#formfield-form-widgets-anonymous_comments'), $('#formfield-form-widgets-moderation_enabled'), $('#formfield-form-widgets-text_transform'), $('#formfield-form-widgets-captcha'), $('#formfield-form-widgets-show_commenter_image'), $('#formfield-form-widgets-moderator_notification_enabled'), $('#formfield-form-widgets-user_notification_enabled')]);
|
||||||
$('#formfield-form-widgets-show_commenter_image'),
|
|
||||||
$('#formfield-form-widgets-moderator_notification_enabled'),
|
|
||||||
$('#formfield-form-widgets-user_notification_enabled')
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$.disableSettings([
|
|
||||||
$('#formfield-form-widgets-anonymous_comments'),
|
|
||||||
$('#formfield-form-widgets-text_transform'),
|
|
||||||
$('#formfield-form-widgets-captcha'),
|
|
||||||
$('#formfield-form-widgets-show_commenter_image'),
|
|
||||||
$('#formfield-form-widgets-moderator_notification_enabled'),
|
|
||||||
$('#formfield-form-widgets-user_notification_enabled')
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the mail setup is invalid, disable the mail settings. */
|
/* If the mail setup is invalid, disable the mail settings. */
|
||||||
if (invalid_mail_setup === true) {
|
if (invalid_mail_setup === true) {
|
||||||
$.disableSettings([
|
$.disableSettings([$('#formfield-form-widgets-moderator_notification_enabled'), $('#formfield-form-widgets-user_notification_enabled')]);
|
||||||
$('#formfield-form-widgets-moderator_notification_enabled'),
|
|
||||||
$('#formfield-form-widgets-user_notification_enabled')
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$.enableSettings([
|
|
||||||
$('#formfield-form-widgets-moderator_notification_enabled'),
|
|
||||||
$('#formfield-form-widgets-user_notification_enabled')
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
};
|
else {
|
||||||
|
$.enableSettings([$('#formfield-form-widgets-moderator_notification_enabled'), $('#formfield-form-widgets-user_notification_enabled')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If a custom workflow for comments is enabled, disable the moderation
|
||||||
|
switch. */
|
||||||
|
if (moderation_custom === true) {
|
||||||
|
$.disableSettings([$('#formfield-form-widgets-moderation_enabled'), ]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$.enableSettings([$('#formfield-form-widgets-moderation_enabled'), ]);
|
||||||
|
}
|
||||||
|
}
|
||||||
//#JSCOVERAGE_IF 0
|
//#JSCOVERAGE_IF 0
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
@ -88,6 +88,8 @@
|
|||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
|
||||||
|
<!-- Control panel event subscribers -->
|
||||||
|
|
||||||
<subscriber
|
<subscriber
|
||||||
for="plone.app.controlpanel.interfaces.IConfigurationChangedEvent"
|
for="plone.app.controlpanel.interfaces.IConfigurationChangedEvent"
|
||||||
handler=".browser.controlpanel.notify_configuration_changed"
|
handler=".browser.controlpanel.notify_configuration_changed"
|
||||||
|
Loading…
Reference in New Issue
Block a user