[CMF-checkins] SVN: CMF/trunk/CMFCore/ Updated the fiveactionstool to Zope 3.2. There is one test that is failing, which is

Lennart Regebro regebro at gmail.com
Wed Jan 18 16:06:19 EST 2006


Log message for revision 41356:
  Updated the fiveactionstool to Zope 3.2. There is one test that is failing, which is 
  indicating that there possibly might be a security problem. But that could also be the 
  test-setup. I'll continue to look into that.
  

Changed:
  U   CMF/trunk/CMFCore/fiveactionstool.py
  U   CMF/trunk/CMFCore/tests/test_fiveactionstool.py

-=-
Modified: CMF/trunk/CMFCore/fiveactionstool.py
===================================================================
--- CMF/trunk/CMFCore/fiveactionstool.py	2006-01-18 15:25:44 UTC (rev 41355)
+++ CMF/trunk/CMFCore/fiveactionstool.py	2006-01-18 21:06:19 UTC (rev 41356)
@@ -16,66 +16,54 @@
 """
 
 from AccessControl import ClassSecurityInfo
+from Acquisition import aq_base
 from Globals import InitializeClass
-from Globals import DTMLFile
 from OFS.SimpleItem import SimpleItem
+
+from Products.CMFCore.ActionInformation import ActionInformation
+from Products.CMFCore.ActionProviderBase import ActionProviderBase
+from Products.CMFCore.Expression import Expression
+from Products.CMFCore.utils import UniqueObject
+
 from zope.app import zapi
 from zope.app.publisher.interfaces.browser import IBrowserMenu
 from zope.app.publisher.browser.menu import getMenu
+    
+def _listMenuIds():
+    return [id for id, utility in zapi.getUtilitiesFor(IBrowserMenu)]
 
-from ActionInformation import ActionInformation
-from ActionProviderBase import ActionProviderBase
-from Expression import Expression
-from permissions import ManagePortal
-from utils import UniqueObject
-from utils import _dtmldir
+from Products.Five import security
+import zope.thread
 
-
-class FiveActionsTool(UniqueObject, SimpleItem, ActionProviderBase):
-    """Five actions tool.
-
-    Provides a bridge that makes Zope 3 menus available as CMF actions.
+class FiveActionsTool( UniqueObject, SimpleItem, ActionProviderBase ):
+    """ Links content to discussions.
     """
 
-    __implements__ = ActionProviderBase.__implements__
+    __implements__ = (ActionProviderBase.__implements__)
 
     id = 'portal_fiveactions'
-    meta_type = 'CMF Five Actions Tool'
+    meta_type = 'Five Actions Tool'
 
     security = ClassSecurityInfo()
 
-    manage_options = (({'label': 'Overview',
-                        'action': 'manage_overview'},
-                       ) +
-                      SimpleItem.manage_options)
+    def getReqestURL(self):
+        return self.REQUEST.URL
 
-    #
-    # ZMI methods
-    #
-
-    security.declareProtected(ManagePortal, 'manage_overview')
-    manage_overview = DTMLFile('explainFiveActionsTool', _dtmldir)
-
-    #
-    # ActionProvider
-    #
-
     security.declarePrivate('listActions')
     def listActions(self, info=None, object=None):
         """ List all the actions defined by a provider.
-        """
-        if object is None and info is not None:
-            # BBB (according to the interface)
-            object = info.content
+        """       
         if object is None:
-            # The tool itself doesn't provide any action
-            return ()
+            if  info is None:
+                # There is no support for global actions
+                return ()
+            else:
+                object = info.content
 
         actions = []
-
-        for menu_id in zapi.getUtilitiesFor(IBrowserMenu):
+        for menu_id in _listMenuIds():
             for entry in getMenu(menu_id, object, self.REQUEST):
-                # The action needs a unique name, so we'll build one
+                # The action needs a unique name, so I'll build one
                 # from the object_id and the action url. That is sure
                 # to be unique.
                 action = str(entry['action'])
@@ -83,21 +71,30 @@
                     act_id = 'action_%s' % action
                 else:
                     act_id = 'action_%s_%s' % (object.getId(), action)
-
-                if entry['filter'] is None:
+                    
+                if entry.get('filter') is None:
                     filter = None
                 else:
                     filter = Expression(text=str(entry['filter']))
 
+                title = entry['title']
+                # Having bits of unicode here can make rendering very confused,
+                # so we convert it to plain strings, but NOT if it is a 
+                # messageID. In Zope 3.2 there are two types of messages,
+                # Message and MessageID, where MessageID is depracated. We can 
+                # type-check for both but that provokes a deprecation warning, 
+                # so we check for the "domain" attribute instead. 
+                if not hasattr(title, 'domain'):
+                    title = str(title)
                 act = ActionInformation(id=act_id,
-                    title=str(entry['title']),
+                    title=title,
                     action=Expression(text='string:%s' % action),
                     condition=filter,
                     category=str(menu_id),
                     visible=1)
                 actions.append(act)
-
+                
         return tuple(actions)
 
 
-InitializeClass(FiveActionsTool)
+InitializeClass( FiveActionsTool )

Modified: CMF/trunk/CMFCore/tests/test_fiveactionstool.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_fiveactionstool.py	2006-01-18 15:25:44 UTC (rev 41355)
+++ CMF/trunk/CMFCore/tests/test_fiveactionstool.py	2006-01-18 21:06:19 UTC (rev 41356)
@@ -37,7 +37,22 @@
       >>> zcml.load_config('permissions.zcml', Products.Five)
       >>> zcml.load_config('meta.zcml', Products.CMFCore)
       >>> folder = self.folder
+    
+    Do a Zope 2 login:
+    
+      >>> from Products.Five.security import newInteraction
+      >>> newInteraction()
 
+    The request needs a skin layer for the test.
+    XXX: There is probably a better way to do this.
+    
+      >>> zcml.load_string('''<configure xmlns="http://namespaces.zope.org/five">
+      ...       <implements class="ZPublisher.HTTPRequest.HTTPRequest"
+      ...          interface="zope.publisher.interfaces.browser.IDefaultBrowserLayer"
+      ...          />
+      ...     </configure>''')
+      
+
     Let's create a Five actions tool:
 
       >>> from Products.CMFCore.fiveactionstool import FiveActionsTool
@@ -59,7 +74,7 @@
     that 'action_content_protected.html' is not present, as it was
     protected by a more restrictive permission:
 
-      >>> actions = tool.listActions(object=foo)
+      >>> actions = tool.listActions(object=foo, info="kuk")
       >>> [(action.category, action.id) for action in actions]
       [('mymenu', 'action_foo_public.html')]
 



More information about the CMF-checkins mailing list