Commit 55049a0c authored by Jérome Perrin's avatar Jérome Perrin

workflow: fix Update Security Roles action on workflow

This was redirecting with the full list of updated documents URLs,
causing too long URLs.

This also simplifies code a bit, change the wording of messages and
use translation.
parent e0999427
import urlparse
import unittest import unittest
from erp5.component.mixin.TestWorkflowMixin import TestWorkflowMixin from erp5.component.mixin.TestWorkflowMixin import TestWorkflowMixin
from Products.ERP5Type.Core.Workflow import ValidationFailed from Products.ERP5Type.Core.Workflow import ValidationFailed
...@@ -434,7 +435,10 @@ class TestConvertedWorkflow(TestERP5WorkflowMixin): ...@@ -434,7 +435,10 @@ class TestConvertedWorkflow(TestERP5WorkflowMixin):
modified_role_dict['View'] = ('Assignee', 'Assignor', 'Associate', 'Auditor', 'Author', 'Manager') modified_role_dict['View'] = ('Assignee', 'Assignor', 'Associate', 'Auditor', 'Author', 'Manager')
self.workflow.state_draft.setStatePermissionRoleListDict(modified_role_dict) self.workflow.state_draft.setStatePermissionRoleListDict(modified_role_dict)
self.tic() self.tic()
self.workflow.Workflow_updateSecurityRoles() ret = self.workflow.Workflow_updateSecurityRoles()
self.assertEqual(
urlparse.parse_qs(urlparse.urlparse(ret).query)['portal_status_message'],
["1 documents updated."])
self.tic() self.tic()
self.assertEqual(text_document._View_Permission, ('Assignee', 'Assignor', 'Associate', 'Auditor', 'Author', 'Manager')) self.assertEqual(text_document._View_Permission, ('Assignee', 'Assignor', 'Associate', 'Auditor', 'Author', 'Manager'))
self.workflow.state_draft.setStatePermissionRoleListDict(default_role_dict) self.workflow.state_draft.setStatePermissionRoleListDict(default_role_dict)
......
"""
Changes permissions of all objects related to this workflow
"""
from Products.ERP5Type.Message import translateString
portal = context.getPortalObject()
ACTIVITY_GROUPING_COUNT = 100 ACTIVITY_GROUPING_COUNT = 100
def updateRoleMappings(self, REQUEST=None): portal_type_id_list = context.getPortalTypeListForWorkflow()
""" object_list = []
Changes permissions of all objects related to this workflow if portal_type_id_list:
""" object_list = portal.portal_catalog(portal_type=portal_type_id_list, limit=None)
portal_type_id_list = self.getPortalTypeListForWorkflow() portal_activities_activate = portal.portal_activities.activate
if portal_type_id_list:
object_list = self.portal_catalog(portal_type=portal_type_id_list, limit=None)
portal_activities = self.portal_activities
object_path_list = [x.path for x in object_list] object_path_list = [x.path for x in object_list]
for i in xrange(0, len(object_list), ACTIVITY_GROUPING_COUNT): for i in xrange(0, len(object_list), ACTIVITY_GROUPING_COUNT):
current_path_list = object_path_list[i:i+ACTIVITY_GROUPING_COUNT] current_path_list = object_path_list[i:i+ACTIVITY_GROUPING_COUNT]
portal_activities.activate(activity='SQLQueue', portal_activities_activate(
priority=3)\ activity='SQLQueue',
.callMethodOnObjectList(current_path_list, priority=3,
).callMethodOnObjectList(
current_path_list,
'updateRoleMappingsFor', 'updateRoleMappingsFor',
wf_id = self.getId()) wf_id=context.getId(),
else: )
object_list = [] message = translateString('No document updated.')
if REQUEST is not None: if object_list:
message = 'No object updated.' message = translateString(
if object_list: '${document_count} documents updated.',
message = '%d object(s) updated: \n %s.' % (len(object_list), mapping={'document_count': len(object_list)},
', '.join([o.getTitleOrId() + ' (' + o.getPortalType() + ')' )
for o in object_list]))
return message
else:
return len(object_list)
message = updateRoleMappings(context, context.REQUEST)
return context.Base_redirect(form_id, keep_items={'portal_status_message': message}) return context.Base_redirect(form_id, keep_items={'portal_status_message': message})
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>form_id=None</string> </value> <value> <string>form_id=None, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
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