Commit 48acc068 authored by Julien Muchembled's avatar Julien Muchembled

Create getRoleList and getActionList accessors for portal types

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29247 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7955aa81
...@@ -2463,7 +2463,7 @@ class ActionTemplateItem(ObjectTemplateItem): ...@@ -2463,7 +2463,7 @@ class ActionTemplateItem(ObjectTemplateItem):
for path, action_dict in portal_type_dict.iteritems(): for path, action_dict in portal_type_dict.iteritems():
container = p.unrestrictedTraverse(path) container = p.unrestrictedTraverse(path)
container.manage_delObjects([obj.id container.manage_delObjects([obj.id
for obj in container.objectValues(portal_type='Action Information') for obj in container.getActionList()
if obj.reference in action_dict]) if obj.reference in action_dict])
for obj in action_dict.itervalues(): for obj in action_dict.itervalues():
container._importOldAction(obj) container._importOldAction(obj)
...@@ -2544,7 +2544,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem): ...@@ -2544,7 +2544,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem):
obj = p.unrestrictedTraverse("portal_types/%s" % obj = p.unrestrictedTraverse("portal_types/%s" %
relative_url.split('/', 1)[1]) relative_url.split('/', 1)[1])
self._objects[relative_url] = type_role_list = [] self._objects[relative_url] = type_role_list = []
for role in obj.objectValues(portal_type='Role Information'): for role in obj.getRoleList():
type_role_dict = {} type_role_dict = {}
for k, v in aq_base(role).__getstate__().iteritems(): for k, v in aq_base(role).__getstate__().iteritems():
if k == 'condition': if k == 'condition':
...@@ -2647,8 +2647,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem): ...@@ -2647,8 +2647,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem):
obj = p.unrestrictedTraverse(path, None) obj = p.unrestrictedTraverse(path, None)
if obj is not None: if obj is not None:
# reset roles before applying # reset roles before applying
obj.manage_delObjects([x.id obj.manage_delObjects([x.id for x in obj.getRoleList()])
for x in obj.objectValues(portal_type='Role Information')])
type_roles_list = self._objects[roles_path] or [] type_roles_list = self._objects[roles_path] or []
for role_property_dict in type_roles_list: for role_property_dict in type_roles_list:
obj._importRole(role_property_dict) obj._importRole(role_property_dict)
......
...@@ -378,8 +378,7 @@ class TestLocalRoleManagement(ERP5TypeTestCase): ...@@ -378,8 +378,7 @@ class TestLocalRoleManagement(ERP5TypeTestCase):
base_cat.manage_delObjects(list(base_cat.objectIds())) base_cat.manage_delObjects(list(base_cat.objectIds()))
# clear role definitions # clear role definitions
for ti in self.getTypesTool().objectValues(): for ti in self.getTypesTool().objectValues():
ti.manage_delObjects([x.id ti.manage_delObjects([x.id for x in ti.getRoleList()])
for x in ti.objectValues(portal_type='ERP5 Role Information')])
# clear modules # clear modules
for module in self.portal.objectValues(): for module in self.portal.objectValues():
if module.getId().endswith('_module'): if module.getId().endswith('_module'):
......
...@@ -245,7 +245,7 @@ class ERP5TypeInformation(XMLObject, ...@@ -245,7 +245,7 @@ class ERP5TypeInformation(XMLObject,
# which acquire their security definition from their parent # which acquire their security definition from their parent
# The downside of this optimisation is that it is not possible to # The downside of this optimisation is that it is not possible to
# set a local role definition if the local role list is empty # set a local role definition if the local role list is empty
if len(self.objectValues(portal_type='Role Information')): if self.getRoleList():
self.updateLocalRolesOnObject(ob) self.updateLocalRolesOnObject(ob)
# notify workflow after generating local roles, in order to prevent # notify workflow after generating local roles, in order to prevent
...@@ -528,9 +528,7 @@ class ERP5TypeInformation(XMLObject, ...@@ -528,9 +528,7 @@ class ERP5TypeInformation(XMLObject,
folder = aq_parent(folder) folder = aq_parent(folder)
ec = createExprContext(folder, portal, ob) ec = createExprContext(folder, portal, ob)
for role in self.objectValues(portal_type='Role Information'): return (role for role in self.getRoleList() if role.testCondition(ec))
if role.testCondition(ec):
yield role
security.declareProtected(Permissions.ManagePortal, 'updateRoleMapping') security.declareProtected(Permissions.ManagePortal, 'updateRoleMapping')
def updateRoleMapping(self, REQUEST=None, form_id=''): def updateRoleMapping(self, REQUEST=None, form_id=''):
...@@ -601,6 +599,16 @@ class ERP5TypeInformation(XMLObject, ...@@ -601,6 +599,16 @@ class ERP5TypeInformation(XMLObject,
# USE_BASE_TYPE # USE_BASE_TYPE
# #
security.declarePrivate('getRoleList')
def getRoleList(self):
"""Return all roles for this portal type"""
return self.objectValues(portal_type='Role Information')
security.declarePrivate('getActionList')
def getActionList(self):
"""Return all actions for this portal type"""
return self.objectValues(portal_type='Action Information')
def getIcon(self): def getIcon(self):
return self.content_icon return self.content_icon
...@@ -639,8 +647,7 @@ class ERP5TypeInformation(XMLObject, ...@@ -639,8 +647,7 @@ class ERP5TypeInformation(XMLObject,
security.declarePrivate('listActions') security.declarePrivate('listActions')
def listActions(self, info=None, object=None): def listActions(self, info=None, object=None):
""" List all the actions defined by a provider.""" """ List all the actions defined by a provider."""
return sorted(self.objectValues(portal_type='Action Information'), return sorted(self.getActionList(), key=lambda x: x.getFloatIndex())
key=lambda x: x.getFloatIndex())
def _importOldAction(self, old_action): def _importOldAction(self, old_action):
from Products.ERP5Type.Document.ActionInformation import ActionInformation from Products.ERP5Type.Document.ActionInformation import ActionInformation
......
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