[CMF-checkins] SVN: CMF/branches/2.1/CMFDefault/ - replaced
portal_membership.checkPermission by _checkPermission
(removes portal_membership dependency)
Yvo Schubbe
y.2007- at wcm-solutions.de
Tue Jul 3 10:55:12 EDT 2007
Log message for revision 77356:
- replaced portal_membership.checkPermission by _checkPermission (removes portal_membership dependency)
- re-registered portal_discussion as utility
Changed:
U CMF/branches/2.1/CMFDefault/DiscussionItem.py
U CMF/branches/2.1/CMFDefault/DiscussionTool.py
U CMF/branches/2.1/CMFDefault/browser/metadata.py
U CMF/branches/2.1/CMFDefault/profiles/default/componentregistry.xml
U CMF/branches/2.1/CMFDefault/skins/zpt_content/metadata_edit_control.py
U CMF/branches/2.1/CMFDefault/skins/zpt_generic/discitem_delete.py
U CMF/branches/2.1/CMFDefault/skins/zpt_generic/discussion_reply.py
U CMF/branches/2.1/CMFDefault/tests/test_DiscussionTool.py
U CMF/branches/2.1/CMFDefault/tests/test_Discussions.py
-=-
Modified: CMF/branches/2.1/CMFDefault/DiscussionItem.py
===================================================================
--- CMF/branches/2.1/CMFDefault/DiscussionItem.py 2007-07-03 14:53:34 UTC (rev 77355)
+++ CMF/branches/2.1/CMFDefault/DiscussionItem.py 2007-07-03 14:55:11 UTC (rev 77356)
@@ -22,16 +22,17 @@
from Globals import Persistent
from Globals import PersistentMapping
from OFS.Traversable import Traversable
+from zope.component import getUtility
from zope.interface import implements
from Products.CMFCore.interfaces import ICallableOpaqueItemEvents
from Products.CMFCore.interfaces import IDiscussable
from Products.CMFCore.interfaces import IDiscussionResponse
+from Products.CMFCore.interfaces import IDiscussionTool
from Products.CMFCore.interfaces.Discussions \
import Discussable as z2IDiscussable
from Products.CMFCore.interfaces.Discussions \
import DiscussionResponse as z2IDiscussionResponse
-from Products.CMFCore.utils import getToolByName
from Document import Document
from permissions import AccessContentsInformation
@@ -113,7 +114,7 @@
- We are a nested reply; in this case, our 'in_reply_to'
field will be the ID of the parent DiscussionItem.
"""
- tool = getToolByName( self, 'portal_discussion' )
+ tool = getUtility(IDiscussionTool)
talkback = tool.getDiscussionFor( self )
return talkback._getReplyParent( self.in_reply_to )
Modified: CMF/branches/2.1/CMFDefault/DiscussionTool.py
===================================================================
--- CMF/branches/2.1/CMFDefault/DiscussionTool.py 2007-07-03 14:53:34 UTC (rev 77355)
+++ CMF/branches/2.1/CMFDefault/DiscussionTool.py 2007-07-03 14:55:11 UTC (rev 77356)
@@ -28,7 +28,8 @@
import DiscussionResponse as z2IDiscussionResponse
from Products.CMFCore.interfaces.portal_discussion \
import portal_discussion as z2IDiscussionTool
-from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import _checkPermission
+from Products.CMFCore.utils import registerToolInterface
from Products.CMFCore.utils import UniqueObject
from DiscussionItem import DiscussionItemContainer
@@ -73,10 +74,7 @@
def overrideDiscussionFor(self, content, allowDiscussion):
""" Override discussability for the given object or clear the setting.
"""
- # XXX: this method violates the rules for tools/utilities:
- # it depends on a non-utility tool
- mtool = getToolByName( self, 'portal_membership' )
- if not mtool.checkPermission(ModifyPortalContent, content):
+ if not _checkPermission(ModifyPortalContent, content):
raise AccessControl_Unauthorized
if allowDiscussion is None or allowDiscussion == 'None':
@@ -126,3 +124,4 @@
return content.talkback
InitializeClass( DiscussionTool )
+registerToolInterface('portal_discussion', IDiscussionTool)
Modified: CMF/branches/2.1/CMFDefault/browser/metadata.py
===================================================================
--- CMF/branches/2.1/CMFDefault/browser/metadata.py 2007-07-03 14:53:34 UTC (rev 77355)
+++ CMF/branches/2.1/CMFDefault/browser/metadata.py 2007-07-03 14:55:11 UTC (rev 77356)
@@ -18,6 +18,7 @@
from Acquisition import aq_self
from zope.app.form.browser import DatetimeI18nWidget
from zope.component import adapts
+from zope.component import getUtility
from zope.formlib import form
from zope.interface import implements
from zope.interface import Interface
@@ -29,9 +30,9 @@
from zope.schema import Tuple
from zope.schema import URI
+from Products.CMFCore.interfaces import IDiscussionTool
from Products.CMFCore.interfaces import IMutableDublinCore
from Products.CMFCore.interfaces import IMutableMinimalDublinCore
-from Products.CMFCore.utils import getToolByName
from Products.CMFDefault.formlib.form import ContentEditFormBase
from Products.CMFDefault.formlib.schema import ProxyFieldProperty
from Products.CMFDefault.formlib.schema import SchemaAdapterBase
@@ -172,7 +173,7 @@
return getattr(context, 'allow_discussion', None)
def _setAllowDiscussion(self, value):
- dtool = getToolByName(self.context, 'portal_discussion')
+ dtool = getUtility(IDiscussionTool)
dtool.overrideDiscussionFor(self.context, value)
allow_discussion = property(_getAllowDiscussion, _setAllowDiscussion)
Modified: CMF/branches/2.1/CMFDefault/profiles/default/componentregistry.xml
===================================================================
--- CMF/branches/2.1/CMFDefault/profiles/default/componentregistry.xml 2007-07-03 14:53:34 UTC (rev 77355)
+++ CMF/branches/2.1/CMFDefault/profiles/default/componentregistry.xml 2007-07-03 14:55:11 UTC (rev 77356)
@@ -3,6 +3,9 @@
<adapters/>
<utilities>
<utility
+ interface="Products.CMFCore.interfaces.IDiscussionTool"
+ object="/portal_discussion"/>
+ <utility
interface="Products.CMFCore.interfaces.IMetadataTool"
object="/portal_metadata"/>
<utility
Modified: CMF/branches/2.1/CMFDefault/skins/zpt_content/metadata_edit_control.py
===================================================================
--- CMF/branches/2.1/CMFDefault/skins/zpt_content/metadata_edit_control.py 2007-07-03 14:53:34 UTC (rev 77355)
+++ CMF/branches/2.1/CMFDefault/skins/zpt_content/metadata_edit_control.py 2007-07-03 14:55:11 UTC (rev 77356)
@@ -1,10 +1,10 @@
##parameters=allow_discussion, title=None, subject=None, description=None, contributors=None, effective_date=None, expiration_date=None, format=None, language=None, rights=None, **kw
##
-from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import getToolByInterfaceName
from Products.CMFDefault.exceptions import ResourceLockedError
from Products.CMFDefault.utils import Message as _
-dtool = getToolByName(script, 'portal_discussion')
+dtool = getToolByInterfaceName('Products.CMFCore.interfaces.IDiscussionTool')
def tuplify( value ):
Modified: CMF/branches/2.1/CMFDefault/skins/zpt_generic/discitem_delete.py
===================================================================
--- CMF/branches/2.1/CMFDefault/skins/zpt_generic/discitem_delete.py 2007-07-03 14:53:34 UTC (rev 77355)
+++ CMF/branches/2.1/CMFDefault/skins/zpt_generic/discitem_delete.py 2007-07-03 14:55:11 UTC (rev 77356)
@@ -1,10 +1,10 @@
##parameters=
##title=Delete reply
##
-from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import getToolByInterfaceName
from Products.CMFDefault.utils import Message as _
-dtool = getToolByName(script, 'portal_discussion')
+dtool = getToolByInterfaceName('Products.CMFCore.interfaces.IDiscussionTool')
parent = context.inReplyTo()
talkback = dtool.getDiscussionFor(parent)
Modified: CMF/branches/2.1/CMFDefault/skins/zpt_generic/discussion_reply.py
===================================================================
--- CMF/branches/2.1/CMFDefault/skins/zpt_generic/discussion_reply.py 2007-07-03 14:53:34 UTC (rev 77355)
+++ CMF/branches/2.1/CMFDefault/skins/zpt_generic/discussion_reply.py 2007-07-03 14:55:11 UTC (rev 77356)
@@ -1,10 +1,10 @@
##parameters=title, text, **kw
##title=Reply to content
##
-from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import getToolByInterfaceName
from Products.CMFDefault.utils import Message as _
-dtool = getToolByName(script, 'portal_discussion')
+dtool = getToolByInterfaceName('Products.CMFCore.interfaces.IDiscussionTool')
talkback = dtool.getDiscussionFor(context)
replyID = talkback.createReply(title=title, text=text)
Modified: CMF/branches/2.1/CMFDefault/tests/test_DiscussionTool.py
===================================================================
--- CMF/branches/2.1/CMFDefault/tests/test_DiscussionTool.py 2007-07-03 14:53:34 UTC (rev 77355)
+++ CMF/branches/2.1/CMFDefault/tests/test_DiscussionTool.py 2007-07-03 14:55:11 UTC (rev 77356)
@@ -18,14 +18,17 @@
import unittest
import Testing
+from zope.component import getSiteManager
from zope.testing.cleanup import cleanUp
+from Products.CMFCore.interfaces import IDiscussionTool
from Products.CMFCore.tests.base.dummy import DummyFolder
from Products.CMFCore.tests.base.dummy import DummySite
from Products.CMFCore.tests.base.dummy import DummyTool
+from Products.CMFCore.tests.base.testcase import SecurityTest
-class DiscussionToolTests(unittest.TestCase):
+class DiscussionToolTests(SecurityTest):
def _makeOne(self, *args, **kw):
from Products.CMFDefault.DiscussionTool import DiscussionTool
@@ -33,13 +36,16 @@
return DiscussionTool(*args, **kw)
def setUp(self):
+ SecurityTest.setUp(self)
self.site = DummySite('site')
+ sm = getSiteManager()
self.site._setObject( 'portal_discussion', self._makeOne() )
- self.site._setObject( 'portal_membership', DummyTool() )
+ sm.registerUtility(self.site.portal_discussion, IDiscussionTool)
self.site._setObject( 'portal_types', DummyTool() )
def tearDown(self):
cleanUp()
+ SecurityTest.tearDown(self)
def test_z2interfaces(self):
from Interface.Verify import verifyClass
Modified: CMF/branches/2.1/CMFDefault/tests/test_Discussions.py
===================================================================
--- CMF/branches/2.1/CMFDefault/tests/test_Discussions.py 2007-07-03 14:53:34 UTC (rev 77355)
+++ CMF/branches/2.1/CMFDefault/tests/test_Discussions.py 2007-07-03 14:55:11 UTC (rev 77356)
@@ -18,7 +18,10 @@
import unittest
import Testing
+from zope.component import getSiteManager
+
from Products.CMFCore.CatalogTool import CatalogTool
+from Products.CMFCore.interfaces import IDiscussionTool
from Products.CMFCore.testing import EventZCMLLayer
from Products.CMFCore.tests.base.dummy import DummyContent
from Products.CMFCore.tests.base.dummy import DummySite
@@ -106,7 +109,9 @@
def setUp(self):
SecurityTest.setUp(self)
self.site = DummySite('site').__of__(self.root)
+ sm = getSiteManager()
self.site._setObject( 'portal_discussion', DiscussionTool() )
+ sm.registerUtility(self.site.portal_discussion, IDiscussionTool)
self.site._setObject( 'portal_membership', DummyTool() )
self.site._setObject( 'portal_types', TypesTool() )
More information about the CMF-checkins
mailing list