Commit c8d35a67 authored by iv's avatar iv

ERP5Workflow: use a persistent mapping for state_permission_roles

WIP
todo: remove property in property sheet
persistent mapping will take care of changes on the dict and commit them in the ZODB
otherwise, because we change the attributes of the dict and not of the State object,
the changes will be lost
parent c11f9383
...@@ -117,15 +117,12 @@ class PermissionRoles(XMLObject): ...@@ -117,15 +117,12 @@ class PermissionRoles(XMLObject):
# update the state permission structure to take into account # update the state permission structure to take into account
# the selection/non-selection of this cell # the selection/non-selection of this cell
if value and (cell_role not in state.state_permission_roles[cell_permission]): roles = state._getStatePermissionRolesDict()[cell_permission]
roles = state.state_permission_roles[cell_permission] acquired = isinstance(roles, tuple)
acquired = isinstance(roles, tuple) roles = list(set(roles))
roles = list(set(roles)) if value and (cell_role not in roles):
roles.append(cell_role) roles.append(cell_role)
state.setPermission(cell_permission, acquired, roles) # XXX(WORKFLOW) set acquire value correctly state.setPermission(cell_permission, acquired, roles) # XXX(WORKFLOW) set acquire value correctly
if (not value) and (cell_role in state.state_permission_roles[cell_permission]): if (not value) and (cell_role in roles):
roles = state.state_permission_roles[cell_permission]
acquired = isinstance(roles, tuple)
roles = list(set(roles))
roles.remove(cell_role) roles.remove(cell_role)
state.setPermission(cell_permission, acquired, roles) state.setPermission(cell_permission, acquired, roles)
...@@ -66,7 +66,6 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr ...@@ -66,7 +66,6 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
isRADContent = 1 isRADContent = 1
default_reference = '' default_reference = ''
state_type = () state_type = ()
state_permission_roles = {}
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -93,6 +92,17 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr ...@@ -93,6 +92,17 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
# return possible transition id list: # return possible transition id list:
return self.getDestinationIdList() return self.getDestinationIdList()
def _getStatePermissionRolesDict(self):
role_dict = getattr(self, 'state_permission_roles', None)
if role_dict is None:
# PersistentMapping is required to have changes on the dict
# commited in the ZODB
self.state_permission_roles = role_dict = PersistentMapping()
return role_dict
def _setStatePermissionRoles(self, permission_roles):
self.state_permission_roles = PersistentMapping(permission_roles)
def setPermission(self, permission, acquired, roles, REQUEST=None): def setPermission(self, permission, acquired, roles, REQUEST=None):
"""Set a permission for this State.""" """Set a permission for this State."""
if acquired: if acquired:
...@@ -125,4 +135,4 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr ...@@ -125,4 +135,4 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
""" """
cell_permission = cell._getPermission() cell_permission = cell._getPermission()
cell_role = cell._getRole() cell_role = cell._getRole()
cell.selected = cell_role in self.state_permission_roles[cell_permission] cell.selected = cell_role in self._getStatePermissionRolesDict()[cell_permission]
...@@ -264,7 +264,6 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -264,7 +264,6 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
wf_id = self.getId()) wf_id = self.getId())
else: else:
object_list = [] object_list = []
if REQUEST is not None: if REQUEST is not None:
message = 'No object updated.' message = 'No object updated.'
if object_list: if object_list:
...@@ -1170,9 +1169,10 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -1170,9 +1169,10 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
sorted(self.getManagedRoleList()), sorted(self.getManagedRoleList()),
base_id='cell') base_id='cell')
for permission in permission_list: for permission in permission_list:
if permission not in state.state_permission_roles: permission_roles_dict = state._getStatePermissionRolesDict()
if permission not in permission_roles_dict:
state.state_permission_roles[permission] = [] state.state_permission_roles[permission] = []
# remove permission from state_permission_roles dict # remove permission from state_permission_roles dict
for permission in state.state_permission_roles.keys(): for permission in permission_roles_dict:
if permission not in permission_list: if permission not in permission_list:
del state.state_permission_roles[permission] del state.state_permission_roles[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