Commit 536564ac authored by iv's avatar iv

ERP5Workflow: add acquire_permission_list attribute, setup acquisition of...

ERP5Workflow: add acquire_permission_list attribute, setup acquisition of permission/roles correctly when converting, rename methods
parent a2599069
...@@ -117,7 +117,7 @@ class PermissionRoles(XMLObject): ...@@ -117,7 +117,7 @@ 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
roles = state._getStatePermissionRolesDict()[cell_permission] roles = state.getStatePermissionRolesDict()[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): if value and (cell_role not in roles):
......
...@@ -66,6 +66,7 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr ...@@ -66,6 +66,7 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
isRADContent = 1 isRADContent = 1
default_reference = '' default_reference = ''
state_type = () state_type = ()
acquire_permission = []
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -92,7 +93,7 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr ...@@ -92,7 +93,7 @@ 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): def getStatePermissionRolesDict(self):
role_dict = getattr(self, 'state_permission_roles', None) role_dict = getattr(self, 'state_permission_roles', None)
if role_dict is None: if role_dict is None:
# PersistentMapping is required to have changes on the dict # PersistentMapping is required to have changes on the dict
...@@ -100,15 +101,14 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr ...@@ -100,15 +101,14 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
self.state_permission_roles = role_dict = PersistentMapping() self.state_permission_roles = role_dict = PersistentMapping()
return role_dict return role_dict
def _setStatePermissionRoles(self, permission_roles): def setStatePermissionRolesDict(self, permission_roles):
self.state_permission_roles = PersistentMapping(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.""" """
if acquired: Set a permission for this State.
self.state_permission_roles[permission] = list(roles) """
else: self.state_permission_roles[permission] = list(roles)
self.state_permission_roles[permission] = tuple(roles)
def getDestinationReferenceList(self): def getDestinationReferenceList(self):
ref_list = [] ref_list = []
...@@ -135,4 +135,4 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr ...@@ -135,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._getStatePermissionRolesDict()[cell_permission] cell.selected = cell_role in self.getStatePermissionRolesDict()[cell_permission]
...@@ -46,7 +46,6 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed ...@@ -46,7 +46,6 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Products.DCWorkflow.Expression import StateChangeInfo from Products.DCWorkflow.Expression import StateChangeInfo
from Products.DCWorkflow.utils import Message as _ from Products.DCWorkflow.utils import Message as _
from Products.DCWorkflow.utils import modifyRolesForPermission from Products.DCWorkflow.utils import modifyRolesForPermission
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition as DCWorkflow
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.Globals import PersistentMapping from Products.ERP5Type.Globals import PersistentMapping
...@@ -217,7 +216,13 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -217,7 +216,13 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
changed = 0 changed = 0
state = self._getWorkflowStateOf(document, id_only=False) state = self._getWorkflowStateOf(document, id_only=False)
if state is not None: if state is not None:
for permission, role_list in state.state_permission_roles.items(): 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.getAcquirePermissionList():
role_list = list(role_list)
else:
role_list = tuple(role_list)
if modifyRolesForPermission(document, permission, role_list): if modifyRolesForPermission(document, permission, role_list):
changed = 1 changed = 1
return changed return changed
...@@ -1169,10 +1174,13 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -1169,10 +1174,13 @@ 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:
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[permission] = []
# remove permission from state_permission_roles dict # remove permission from state_permission_roles dict
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:
del state.state_permission_roles[permission] permission_to_delete.append(permission)
for permission in permission_to_delete:
del state.state_permission_roles[permission]
...@@ -348,7 +348,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -348,7 +348,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
for transition in workflow.objectValues(portal_type='Transition'): for transition in workflow.objectValues(portal_type='Transition'):
# configure after/before scripts # configure after/before scripts
# we have to loop again over transitions because some # we have to loop again over transitions because some
# before/after/... scripts are transitions and obviously, all of # before/after/... scripts are transitions and obviously, all of
# them were not defined on the new workflow in the previous loop # them were not defined on the new workflow in the previous loop
old_transition = dc_workflow_transition_value_list.get(transition.getReference()) old_transition = dc_workflow_transition_value_list.get(transition.getReference())
...@@ -370,10 +370,19 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -370,10 +370,19 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
state.setTitle(sdef.title) state.setTitle(sdef.title)
state.setReference(sdef.id) state.setReference(sdef.id)
state.setDescription(sdef.description) state.setDescription(sdef.description)
permission_roles = sdef.permission_roles or {}
state.setStatePermissionRoles(permission_roles) acquire_permission_list = []
if permission_roles: permission_roles_dict = {}
state.setCellRange(sorted(permission_roles.keys()), if sdef.permission_roles:
for (permission, roles) in sdef.permission_roles.items():
if isinstance(roles, list): # type 'list' means acquisition
acquire_permission_list.append(permission)
permission_roles_dict[permission] = list(roles)
state.setAcquirePermission(acquire_permission_list)
state.setStatePermissionRolesDict(permission_roles_dict)
if permission_roles_dict:
state.setCellRange(sorted(permission_roles_dict.keys()),
sorted(workflow.getManagedRoleList()), sorted(workflow.getManagedRoleList()),
base_id='cell') base_id='cell')
......
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