From 1a751b495fb0a46a9e7da9344114b3752da99018 Mon Sep 17 00:00:00 2001 From: Erico Andrei Date: Wed, 27 Apr 2011 17:41:07 +0000 Subject: [PATCH] Unless Discussion Item has an workflow, moderation is not enabled svn path=/plone.app.discussion/trunk/; revision=49135 --- plone/app/discussion/browser/moderation.py | 28 +++++++++++-------- .../discussion/tests/test_moderation_view.py | 4 ++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/plone/app/discussion/browser/moderation.py b/plone/app/discussion/browser/moderation.py index 4209f11..78b3b99 100644 --- a/plone/app/discussion/browser/moderation.py +++ b/plone/app/discussion/browser/moderation.py @@ -39,12 +39,14 @@ class View(BrowserView): """ context = aq_inner(self.context) workflowTool = getToolByName(context, 'portal_workflow') - comment_workflow = workflowTool.getChainForPortalType('Discussion Item')[0] - comment_workflow = workflowTool[comment_workflow] - if 'pending' in comment_workflow.states: - return True - else: - return False + comment_workflow = workflowTool.getChainForPortalType('Discussion Item') + if comment_workflow: + comment_workflow = comment_workflow[0] + comment_workflow = workflowTool[comment_workflow] + if 'pending' in comment_workflow.states: + return True + else: + return class ModerateCommentsEnabled(BrowserView): @@ -56,12 +58,14 @@ class ModerateCommentsEnabled(BrowserView): """ context = aq_inner(self.context) workflowTool = getToolByName(context, 'portal_workflow', None) - comment_workflow = workflowTool.getChainForPortalType('Discussion Item')[0] - comment_workflow = workflowTool[comment_workflow] - if 'pending' in comment_workflow.states: - return True - else: - return + comment_workflow = workflowTool.getChainForPortalType('Discussion Item') + if comment_workflow: + comment_workflow = comment_workflow[0] + comment_workflow = workflowTool[comment_workflow] + if 'pending' in comment_workflow.states: + return True + else: + return class DeleteComment(BrowserView): diff --git a/plone/app/discussion/tests/test_moderation_view.py b/plone/app/discussion/tests/test_moderation_view.py index 3382dd1..d5ecda5 100644 --- a/plone/app/discussion/tests/test_moderation_view.py +++ b/plone/app/discussion/tests/test_moderation_view.py @@ -47,6 +47,9 @@ class ModerationViewTest(unittest.TestCase): """Make sure that moderation_enabled returns true if the comment workflow implements a 'pending' state. """ + # If workflow is not set, enabled must return False + self.wf_tool.setChainForPortalTypes(('Discussion Item',),()) + self.assertEqual(self.view.moderation_enabled(), False) # The one_state_workflow does not have a 'pending' state self.wf_tool.setChainForPortalTypes(('Discussion Item',), ('one_state_workflow,')) @@ -77,7 +80,6 @@ class ModerationViewTest(unittest.TestCase): self.assertTrue('No comments to moderate' in view) self.assertEqual(len(self.view.comments), 0) - class ModerationBulkActionsViewTest(unittest.TestCase): layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING