Commit e0b58aa3 authored by iv's avatar iv

ERP5Workflow: rename and fix state_permission_roles

parent 92cfba78
......@@ -67,6 +67,7 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
default_reference = ''
state_type = ()
acquire_permission = []
state_permission_roles_dict = {}
# Declarative security
security = ClassSecurityInfo()
......@@ -113,15 +114,26 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
# return possible transition id list:
return self.getDestinationIdList()
security.declareProtected(Permissions.ModifyPortalContent,
security.declareProtected(Permissions.AccessContentsInformation,
'setStatePermissionRolesDict')
def setStatePermissionRolesDict(self, permission_roles):
"""
create a dict containing state/permission role dict
create a dict containing the state's permission (as key) and its
associated role list (value)
use a PersistentMapping so that the ZODB is updated
when this dict is changed
"""
self.state_permission_roles = PersistentMapping(permission_roles)
self.state_permission_roles_dict = PersistentMapping(permission_roles)
security.declareProtected(Permissions.ModifyPortalContent,
'getStatePermissionRolesDict')
def getStatePermissionRolesDict(self):
"""
return the permission/roles dict
"""
if self.state_permission_roles_dict is None:
return {}
return self.state_permission_roles_dict
security.declareProtected(Permissions.ModifyPortalContent,
'setPermission')
......@@ -129,7 +141,7 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
"""
Set a permission for this State.
"""
self.state_permission_roles[permission] = list(roles)
self.state_permission_roles_dict[permission] = list(roles)
security.declareProtected(Permissions.AccessContentsInformation,
'getAvailableTypeList')
......
......@@ -227,16 +227,15 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
state = self._getWorkflowStateOf(document, id_only=False)
if state is not None:
state_permission_list = state.getAcquirePermissionList()
if hasattr(state, 'getStatePermissionRolesDict'):
for permission, role_list in state.getStatePermissionRolesDict().items():
# tuple means "don't acquire" in zope internal security and list
# is used when acquisition should be done
if permission in state_permission_list:
role_list = list(role_list)
else:
role_list = tuple(role_list)
if modifyRolesForPermission(document, permission, role_list):
changed = True
for permission, role_list in state.getStatePermissionRolesDict().items():
# tuple means "don't acquire" in zope internal security and list
# is used when acquisition should be done
if permission in state_permission_list:
role_list = list(role_list)
else:
role_list = tuple(role_list)
if modifyRolesForPermission(document, permission, role_list):
changed = True
return changed
# This method allows to update all objects using one workflow, for example
......@@ -872,8 +871,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
state = SubElement(states, 'state', attrib=dict(reference=sdef.getReference(), portal_type=sdef.getPortalType()))
for property_id in sorted(state_prop_id_to_show):
if property_id == 'permission_roles':
property_value = sdef.getProperty('state_permission_roles')
property_type = sdef.getPropertyType('state_permission_roles')
property_value = sdef.getProperty('state_permission_roles_dict')
property_type = sdef.getPropertyType('state_permission_roles_dict')
elif property_id == 'transitions':
property_value = sdef.getDestinationIdList()
destination_list = []
......@@ -1204,11 +1203,11 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
for permission in permission_list:
permission_roles_dict = state.getStatePermissionRolesDict()
if permission not in permission_roles_dict:
state.state_permission_roles[permission] = []
# remove permission from state_permission_roles dict
state.state_permission_roles_dict[permission] = []
# remove permission from state_permission_roles_dict
permission_to_delete = []
for permission in permission_roles_dict:
if permission not in permission_list:
permission_to_delete.append(permission)
for permission in permission_to_delete:
del state.state_permission_roles[permission]
del state.state_permission_roles_dict[permission]
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