From 352a517a0a21d84b907d527fe79473e9a9256507 Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Fri, 20 Aug 2010 11:52:05 +0000 Subject: [PATCH] Fixed the case where a folder has allow_discussion=False and conversation.enabled() on a document in this folder returned False instead of True because of allow_discussion acquisition. svn path=/plone.app.discussion/trunk/; revision=38835 --- CHANGES.txt | 5 ++++ plone/app/discussion/conversation.py | 2 +- .../app/discussion/tests/test_conversation.py | 27 ++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 43648e5..f3e4f95 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,11 @@ Changelog 1.0b6 (unreleased) ------------------ +* Fixed the case where a folder has allow_discussion=False and + conversation.enabled() on a document in this folder returned False + instead of True because of allow_discussion acquisition. + [vincentfretin] + * Redirect to the comment form action instead of the absolute url when a comment is posted. This fixes the accidentially triggered file upload when a comment is posted on a file content object. diff --git a/plone/app/discussion/conversation.py b/plone/app/discussion/conversation.py index 80419ec..f3dc1f8 100644 --- a/plone/app/discussion/conversation.py +++ b/plone/app/discussion/conversation.py @@ -127,7 +127,7 @@ class Conversation(Traversable, Persistent, Explicit): obj = aq_parent(self) # If discussion is disabled for the object, bail out - obj_flag = getattr(obj, 'allow_discussion', None) + obj_flag = getattr(aq_base(obj), 'allow_discussion', None) if obj_flag is False: return False diff --git a/plone/app/discussion/tests/test_conversation.py b/plone/app/discussion/tests/test_conversation.py index 05cc507..69659a7 100644 --- a/plone/app/discussion/tests/test_conversation.py +++ b/plone/app/discussion/tests/test_conversation.py @@ -215,6 +215,31 @@ class ConversationTest(PloneTestCase): self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), True) self.assertEquals(getattr(self.portal.doc1, 'allow_discussion', None), True) + def test_comments_enabled_on_doc_in_subfolder(self): + typetool = self.portal.portal_types + typetool.constructContent('Folder', self.portal, 'folder1') + typetool.constructContent('Document', self.portal.folder1, 'doc2') + + folder = self.portal.folder1 + folder.allowDiscussion(False) + self.assertFalse(hasattr(aq_base(folder), 'allow_discussion')) + folder.allowDiscussion(True) + self.assertTrue(aq_base(folder).allow_discussion) + folder.allowDiscussion(False) + self.assertFalse(aq_base(folder).allow_discussion) + + doc = self.portal.folder1.doc2 + conversation = IConversation(doc) + self.assertEquals(conversation.enabled(), False) + + # We have to allow discussion on Document content type, since + # otherwise allow_discussion will always return False + portal_types = getToolByName(self.portal, 'portal_types') + document_fti = getattr(portal_types, 'Document') + document_fti.manage_changeProperties(allow_discussion = True) + + self.assertEquals(conversation.enabled(), True) + def test_disable_commenting_globally(self): # Create a conversation. @@ -814,4 +839,4 @@ class RepliesTest(PloneTestCase): self.assertEquals(len(replies_to_comment2), 1) def test_suite(): - return unittest.defaultTestLoader.loadTestsFromName(__name__) \ No newline at end of file + return unittest.defaultTestLoader.loadTestsFromName(__name__)