Commit e71090b9 authored by Jérome Perrin's avatar Jérome Perrin

core: introduce Base_addEditWorkflowComment helper script

This is intended to replace portal_workflow.doActionFor with edit_action,
which was only available for users with modify portal content permission
on the document and also is a bit low level.

It is a common, especially in project specific code that we use
edit_action to leave notes in history and provide better traceability
and we sometimes do this on documents where user does not have the
modify portal content permission.
parent 977414cd
Pipeline #19045 failed with stage
in 0 seconds
......@@ -11,7 +11,4 @@ context.setAggregateSet(
portal_type='Bank Reconciliation')
# for traceability
portal.portal_workflow.doActionFor(
context.getParentValue(),
"edit_action",
comment=message)
context.getParentValue().Base_addEditWorkflowComment(comment=message)
......@@ -14,7 +14,4 @@ context.setAggregateList(
portal_type='Bank Reconciliation')
# for traceability
portal.portal_workflow.doActionFor(
context.getParentValue(),
"edit_action",
comment=message)
context.getParentValue().Base_addEditWorkflowComment(comment=message)
from Products.ERP5Type.Message import translateString
context.getPortalObject().portal_workflow.doActionFor(
context, 'edit_action', comment=translateString('Select non reconciled transactions finished'))
context.Base_addEditWorkflowComment(comment=translateString('Select non reconciled transactions finished'))
......@@ -1150,6 +1150,18 @@ class TestERP5Base(ERP5TypeTestCase):
# workflow is affected
self.assertTrue(comment in [q['comment'] for q in workflow_history ])
def test_Base_addEditWorkflowComment(self):
# rather than using low level doActionFor, an helper script Base_addEditWorkflowComment
# is available. This scrit also has a proxy role, so that we can programatically
# add comment to workflow history, which can be good for traceability of autamated
# actions.
comment = 'some comment'
person = self.portal.person_module.newContent(portal_type='Person')
self.logout()
person.Base_addEditWorkflowComment(comment=comment)
workflow_history = self.getWorkflowHistory(person, 'edit_workflow')
self.assertIn(('Anonymous User', comment), [(q['actor'], q['comment']) for q in workflow_history ])
def test_comment_validation_workflow(self):
comment = 'some comment'
person = self.portal.person_module.newContent(portal_type='Person')
......
......@@ -5,10 +5,7 @@ the support request can still increase the modification date this way.
"""
from Products.ERP5Type.Message import translateString
context.getPortalObject().portal_workflow.doActionFor(
context,
'edit_action',
comment=translateString(
context.Base_addEditWorkflowComment(comment=translateString(
"New event ${event_reference}",
mapping={
'event_reference': event.getReference()}))
......@@ -11,7 +11,7 @@ clean_up_done = False
if flush_worklfow_history_comment:
document_to_cleanup.Base_purgeWorkflowHistoryCommentList()
edit_message = translateString('Workflow comments deleted by data protection manager')
portal.portal_workflow.doActionFor(document_to_cleanup, 'edit_action', comment=edit_message)
document_to_cleanup.Base_addEditWorkflowComment(comment=edit_message)
clean_up_done = True
# Second: erase properties
......@@ -21,7 +21,7 @@ if property_id_list:
edit_message = translateString('Properties deleted by data protection manager: ${items}',
mapping={'items': ', '.join(property_id_list)})
portal.portal_workflow.doActionFor(document_to_cleanup, 'edit_action', comment=edit_message)
document_to_cleanup.Base_addEditWorkflowComment(comment=edit_message)
if 'data' in edit_kw:
# Drop filename too, to prevent triggering guess mime type interaction workflow which run with user permission
......
......@@ -5,7 +5,4 @@ the bug can still increase the modification date this way.
"""
from Products.ERP5Type.Message import translateString
context.getPortalObject().portal_workflow.doActionFor(
context,
'edit_action',
comment=translateString("New comment"))
context.Base_addEditWorkflowComment(comment=translateString("New comment"))
from Products.ERP5Type.Message import translateString
portal = context.getPortalObject()
getDocumentValue = context.getDocumentValue
error_list = []
......@@ -23,9 +22,6 @@ if context.getAggregate():
"Web Section {} is older than default page".format(
context.getRelativeUrl()))
if fixit:
portal.portal_workflow.doActionFor(
context,
'edit_action',
comment=translateString('Edited Web Section, it was older than default page'))
context.Base_addEditWorkflowComment(comment=translateString('Edited Web Section, it was older than default page'))
return error_list
from Products.ERP5Type.Message import translateString
portal = context.getPortalObject()
gadget_translation_data_js = context.WebSite_getTranslationDataWebScriptValue()
if gadget_translation_data_js is None:
......@@ -10,18 +9,12 @@ if gadget_translation_data_js is None:
gadget_translation_data_js.setTextContent(
context.WebSite_getTranslationDataTextContent())
portal.portal_workflow.doActionFor(
gadget_translation_data_js,
'edit_action',
comment=translateString(
gadget_translation_data_js.Base_addEditWorkflowComment(comment=translateString(
"Translation data updated from web site ${web_site_id}.",
mapping={'web_site_id': context.getId()}))
# Edit web section modification date
portal.portal_workflow.doActionFor(
context,
'edit_action',
comment=translateString("Translation data updated.",))
context.Base_addEditWorkflowComment(comment=translateString("Translation data updated.",))
if REQUEST is not None:
return context.Base_redirect(
......
"""Adds an entry in edit workflow history with given comment.
"""
assert REQUEST is None and not container.REQUEST.args
context.getPortalObject().portal_workflow.doActionFor(
context,
'edit_action',
comment=comment
)
<?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>_params</string> </key>
<value> <string>comment, REQUEST=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_addEditWorkflowComment</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -109,15 +109,11 @@ if object_to_remove_list:
return context.Base_renderMessage(str(error), "error")
try:
# record object deletion in workflow history
portal.portal_workflow.doActionFor(
context,
'edit_action',
comment=Message(
context.Base_addEditWorkflowComment(comment=Message(
domain='ui',
message='Deleted objects: ${object_ids}',
mapping={'object_ids': [x.getId() for x in object_to_remove_list]},
),
)
))
except WorkflowException:
# no 'edit_action' transition for this container
pass
......
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