From 910f75aa7e3f98e4467ea5e3aec89765a95af9cf Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 15 Mar 2012 13:06:00 +0100 Subject: [PATCH] Make comments and controlpanel views more robust, so they don't break if no workflow is assigned to the 'Discussion Item' content type. --- CHANGES.txt | 8 +++++ plone/app/discussion/browser/comments.pt | 2 +- plone/app/discussion/browser/comments.py | 18 ++++++----- plone/app/discussion/browser/controlpanel.py | 34 +++++++++++--------- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d834cd5..d029a41 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,14 @@ Changelog ========= +2.1.5 (unreleased) +------------------ + +- Make comments and controlpanel views more robust, so they don't break if no + workflow is assigned to the 'Discussion Item' content type. + [timo] + + 2.1.4 (2012-02-29) ------------------ diff --git a/plone/app/discussion/browser/comments.pt b/plone/app/discussion/browser/comments.pt index bee182f..ac38d1a 100644 --- a/plone/app/discussion/browser/comments.pt +++ b/plone/app/discussion/browser/comments.pt @@ -34,7 +34,7 @@ author_home_url python:view.get_commenter_home_url(username=reply.author_username); has_author_link python:author_home_url and not isAnon; portrait_url python:view.get_commenter_portrait(reply.author_username); - review_state python:wtool.getInfoFor(reply, 'review_state');" + review_state python:wtool.getInfoFor(reply, 'review_state', 'none');" tal:attributes="class python:'comment replyTreeLevel'+str(depth)+' state-'+str(review_state); style string:margin-left: ${depth}em; id string:${reply/getId}" diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 2da56ff..28d4d44 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -310,14 +310,16 @@ class CommentsViewlet(ViewletBase): # comment workflow wftool = getToolByName(context, "portal_workflow", None) - comment_workflow = wftool.getChainForPortalType('Discussion Item')[0] - comment_workflow = wftool[comment_workflow] - # check if the current workflow implements a pending state. If this is - # true comments are moderated - if 'pending' in comment_workflow.states: - message = message + " " + \ - translate(Message(COMMENT_DESCRIPTION_MODERATION_ENABLED), - context=self.request) + workflow_chain = wftool.getChainForPortalType('Discussion Item') + if workflow_chain: + comment_workflow = workflow_chain[0] + comment_workflow = wftool[comment_workflow] + # check if the current workflow implements a pending state. If this + # is true comments are moderated + if 'pending' in comment_workflow.states: + message = message + " " + \ + translate(Message(COMMENT_DESCRIPTION_MODERATION_ENABLED), + context=self.request) return message diff --git a/plone/app/discussion/browser/controlpanel.py b/plone/app/discussion/browser/controlpanel.py index 1e8407e..f993612 100644 --- a/plone/app/discussion/browser/controlpanel.py +++ b/plone/app/discussion/browser/controlpanel.py @@ -99,7 +99,7 @@ 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') + workflow_chain = wftool.getChainForPortalType('Discussion Item') output = [] # Globally enabled @@ -107,8 +107,8 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper): output.append("globally_enabled") # Comment moderation - if 'one_state_workflow' not in wf and \ - 'comment_review_workflow' not in wf: + if 'one_state_workflow' not in workflow_chain and \ + 'comment_review_workflow' not in workflow_chain: output.append("moderation_custom") elif settings.moderation_enabled: output.append("moderation_enabled") @@ -125,9 +125,8 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper): # Workflow wftool = getToolByName(self.context, 'portal_workflow', None) - discussion_workflow = \ - wftool.getChainForPortalType('Discussion Item')[0] - if discussion_workflow: + if workflow_chain: + discussion_workflow = workflow_chain[0] output.append(discussion_workflow) # Merge all settings into one string @@ -150,8 +149,9 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper): """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: + workflow_chain = wftool.getChainForPortalType('Discussion Item') + if 'one_state_workflow' in workflow_chain \ + or 'comment_review_workflow' in workflow_chain: return return True @@ -180,11 +180,13 @@ def notify_configuration_changed(event): 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 + workflow_chain = wftool.getChainForPortalType('Discussion Item') + if workflow_chain: + workflow = workflow_chain[0] + if workflow == 'one_state_workflow': + settings.moderation_enabled = False + elif workflow == 'comment_review_workflow': + settings.moderation_enabled = True + else: + # Custom workflow + pass