From ddcf29ee79ac5b023df8b138a926513d7f468d18 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Thu, 9 Oct 2008 13:01:06 +0000
Subject: [PATCH] unrestrictedTraverse is no suitable for this use: it can
 raise another exception than KeyError (see OFS/Traversable.py) and also
 prevents from finding methods on object (only subobjects or objects
 accessible via acquisition context).

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24123 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/CMFActivity/ActivityTool.py          |  4 ++--
 product/CMFActivity/tests/testCMFActivity.py | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/product/CMFActivity/ActivityTool.py b/product/CMFActivity/ActivityTool.py
index f43b282571..1c97018226 100644
--- a/product/CMFActivity/ActivityTool.py
+++ b/product/CMFActivity/ActivityTool.py
@@ -252,8 +252,8 @@ class Message:
           try:
             # XXX: There is no check to see if user is allowed to access
             # that method !
-            method = obj.unrestrictedTraverse(self.method_id)
-          except KeyError:
+            method = getattr(obj, self.method_id)
+          except:
             method = None
             self.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=activity_tool)
           else:
diff --git a/product/CMFActivity/tests/testCMFActivity.py b/product/CMFActivity/tests/testCMFActivity.py
index 9dfc5deffc..f3a8818099 100644
--- a/product/CMFActivity/tests/testCMFActivity.py
+++ b/product/CMFActivity/tests/testCMFActivity.py
@@ -2973,9 +2973,9 @@ class TestCMFActivity(ERP5TypeTestCase):
       LOG('Testing... ',0,message)
     portal = self.getPortalObject()
     activity_tool = self.getActivityTool()
-    def checkMessage(message):
+    def checkMessage(message, exception_type):
       self.assertNotEqual(message.getExecutionState(), 1) # 1 == MESSAGE_EXECUTED
-      self.assertEqual(message.exc_type, KeyError)
+      self.assertEqual(message.exc_type, exception_type)
       self.assertNotEqual(message.traceback, None)
     # With Message.__call__
     # 1: activity context does not exist when activity is executed
@@ -2989,7 +2989,7 @@ class TestCMFActivity(ERP5TypeTestCase):
     message = message_list[0]
     portal.organisation_module._delOb(organisation.id)
     message(activity_tool)
-    checkMessage(message)
+    checkMessage(message, KeyError)
     activity_tool.manageCancel(message.object_path, message.method_id)
     # 2: activity method does not exist when activity is executed
     portal.organisation_module.activate().this_method_does_not_exist()
@@ -2998,7 +2998,7 @@ class TestCMFActivity(ERP5TypeTestCase):
     self.assertEqual(len(message_list), 1)
     message = message_list[0]
     message(activity_tool)
-    checkMessage(message)
+    checkMessage(message, AttributeError)
     activity_tool.manageCancel(message.object_path, message.method_id)
 
     # With ActivityTool.invokeGroup
@@ -3013,7 +3013,7 @@ class TestCMFActivity(ERP5TypeTestCase):
     message = message_list[0]
     portal.organisation_module._delOb(organisation.id)
     activity_tool.invokeGroup('getTitle', [message])
-    checkMessage(message)
+    checkMessage(message, KeyError)
     activity_tool.manageCancel(message.object_path, message.method_id)
     # 2: activity method does not exist when activity is executed
     portal.organisation_module.activate().this_method_does_not_exist()
@@ -3022,7 +3022,7 @@ class TestCMFActivity(ERP5TypeTestCase):
     self.assertEqual(len(message_list), 1)
     message = message_list[0]
     activity_tool.invokeGroup('this_method_does_not_exist', [message])
-    checkMessage(message)
+    checkMessage(message, KeyError)
     activity_tool.manageCancel(message.object_path, message.method_id)
 
     # Unadressed error paths (in both cases):
-- 
2.30.9