本文整理汇总了Python中zope.securitypolicy.interfaces.IPrincipalRoleMap.getRolesForPrincipal方法的典型用法代码示例。如果您正苦于以下问题:Python IPrincipalRoleMap.getRolesForPrincipal方法的具体用法?Python IPrincipalRoleMap.getRolesForPrincipal怎么用?Python IPrincipalRoleMap.getRolesForPrincipal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zope.securitypolicy.interfaces.IPrincipalRoleMap
的用法示例。
在下文中一共展示了IPrincipalRoleMap.getRolesForPrincipal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cached_principal_roles
# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getRolesForPrincipal [as 别名]
def cached_principal_roles(self, parent, principal):
cache = self.cache(parent)
try:
cache_principal_roles = cache.principal_roles
except AttributeError:
cache_principal_roles = cache.principal_roles = {}
try:
return cache_principal_roles[principal]
except KeyError:
pass
if parent is None:
roles = dict(
[(role, SettingAsBoolean[setting])
for (role, setting) in globalRolesForPrincipal(principal)])
roles['zope.Anonymous'] = True # Everybody has Anonymous
cache_principal_roles[principal] = roles
return roles
roles = self.cached_principal_roles(
removeSecurityProxy(getattr(parent, '__parent__', None)),
principal)
prinrole = IPrincipalRoleMap(parent, None)
if prinrole:
roles = roles.copy()
for role, setting in prinrole.getRolesForPrincipal(principal):
roles[role] = SettingAsBoolean[setting]
cache_principal_roles[principal] = roles
return roles
示例2: cached_principal_roles
# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getRolesForPrincipal [as 别名]
def cached_principal_roles(self, parent, principal):
cache = self.cache(parent)
try:
cache_principal_roles = cache.principal_roles
except AttributeError:
cache_principal_roles = cache.principal_roles = {}
try:
return cache_principal_roles[principal]
except KeyError:
pass
if parent is None:
roles = dict(
[(role, zopepolicy.SettingAsBoolean[setting])
for (role, setting) in
zopepolicy.globalRolesForPrincipal(principal)])
roles['zope.Anonymous'] = True # Everybody has Anonymous
cache_principal_roles[principal] = roles
return roles
roles = self.cached_principal_roles(
removeSecurityProxy(getattr(parent, '__parent__', None)),
principal)
prinrole = IPrincipalRoleMap(parent, None)
if prinrole:
roles = roles.copy()
for role, setting in prinrole.getRolesForPrincipal(principal):
roles[role] = zopepolicy.SettingAsBoolean[setting]
# The lines below include the group that a document has been assigned
# to into the lookup hierarchy.
group_assignments = getattr(parent, "sa_group_assignments", [])
for group_assignment in group_assignments:
group = group_assignment.principal
#!+GROUP_ASSIGNMENT.GROUP assert isinstance(group, domain.Group), group
assigned_group_prinrole = IPrincipalRoleMap(group, None)
if assigned_group_prinrole:
roles = roles.copy()
role_settings = assigned_group_prinrole.getRolesForPrincipal(
principal)
for role, setting in role_settings:
roles[role] = zopepolicy.SettingAsBoolean[setting]
cache_principal_roles[principal] = roles
return roles
示例3: getAllRoles
# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getRolesForPrincipal [as 别名]
def getAllRoles(self):
hfr = IPrincipalRoleMap(self.homefolder)
masteruser = False
ret = []
for rolesetting in hfr.getRolesForPrincipal(self.principal.id):
role, setting = rolesetting
if 'uvc.Editor' == role and setting is Allow:
masteruser = True
ret.append('ENMS')
for name, productfolder in self.homefolder.items():
if not name.startswith('__'):
if masteruser:
ret.append(name)
else:
prm = IPrincipalRoleMap(productfolder)
for rolesetting in prm.getRolesForPrincipal(self.principal.id):
role, setting = rolesetting
if 'uvc.Editor' == role and setting is Allow:
ret.append(name)
return ret
示例4: roles
# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getRolesForPrincipal [as 别名]
def roles(self):
prmap = IPrincipalRoleMap(self.context)
return [ids for ids, setting in prmap.getRolesForPrincipal(self.principal_id)]