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