From 1e9909ab6f0e51dd0a54806a8c3dc03743fb160f Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 10 Jun 2016 03:40:07 +0200 Subject: [PATCH] Split too complex _enabled_for_archetypes. --- CHANGES.rst | 3 +- plone/app/discussion/browser/conversation.py | 37 ++++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ec4efc4..1a0e008 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -22,6 +22,8 @@ Bug fixes: Bug fixes: +- Cleaned code from flake8 errors. [maurits] + - Reset the required setting of the author_email widget each time. Otherwise, the email field might get set to required when an anonymous user visits, and then remain required when an @@ -29,7 +31,6 @@ Bug fixes: user to fill in the form without validation error. Or when in the control panel the field is set as not required anymore, that change would have no effect until the instance was restarted. [maurits] -- Cleaned code from flake8 errors. [maurits] 2.4.14 (2016-06-06) diff --git a/plone/app/discussion/browser/conversation.py b/plone/app/discussion/browser/conversation.py index b198e6f..0017da4 100644 --- a/plone/app/discussion/browser/conversation.py +++ b/plone/app/discussion/browser/conversation.py @@ -19,6 +19,20 @@ except ImportError: DEXTERITY_INSTALLED = False +def traverse_parents(context): + # Run through the aq_chain of obj and check if discussion is + # enabled in a parent folder. + for obj in aq_chain(context): + if not IPloneSiteRoot.providedBy(obj): + obj_is_folderish = IFolderish.providedBy(obj) + obj_is_stuctural = not INonStructuralFolder.providedBy(obj) + if (obj_is_folderish and obj_is_stuctural): + flag = getattr(obj, 'allow_discussion', None) + if flag is not None: + return flag + return None + + class ConversationView(object): def enabled(self): @@ -31,14 +45,14 @@ class ConversationView(object): """ Returns True if discussion is enabled for this conversation. This method checks five different settings in order to figure out if - discussion is enable on a specific content object: + discussion is enabled on a specific content object: 1) Check if discussion is enabled globally in the plone.app.discussion registry/control panel. 2) If the current content object is a folder, always return False, since we don't allow comments on a folder. This - setting is used to allow/ disallow comments for all content + setting is used to allow / disallow comments for all content objects inside a folder, not for the folder itself. 3) Check if the allow_discussion boolean flag on the content object is @@ -63,22 +77,9 @@ class ConversationView(object): # Always return False if object is a folder context_is_folderish = IFolderish.providedBy(context) - context_is_structural = not INonStructuralFolder.providedBy(context) - if (context_is_folderish and context_is_structural): - return False - - def traverse_parents(context): - # Run through the aq_chain of obj and check if discussion is - # enabled in a parent folder. - for obj in aq_chain(context): - if not IPloneSiteRoot.providedBy(obj): - obj_is_folderish = IFolderish.providedBy(obj) - obj_is_stuctural = not INonStructuralFolder.providedBy(obj) - if (obj_is_folderish and obj_is_stuctural): - flag = getattr(obj, 'allow_discussion', None) - if flag is not None: - return flag - return None + if context_is_folderish: + if not INonStructuralFolder.providedBy(context): + return False # If discussion is disabled for the object, bail out obj_flag = getattr(aq_base(context), 'allow_discussion', None)