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