Commit 8e001351 authored by Nicolas Delaby's avatar Nicolas Delaby

Use getattr instead of hasattr; reindent code

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21007 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6cf8c934
...@@ -27,35 +27,32 @@ import ERP5RoleManager ...@@ -27,35 +27,32 @@ import ERP5RoleManager
import ERP5UserFactory import ERP5UserFactory
def mergedLocalRoles(object): def mergedLocalRoles(object):
"""Returns a merging of object and its ancestors' """Returns a merging of object and its ancestors'
__ac_local_roles__.""" __ac_local_roles__."""
# Modified to take into account _getAcquireLocalRoles # Modified to take into account _getAcquireLocalRoles
merged = {} merged = {}
object = getattr(object, 'aq_inner', object) object = getattr(object, 'aq_inner', object)
while 1: while 1:
if hasattr(object, '__ac_local_roles__'): if getattr(object, '__ac_local_roles__', None) is not None:
roles = object.__ac_local_roles__ or {} roles = object.__ac_local_roles__ or {}
if callable(roles): roles = roles() if callable(roles): roles = roles()
for k, v in roles.items(): for k, v in roles.iteritems():
if merged.has_key(k): merged.setdefault(k, []).extend(v)
merged[k] = merged[k] + v # block acquisition
else: if getattr(object, '_getAcquireLocalRoles', None) is not None:
merged[k] = v if not object._getAcquireLocalRoles() is not None:
# block acquisition
if hasattr(object, '_getAcquireLocalRoles'):
if not object._getAcquireLocalRoles():
break
if hasattr(object, 'aq_parent'):
object=object.aq_parent
object=getattr(object, 'aq_inner', object)
continue
if hasattr(object, 'im_self'):
object=object.im_self
object=getattr(object, 'aq_inner', object)
continue
break break
if getattr(object, 'aq_parent', None) is not None:
object = object.aq_parent
object = getattr(object, 'aq_inner', object)
continue
if getattr(object, 'im_self', None) is not None:
object = object.im_self
object = getattr(object, 'aq_inner', object)
continue
break
return deepcopy(merged) return deepcopy(merged)
registerMultiPlugin(ERP5UserManager.ERP5UserManager.meta_type) registerMultiPlugin(ERP5UserManager.ERP5UserManager.meta_type)
registerMultiPlugin(ERP5GroupManager.ERP5GroupManager.meta_type) registerMultiPlugin(ERP5GroupManager.ERP5GroupManager.meta_type)
......
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