From f2f97c5b389f3006dccadbabb32df14ec0ebbb03 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 11 Dec 2010 21:30:18 +0000 Subject: [PATCH] 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 --- plone/app/discussion/browser/controlpanel.pt | 21 ++++++++ plone/app/discussion/browser/controlpanel.py | 43 ++++++++++++--- .../browser/javascripts/controlpanel.js | 53 ++++++++----------- plone/app/discussion/subscribers.zcml | 2 + 4 files changed, 81 insertions(+), 38 deletions(-) diff --git a/plone/app/discussion/browser/controlpanel.pt b/plone/app/discussion/browser/controlpanel.pt index 00c5df2..1fbd431 100644 --- a/plone/app/discussion/browser/controlpanel.pt +++ b/plone/app/discussion/browser/controlpanel.pt @@ -43,6 +43,27 @@ to fix this. + +
+
+ Warning +
+
+ 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 + + Types control panel + + to choose a workflow for the 'Discussion Item' type. +
+
+
Portal status message
diff --git a/plone/app/discussion/browser/controlpanel.py b/plone/app/discussion/browser/controlpanel.py index ad30781..dd2ca1d 100644 --- a/plone/app/discussion/browser/controlpanel.py +++ b/plone/app/discussion/browser/controlpanel.py @@ -8,15 +8,20 @@ from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.statusmessages.interfaces import IStatusMessage +from plone.app.controlpanel.interfaces import IConfigurationChangedEvent + from plone.app.registry.browser import controlpanel 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 z3c.form import button from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget - + from plone.app.discussion.interfaces import IDiscussionSettings, _ @@ -92,7 +97,8 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper): """ registry = queryUtility(IRegistry) settings = registry.forInterface(IDiscussionSettings, check=False) - + wftool = getToolByName(self.context, "portal_workflow", None) + wf = wftool.getChainForPortalType('Discussion Item') output = [] # Globally enabled @@ -100,6 +106,11 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper): output.append("globally_enabled") # 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 if settings.anonymous_comments: @@ -133,13 +144,22 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper): return False 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): """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': @@ -153,9 +173,16 @@ def notify_configuration_changed(event): 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 - + 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 diff --git a/plone/app/discussion/browser/javascripts/controlpanel.js b/plone/app/discussion/browser/javascripts/controlpanel.js index 3c50d51..b416407 100644 --- a/plone/app/discussion/browser/javascripts/controlpanel.js +++ b/plone/app/discussion/browser/javascripts/controlpanel.js @@ -27,46 +27,39 @@ }; /* Update settings */ - $.updateSettings = function () { - + $.updateSettings = function(){ + var globally_enabled = $("#content").hasClass("globally_enabled"); 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"); /* If commenting is globally disabled, disable all settings. */ if (globally_enabled === true) { - $.enableSettings([ - $('#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') - ]); - } 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') - ]); + $.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')]); } - + else { + $.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')]); + } + /* If the mail setup is invalid, disable the mail settings. */ if (invalid_mail_setup === true) { - $.disableSettings([ - $('#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') - ]); + $.disableSettings([$('#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 /************************************************************************** diff --git a/plone/app/discussion/subscribers.zcml b/plone/app/discussion/subscribers.zcml index ebb57dd..c9e63db 100644 --- a/plone/app/discussion/subscribers.zcml +++ b/plone/app/discussion/subscribers.zcml @@ -88,6 +88,8 @@ + +