Commit 1755c61b authored by iv's avatar iv

ERP5Workflow: override edit on PermissionRoles cells to save changes in the state

data structure state_permission_roles
parent ced674e1
...@@ -43,7 +43,7 @@ class PermissionRoles(XMLObject): ...@@ -43,7 +43,7 @@ class PermissionRoles(XMLObject):
portal_type = 'PermissionRoles' portal_type = 'PermissionRoles'
add_permission = Permissions.AddPortalContent add_permission = Permissions.AddPortalContent
isIndexable = ConstantGetter('isIndexable', value=False) isIndexable = ConstantGetter('isIndexable', value=False)
is_selected = 0 # for checkerbox (True 1 /False 0) is_selected = 0 # checkerbox
isPortalContent = 1 isPortalContent = 1
isRADContent = 1 isRADContent = 1
...@@ -76,3 +76,39 @@ class PermissionRoles(XMLObject): ...@@ -76,3 +76,39 @@ class PermissionRoles(XMLObject):
if role == 'None': if role == 'None':
role = ['Manager'] role = ['Manager']
return permission, role return permission, role
def getCellInfo(self):
(cell_permission_index, cell_role_index) = self.id[len(self.base_id+'_'):]\
.split('_')
return {'prefix': self.base_id,
'permission_index': int(cell_permission_index),
'role_index': int(cell_role_index)}
def editStatePermissionRolesFromCellSelection(self, value):
"""
edit the parent state's permission/role dict to reflect current cell selection (is_selected) status
"""
state = self.getParentValue()
cell_info = self.getCellInfo()
cell_range = state.getCellRange()
cell_permission = sorted(cell_range[0])[cell_info['permission_index']]
cell_role = sorted(cell_range[1])[cell_info['role_index']]
# update the state permission structure to take into account
# the selection/non-selection of this cell
if value and (cell_role not in state.state_permission_roles[cell_permission]):
roles = state.state_permission_roles[cell_permission]
acquired = isinstance(roles, tuple)
roles = list(set(roles))
roles.append(cell_role)
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]):
roles = state.state_permission_roles[cell_permission]
acquired = isinstance(roles, tuple)
roles = list(set(roles))
roles.remove(cell_role)
state.setPermission(cell_permission, acquired, roles)
def edit(self, *args, **kw):
super(PermissionRoles, self).edit(*args, **kw)
if kw.get('is_selected') is not None:
self.editStatePermissionRolesFromCellSelection(kw['is_selected'])
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