From 3708429a375a063e172cc10d329d7fe29e2f78de Mon Sep 17 00:00:00 2001 From: Ross Patterson Date: Fri, 15 Apr 2011 04:29:46 +0000 Subject: [PATCH] Move some policy out of the conversation storage adapter into a view, specifically "enabled()". Prevents having to replace/migrate persistent objects to change policy which really only concerns the context and possibly the request, not the conversation storage. Fixes #11372. svn path=/plone.app.discussion/trunk/; revision=48849 --- CHANGES.txt | 7 ++ plone/app/discussion/browser/comments.py | 12 +-- plone/app/discussion/browser/configure.zcml | 9 ++ plone/app/discussion/browser/conversation.py | 95 +++++++++++++++++++ plone/app/discussion/conversation.py | 68 +------------ plone/app/discussion/interfaces.py | 25 ----- .../discussion/tests/test_comments_viewlet.py | 10 ++ .../app/discussion/tests/test_conversation.py | 24 +++-- 8 files changed, 146 insertions(+), 104 deletions(-) create mode 100644 plone/app/discussion/browser/conversation.py diff --git a/CHANGES.txt b/CHANGES.txt index 7329c5d..7fedca1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,13 @@ Changelog 2.0b2 (Unreleased) ------------------ +- Move some policy out of the conversation storage adapter into a + view, specifically "enabled()". Prevents having to replace/migrate + persistent objects to change policy which really only concerns the + context and possibly the request, not the conversation storage. + Fixes #11372. + [rossp] + - Fix unindexing of comments when deleting content resulting from iterating over a BTree while modifying it. Fixes #11402. [rossp] diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 6627987..a6b143f 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -168,14 +168,15 @@ class CommentForm(extensible.ExtensibleForm, form.Form): if 'user_notification' in data: user_notification = data['user_notification'] - # The add-comment view is called on the conversation object - conversation = IConversation(self.__parent__) - # Check if conversation is enabled on this content object - if not conversation.enabled(): + if not self.__parent__.restrictedTraverse( + '@@conversation_view').enabled(): raise Unauthorized, "Discussion is not enabled for this content\ object." + # The add-comment view is called on the conversation object + conversation = IConversation(self.__parent__) + if data['in_reply_to']: # Fetch the comment we want to reply to conversation_to_reply_to = conversation.get(data['in_reply_to']) @@ -291,8 +292,7 @@ class CommentsViewlet(ViewletBase): def is_discussion_allowed(self): context = aq_inner(self.context) - conversation = IConversation(context) - return conversation.enabled() + return context.restrictedTraverse('@@conversation_view').enabled() def comment_transform_message(self): """Returns the description that shows up above the comment text, diff --git a/plone/app/discussion/browser/configure.zcml b/plone/app/discussion/browser/configure.zcml index 95dbf2e..a240167 100644 --- a/plone/app/discussion/browser/configure.zcml +++ b/plone/app/discussion/browser/configure.zcml @@ -100,6 +100,15 @@ permission="zope2.View" /> + + +