From b022bd7244eb8577b6dd274dbd9780689fac76b2 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Wed, 14 Oct 2009 13:18:25 +0000
Subject: [PATCH] * add getActionListFor() that does not filter (cf.
 getFilteredActionListFor() filters). * revert r29647 and use
 getActionListFor() and call test() for its result in getDefaultViewFor(), so
 that createExpressionContext() is only called once. * use getActionListFor()
 and call test() for its result in listFilteredActionsFor(), so that
 createExpressionContext() is only called once..

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29650 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/ERP5Type.py                   | 12 +++++++++---
 product/ERP5Type/Tool/TypesTool.py             |  9 +++++++++
 product/ERP5Type/interfaces/action_provider.py |  3 +++
 product/ERP5Type/patches/ActionsTool.py        |  5 +++--
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/product/ERP5Type/ERP5Type.py b/product/ERP5Type/ERP5Type.py
index 78d56994a7..fdffa623d8 100644
--- a/product/ERP5Type/ERP5Type.py
+++ b/product/ERP5Type/ERP5Type.py
@@ -497,15 +497,16 @@ class ERP5TypeInformation(XMLObject,
       """
       ec = createExpressionContext(ob)
       best_action = (), None
-      for action in self.getFilteredActionListFor(ob):
+      for action in self.getActionListFor(ob):
         if action.getReference() == view:
-          break
+          if action.test(ec):
+            break
         else:
           # In case that "view" (or "list") action is not present or not allowed,
           # find something that's allowed (of the same category, if possible).
           index = (action.getActionType().endswith('_' + view),
                   -action.getFloatIndex())
-          if best_action[0] < index:
+          if best_action[0] < index and action.test(ec):
             best_action = index, action
       else:
         action = best_action[1]
@@ -519,6 +520,11 @@ class ERP5TypeInformation(XMLObject,
       __traceback_info__ = self.getId(), target
       return ob.restrictedTraverse(target)
 
+    security.declarePrivate('getActionListFor')
+    def getActionListFor(self, ob=None):
+      """Return all actions of the object"""
+      return self.getActionInformationList()
+
     security.declarePrivate('getFilteredActionListFor')
     def getFilteredActionListFor(self, ob=None):
       """Return all actions applicable to the object"""
diff --git a/product/ERP5Type/Tool/TypesTool.py b/product/ERP5Type/Tool/TypesTool.py
index aa30db7e14..975a1bb65e 100644
--- a/product/ERP5Type/Tool/TypesTool.py
+++ b/product/ERP5Type/Tool/TypesTool.py
@@ -42,6 +42,15 @@ class TypesTool(BaseTool, CMFCore_TypesTool.TypesTool):
 
   zope.interface.implements(interfaces.IActionProvider)
 
+  security.declarePrivate('getActionListFor')
+  def getActionListFor(self, ob=None):
+    """Return all actions of the object"""
+    if ob is not None:
+      type_info = self.getTypeInfo(ob)
+      if type_info is not None:
+        return type_info.getActionListFor(ob)
+    return ()
+
   security.declarePrivate('getFilteredActionListFor')
   def getFilteredActionListFor(self, ob=None):
     """Return all actions applicable to the object"""
diff --git a/product/ERP5Type/interfaces/action_provider.py b/product/ERP5Type/interfaces/action_provider.py
index 2dc85c6f26..7b8c996b94 100644
--- a/product/ERP5Type/interfaces/action_provider.py
+++ b/product/ERP5Type/interfaces/action_provider.py
@@ -53,6 +53,9 @@ class IAction(Interface):
 class IActionProvider(Interface):
   """
   """
+  def getActionListFor(ob):
+    """Return all actions of the object"""
+
   def getFilteredActionListFor(ob):
     """Return all actions applicable to the object
     """
diff --git a/product/ERP5Type/patches/ActionsTool.py b/product/ERP5Type/patches/ActionsTool.py
index 5a17272cd6..a6888c4d48 100644
--- a/product/ERP5Type/patches/ActionsTool.py
+++ b/product/ERP5Type/patches/ActionsTool.py
@@ -36,12 +36,13 @@ def listFilteredActionsFor(self, object=None):
         provider = getattr(self, provider_name)
         if providedBy(provider):
             actions.extend( provider.listActionInfos(object=object) )
-        elif hasattr(provider, 'getFilteredActionListFor'):
+        elif hasattr(provider, 'getActionListFor'):
             from Products.ERP5Type.Utils import createExpressionContext
             ec = createExpressionContext(object)
             actions += sorted(
               (action.getActionInfo(ec)
-               for action in provider.getFilteredActionListFor(object)),
+               for action in provider.getActionListFor(object)
+               if action.test(ec)),
               key=lambda x: x['priority'])
         else:
             # for Action Providers written for CMF versions before 1.5
-- 
2.30.9