From 25eb9448e1b363cc62363825db6208bb67e29ada Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Mon, 6 Jul 2009 09:39:00 +0000
Subject: [PATCH] When executing a workflow method, raise if the transition
 does not exist from the current state, or if the guard rejects it.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27964 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Base.py               |  5 +++--
 product/ERP5Type/tests/testERP5Type.py | 10 ++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py
index f7617ea9ab..0e94ead315 100644
--- a/product/ERP5Type/Base.py
+++ b/product/ERP5Type/Base.py
@@ -207,8 +207,9 @@ class WorkflowMethod(Method):
         if candidate_workflow.isWorkflowMethodSupported(instance, transition_id):
           valid_list.append(transition_id)
         elif candidate_workflow.__class__.__name__ == 'DCWorkflowDefinition':
-          # XXX Do not raise for the moment as ERP5 is not ready.
-          #raise UnsupportedWorkflowMethod(instance, wf_id, transition_id)
+          raise UnsupportedWorkflowMethod(instance, wf_id, transition_id)
+          # XXX Keep the log for projects that needs to comment out
+          #     the previous line.
           LOG("WorkflowMethod.__call__", ERROR,
               "Transition %s/%s on %r is ignored. Current state is %r."
               % (wf_id, transition_id, instance,
diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py
index a64cfed44d..56c8fa9d5b 100644
--- a/product/ERP5Type/tests/testERP5Type.py
+++ b/product/ERP5Type/tests/testERP5Type.py
@@ -38,6 +38,7 @@ from Products.ERP5Type.tests.utils import DummyLocalizer
 from zLOG import LOG, INFO
 from Products.CMFCore.Expression import Expression
 from Products.CMFCore.tests.base.testcase import LogInterceptor
+from Products.CMFCore.WorkflowCore import WorkflowException
 from Products.ERP5Type.Base import _aq_reset
 from Products.ERP5Type.tests.utils import installRealClassTool
 from Products.ERP5Type.Utils import removeLocalPropertySheet
@@ -2613,6 +2614,15 @@ class TestPropertySheet:
         address.manage_permission(permission, roles=(), acquire=0)
         check(0)
 
+    def test_unsupportedTransitionRaises(self):
+      """
+      Check that an object must be in the expected state in order to execute
+      a transition.
+      """
+      person = self.getPersonModule().newContent(portal_type='Person')
+      person.validate()
+      self.assertRaises(WorkflowException, person.validate)
+
 class TestAccessControl(ERP5TypeTestCase):
   # Isolate test in a dedicaced class in order not to break other tests
   # when this one fails.
-- 
2.30.9