make conversation.enabled return a boolean (remove the property decorator).

Always return false if the content object is a folder.

svn path=/plone.app.discussion/trunk/; revision=27502
This commit is contained in:
Timo Stollenwerk 2009-06-18 21:02:32 +00:00
parent 34ee743bf3
commit c8a24e5d74

View File

@ -25,7 +25,7 @@ from zope.annotation.interfaces import IAnnotations, IAnnotatable
from zope.event import notify from zope.event import notify
from Acquisition import aq_base, aq_inner from Acquisition import aq_base, aq_inner, aq_parent
from Acquisition import Explicit from Acquisition import Explicit
from OFS.Traversable import Traversable from OFS.Traversable import Traversable
@ -34,6 +34,9 @@ from OFS.event import ObjectWillBeAddedEvent
from OFS.event import ObjectWillBeRemovedEvent from OFS.event import ObjectWillBeRemovedEvent
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.CMFCore.interfaces import IFolderish
from Products.CMFPlone.interfaces import IPloneSiteRoot, INonStructuralFolder
from zope.app.container.contained import ContainerModifiedEvent from zope.app.container.contained import ContainerModifiedEvent
@ -84,9 +87,12 @@ class Conversation(Traversable, Persistent, Explicit):
""" """
return self.id return self.id
@property
def enabled(self): def enabled(self):
# Returns True if discussion is allowed # Returns True if discussion is enabled on the conversation
site = getSite()
portal_discussion = getToolByName(site, 'portal_discussion')
portal_types = getToolByName(site, 'portal_types')
# Fetch discussion registry # Fetch discussion registry
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
@ -96,16 +102,38 @@ class Conversation(Traversable, Persistent, Explicit):
if not settings.globally_enabled: if not settings.globally_enabled:
return False return False
# Always return False if object is a folder
if IFolderish.providedBy(aq_inner(self.__parent__)) and not INonStructuralFolder.providedBy(aq_inner(self.__parent__)):
return False
# Check folders by traversing through the object tree
allowed = False
def traverse(obj):
# Run from context to the Plone Site Root
if not IPloneSiteRoot.providedBy(obj):
# Look for Plone folders
if IFolderish.providedBy(obj) and not INonStructuralFolder.providedBy(obj):
if portal_discussion.isDiscussionAllowedFor(obj):
#print "FOLDER %s: discussion allowed => override" % obj.id
allowed = True
traverse(aq_parent(obj))
obj = aq_parent(self)
#print ""
#print "### START TRAVERSE ###"
# Start traversing
#traverse(obj)
#print allowed
#print "### END TRAVERSE ###"
# Check if discussion is allowed on the content type # Check if discussion is allowed on the content type
site = getSite()
portal_types = getToolByName(site, 'portal_types')
portal_type = self.__parent__.portal_type portal_type = self.__parent__.portal_type
document_fti = getattr(portal_types, 'Document') document_fti = getattr(portal_types, 'Document')
if not document_fti.getProperty('allow_discussion'): if not document_fti.getProperty('allow_discussion'):
# If discussion is not allowed on the content type, # If discussion is not allowed on the content type,
# check if 'allow discussion' is overridden on the content object. # check if 'allow discussion' is overridden on the content object.
#if hasattr( aq_base(self.__parent__), 'allow_discussion' ): #if hasattr( aq_base(self.__parent__), 'allow_discussion' ):
portal_discussion = getToolByName(site, 'portal_discussion')
if not portal_discussion.isDiscussionAllowedFor(aq_inner(self.__parent__)): if not portal_discussion.isDiscussionAllowedFor(aq_inner(self.__parent__)):
return False return False