From 03eff6f38a6e45fd85d3610bb2d6776ed00646ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Thu, 18 Oct 2007 17:17:57 +0000 Subject: [PATCH] Also reset aq_dynamic when workflow method are added and state variable name is changed. the comment '# XXX We should also call it whenever we change workflow defition' can be removed from ERP5Type git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17046 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/ERP5Type.py | 2 +- product/ERP5Type/Interactor.py | 17 +++++++++++++++ product/ERP5Type/tests/testERP5Type.py | 29 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/product/ERP5Type/ERP5Type.py b/product/ERP5Type/ERP5Type.py index 9b33743cbe..3487224848 100644 --- a/product/ERP5Type/ERP5Type.py +++ b/product/ERP5Type/ERP5Type.py @@ -723,7 +723,7 @@ class ERP5TypeInformation( FactoryTypeInformation, if previous_property_sheet_list != self.property_sheet_list or \ base_category_list != self.base_category_list: from Products.ERP5Type.Base import _aq_reset - _aq_reset() # XXX We should also call it whenever we change workflow defition + _aq_reset() return result def reorderActions(self, REQUEST=None): diff --git a/product/ERP5Type/Interactor.py b/product/ERP5Type/Interactor.py index e92406d312..18ecfda508 100644 --- a/product/ERP5Type/Interactor.py +++ b/product/ERP5Type/Interactor.py @@ -112,6 +112,22 @@ class WorkflowToolInteractor(AqDynamicInteractor): from Products.CMFCore.WorkflowTool import WorkflowTool self.on(WorkflowTool.manage_changeWorkflows).doAfter(self.resetAqDynamic) + +class DCWorkflowInteractor(AqDynamicInteractor): + """This interactor reset aq_dynamic method cache whenever a workflow + definition changes + """ + def install(self): + from Products.DCWorkflow.Transitions import Transitions + self.on(Transitions.addTransition).doAfter(self.resetAqDynamic) + self.on(Transitions.deleteTransitions).doAfter(self.resetAqDynamic) + + from Products.DCWorkflow.Transitions import TransitionDefinition + self.on(TransitionDefinition.setProperties).doAfter(self.resetAqDynamic) + + from Products.DCWorkflow.Variables import Variables + self.on(Variables.setStateVar).doAfter(self.resetAqDynamic) + ## # ## # Experimental part ## # @@ -224,6 +240,7 @@ class InteractorOfInteractor(Interactor): # Install some interactors: WorkflowToolInteractor().install() +DCWorkflowInteractor().install() # This is used in ERP5Form and install method is called in ERP5Form # Don't install this interactor here. diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py index 3339e252b2..5e175ab079 100644 --- a/product/ERP5Type/tests/testERP5Type.py +++ b/product/ERP5Type/tests/testERP5Type.py @@ -1692,6 +1692,35 @@ class TestPropertySheet: props=dict(chain_Person='delivery_causality_workflow')) self.assertTrue(hasattr(doc, 'getCausalityState')) + def test_aq_reset_on_workflow_method_change(self): + doc = self.portal.person_module.newContent(portal_type='Person') + ti = self.getTypesTool()['Person'] + self.portal.portal_workflow.manage_changeWorkflows( + default_chain='', + props=dict(chain_Person='delivery_causality_workflow')) + self.assertTrue(hasattr(doc, 'diverge')) + + wf = self.portal.portal_workflow.delivery_causality_workflow + wf.transitions.addTransition('dummy_workflow_method') + from Products.DCWorkflow.Transitions import TRIGGER_WORKFLOW_METHOD + wf.transitions.dummy_workflow_method.setProperties( + title='', new_state_id='', trigger_type=TRIGGER_WORKFLOW_METHOD) + self.assertTrue(hasattr(doc, 'dummyWorkflowMethod')) + + wf.transitions.deleteTransitions(['dummy_workflow_method']) + self.assertFalse(hasattr(doc, 'dummyWorkflowMethod')) + + def test_aq_reset_on_workflow_state_variable_change(self): + doc = self.portal.person_module.newContent(portal_type='Person') + ti = self.getTypesTool()['Person'] + self.portal.portal_workflow.manage_changeWorkflows( + default_chain='', + props=dict(chain_Person='delivery_causality_workflow')) + self.assertTrue(hasattr(doc, 'getCausalityState')) + wf = self.portal.portal_workflow.delivery_causality_workflow + wf.variables.setStateVar('dummy_state') + self.assertTrue(hasattr(doc, 'getDummyState')) + # ... other cases should be added here -- 2.30.9