From 473699dea09b9e7f03fb73177a7fe3e938f5729a Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 11 Jun 2009 10:20:44 +0000 Subject: [PATCH] is_discussion_allowed method from the comments viewlet now uses Conversation.enabled. svn path=/plone.app.discussion/trunk/; revision=27381 --- plone/app/discussion/browser/comments.py | 40 ++++++++++++-- .../discussion/tests/test_comments_viewlet.py | 52 ------------------- 2 files changed, 36 insertions(+), 56 deletions(-) diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index e35407d..28009e2 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -54,10 +54,8 @@ class CommentsViewlet(ViewletBase): return getSecurityManager().checkPermission('Reply to item', aq_inner(self.context)) def is_discussion_allowed(self): - if self.portal_discussion is None: - return False - else: - return self.portal_discussion.isDiscussionAllowedFor(aq_inner(self.context)) + conversation = conversationAdapterFactory(self.context) + return conversation.enabled def get_replies(self): # Return all direct replies @@ -177,3 +175,37 @@ class ReplyToComment(BrowserView): # Redirect to comment (inside a content object page) self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url() + '#comment-' + str(reply_to_comment_id)) + +class DeleteComment(BrowserView): + """Delete a comment from a conversation + """ + + def __call__(self): + + comment = aq_inner(self.context) + + # Sanity check + comment_id = self.request.form['comment_id'] + if comment_id != comment.getId(): + raise ValueError + + conversation = self.context.__parent__ + + del conversation[comment_id] + +class PublishComment(BrowserView): + """Publish a comment + """ + + def __call__(self): + + comment = aq_inner(self.context) + + # Sanity check + comment_id = self.request.form['comment_id'] + if comment_id != comment.getId(): + raise ValueError + + action = self.request.form['action'] + portal_workflow = getToolByName(comment, 'portal_workflow') + portal_workflow.doActionFor(comment, action) \ No newline at end of file diff --git a/plone/app/discussion/tests/test_comments_viewlet.py b/plone/app/discussion/tests/test_comments_viewlet.py index 8b1fb04..8f96e3f 100644 --- a/plone/app/discussion/tests/test_comments_viewlet.py +++ b/plone/app/discussion/tests/test_comments_viewlet.py @@ -95,57 +95,5 @@ class CommentsViewletTest(PloneTestCase): # Create a user without setting a username pass - def test_is_discussion_allowed(self): - # We currently have four layers of testing if discussion is allowed - # on a particular content object: - # - # 1) Check if discussion is allowed globally - # 2) Check if discussion is allowed on a particular content type - # 3) If the content object is located in a folder, check if the folder - # has discussion allowed - # 4) Check if discussion is allowed on this particular content object - # - self.viewlet.update() - self.viewlet.is_discussion_allowed() - - def test_is_discussion_allowed_globally(self): - pass - - def test_is_discussion_allowed_for_content_type(self): - # Check discussion allowed for content types - portal_types = getToolByName(self.portal, 'portal_types') - - # Get the FTI for some content types - document_fti = getattr(portal_types, 'Document') - news_item_fti = getattr(portal_types, 'News Item') - folder_fti = getattr(portal_types, 'Folder') - - # By default, discussion is only allowed for Document and News Item - # XXX: allow_discussion always returns False !!! - #self.assertEquals(document_fti.getProperty('allow_discussion'), True) - #self.assertEquals(news_item_fti.getProperty('allow_discussion'), True) - - self.assertEquals(folder_fti.getProperty('allow_discussion'), False) - - # Disallow discussion for the News Item content types - news_item_fti.manage_changeProperties(allow_discussion = False) - - # Allow discussion for the Folder content types - folder_fti.manage_changeProperties(allow_discussion = True) - - # Check if discussion for News Item content types is disallowed - self.assertEquals(news_item_fti.getProperty('allow_discussion'), False) - - # Check if discussion for Folder content types is allowed - self.assertEquals(folder_fti.getProperty('allow_discussion'), True) - - def test_is_discussion_allowed_for_folder(self): - # Create a folder with two content objects. Change allow_discussion - # and check if the content objects inside the folder are commentable. - pass - - def test_is_discussion_allowed_on_content_object(self): - pass - def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) \ No newline at end of file