From 58f8f4bf22f00752d80a603ccb3acfa8a29d860d Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sun, 18 Oct 2009 13:12:52 +0000 Subject: [PATCH] Do not show "publish" bulk action in moderation view when moderation is disabled. Fix story 1105355 . svn path=/plone.app.discussion/trunk/; revision=30678 --- plone/app/discussion/browser/moderation.pt | 5 +-- plone/app/discussion/browser/moderation.py | 25 +++++++++++++-- .../discussion/tests/test_moderation_view.py | 31 ++++++++++++++----- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/plone/app/discussion/browser/moderation.pt b/plone/app/discussion/browser/moderation.pt index 200b915..118bc97 100644 --- a/plone/app/discussion/browser/moderation.pt +++ b/plone/app/discussion/browser/moderation.pt @@ -14,7 +14,8 @@ Batch python:modules['Products.CMFPlone'].Batch; b_size python:30; b_start python:0; - b_start request/b_start | b_start;"> + b_start request/b_start | b_start; + moderation_enabled view/moderation_enabled;">

Moderate comments @@ -79,7 +80,7 @@ + tal:condition="python: filter != 'published' and moderation_enabled">Publish diff --git a/plone/app/discussion/browser/moderation.py b/plone/app/discussion/browser/moderation.py index 46751e6..675ed95 100644 --- a/plone/app/discussion/browser/moderation.py +++ b/plone/app/discussion/browser/moderation.py @@ -41,8 +41,21 @@ class View(BrowserView): def cook(self, text): return text - def comments_all(self, start=0, size=None): + def moderation_enabled(self): + """Returns true if comment moderation workflow is + enabled on 'Discussion Item' content type. + """ + context = aq_inner(self.context) + wf_tool = getToolByName(context, 'portal_workflow') + if wf_tool.getChainForPortalType('Discussion Item') \ + == ('comment_review_workflow',): + return True + else: + return False + def comments_all(self, start=0, size=None): + """Returns all comments. + """ self.state = self.request.get('review_state', 'pending') self.transition = self.request.get('publish_transition', 'publish') self.limit = self.request.get('limit', 100) @@ -57,6 +70,8 @@ class View(BrowserView): ) def comments_pending(self, start=0, size=None): + """Returns all comments with 'pending' review state. + """ self.state = self.request.get('review_state', 'pending') self.transition = self.request.get('publish_transition', 'publish') self.limit = self.request.get('limit', 100) @@ -72,7 +87,8 @@ class View(BrowserView): ) def comments_published(self, start=0, size=None): - + """Returns all comments with 'published' review state. + """ self.state = self.request.get('review_state', 'pending') self.transition = self.request.get('publish_transition', 'pending') self.limit = self.request.get('limit', 100) @@ -88,8 +104,13 @@ class View(BrowserView): ) def comments_spam(self, start=0, size=None): + """Returns all comments that are marked as spam. + + Not implemented yet. + """ return None + class DeleteComment(BrowserView): """Delete a comment from a conversation """ diff --git a/plone/app/discussion/tests/test_moderation_view.py b/plone/app/discussion/tests/test_moderation_view.py index e862d8a..d791fdd 100644 --- a/plone/app/discussion/tests/test_moderation_view.py +++ b/plone/app/discussion/tests/test_moderation_view.py @@ -17,7 +17,8 @@ from Products.CMFPlone.tests import dummy from Products.PloneTestCase.ptc import PloneTestCase from plone.app.discussion.browser.moderation import View -from plone.app.discussion.interfaces import IConversation, IComment, IReplies, IDiscussionSettings +from plone.app.discussion.interfaces import IConversation, IComment +from plone.app.discussion.interfaces import IReplies, IDiscussionSettings from plone.app.discussion.tests.layer import DiscussionLayer @@ -29,13 +30,17 @@ class ModerationViewTest(PloneTestCase): self.loginAsPortalOwner() typetool = self.portal.portal_types typetool.constructContent('Document', self.portal, 'doc1') - self.portal_discussion = getToolByName(self.portal, 'portal_discussion', None) - self.membership_tool = getToolByName(self.folder, 'portal_membership') + self.portal_discussion = getToolByName(self.portal, + 'portal_discussion', + None) + self.membership_tool = getToolByName(self.folder, + 'portal_membership') self.memberdata = self.portal.portal_memberdata request = self.app.REQUEST context = getattr(self.portal, 'doc1') self.view = View(context, request) - self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), 'comment_review_workflow') + self.portal.portal_workflow.setChainForPortalTypes( + ('Discussion Item',), 'comment_review_workflow') self.wf_tool = self.portal.portal_workflow # Add a conversation with three comments @@ -47,21 +52,30 @@ class ModerationViewTest(PloneTestCase): comment1.text = 'Comment text' comment1.Creator = 'Jim' new_id_1 = conversation.addComment(comment1) - self.comment1 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id_1) + self.comment1 = self.portal.doc1.restrictedTraverse(\ + '++conversation++default/%s' % new_id_1) comment2 = createObject('plone.Comment') comment2.title = 'Comment 2' comment2.text = 'Comment text' comment2.Creator = 'Joe' new_id_2 = conversation.addComment(comment2) - self.comment2 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id_2) + self.comment2 = self.portal.doc1.restrictedTraverse(\ + '++conversation++default/%s' % new_id_2) comment3 = createObject('plone.Comment') comment3.title = 'Comment 3' comment3.text = 'Comment text' comment3.Creator = 'Emma' new_id_3 = conversation.addComment(comment3) - self.comment3 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id_3) + self.comment3 = self.portal.doc1.restrictedTraverse(\ + '++conversation++default/%s' % new_id_3) + + def test_moderation_enabled(self): + self.assertEquals(self.view.moderation_enabled(), True) + self.wf_tool.setChainForPortalTypes(('Discussion Item',), + ('simple_publication_workflow,')) + self.assertEquals(self.view.moderation_enabled(), False) def test_comments_all(self): self.failUnless(self.view.comments_all()) @@ -71,7 +85,8 @@ class ModerationViewTest(PloneTestCase): self.wf_tool.getInfoFor(self.comment1, 'review_state') self.failUnless(self.view.comments_pending()) self.assertEquals(len(self.view.comments_pending()), 3) - self.portal.portal_workflow.doActionFor(self.comment1, action='publish') + self.portal.portal_workflow.doActionFor(self.comment1, + action='publish') #self.comment1.reindexObject() #self.assertEquals(len(self.view.comments_pending()), 2)