Commit 4d2c21cf authored by Julien Muchembled's avatar Julien Muchembled

Fix StateChangeInfo.setWorkflowVariable and restrict its usage for the current transition

parent 2e3f28c5
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>transition = state_change[\'transition\'].id[len(\'user_\'):]\n
\n
def TestTitle(object):\n
"""\n
This is the test for this particular action\n
"""\n
if object.getTitle() == \'truc\':\n
return 1\n
return 0\n
\n
object = state_change[\'object\']\n
\n
if TestTitle(object):\n
method = getattr(context, transition)\n
method()\n
else:\n
kw = {\'error_message\':\'Why do you want to do this ?????\'}\n
state_change.setWorkflowVariable(object, **kw)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test_error_message</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -400,8 +400,7 @@ def DCWorkflowDefinition_executeTransition(self, ob, tdef=None, kwargs=None):
sci = StateChangeInfo(
ob, self, status, tdef, old_sdef, new_sdef, kwargs)
# put the error message in the workflow history
sci.setWorkflowVariable(ob, workflow_id=self.id,
error_message = before_script_error_message)
sci.setWorkflowVariable(error_message=before_script_error_message)
if validation_exc :
# reraise validation failed exception
raise validation_exc, None, validation_exc_traceback
......
......@@ -30,19 +30,14 @@ from Products.DCWorkflow.Expression import StateChangeInfo
from Products.PythonScripts.Utility import allow_class
allow_class(StateChangeInfo)
def setWorkflowVariable(self, object, workflow_id='edit_workflow',**kw):
def setWorkflowVariable(self, **kw):
"""
Allows to go through security checking and let a
script allows to modify a workflow variable
"""
workflow_history = object.workflow_history
for workflow in workflow_history.keys():
if len(workflow_history[workflow])!= 0 and workflow==workflow_id:
last_status = workflow_history[workflow][-1]
for variable in kw.keys():
if last_status.has_key(variable):
last_status[variable]=kw[variable]
history = self.object.workflow_history[self.workflow.id]
history[-1].update(kw)
history._p_changed = 1
StateChangeInfo.setWorkflowVariable = setWorkflowVariable
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment