本文整理汇总了Python中trac.perm.PermissionSystem.expand_actions方法的典型用法代码示例。如果您正苦于以下问题:Python PermissionSystem.expand_actions方法的具体用法?Python PermissionSystem.expand_actions怎么用?Python PermissionSystem.expand_actions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.perm.PermissionSystem
的用法示例。
在下文中一共展示了PermissionSystem.expand_actions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_permission
# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import expand_actions [as 别名]
def check_permission(self, action, username, resource, perm):
if ConfigObj is None:
self.log.error('configobj package not found')
return None
if self.authz_file and not self.authz_mtime or \
os.path.getmtime(self.get_authz_file()) > self.authz_mtime:
self.parse_authz()
resource_key = self.normalise_resource(resource)
self.log.debug('Checking %s on %s', action, resource_key)
permissions = self.authz_permissions(resource_key, username)
if permissions is None:
return None # no match, can't decide
elif permissions == ['']:
return False # all actions are denied
# FIXME: expand all permissions once for all
ps = PermissionSystem(self.env)
for deny, perms in groupby(permissions,
key=lambda p: p.startswith('!')):
if deny and action in ps.expand_actions([p[1:] for p in perms]):
return False # action is explicitly denied
elif action in ps.expand_actions(perms):
return True # action is explicitly granted
return None # no match for action, can't decide
示例2: _expand_perms
# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import expand_actions [as 别名]
def _expand_perms(self, env):
permsys = PermissionSystem(env)
grant = frozenset(permsys.expand_actions(self.grant))
revoke = frozenset(permsys.expand_actions(self.revoke))
# Double check ambiguous action lists
if grant & revoke:
raise ValueError('Impossible to grant and revoke (%s)' %
', '.join(sorted(grant & revoke)))
self.grant = grant
self.revoke = revoke
self._expanded = True
示例3: get_relevant_permissions
# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import expand_actions [as 别名]
def get_relevant_permissions(self, policy, username):
ps = PermissionSystem(self.env)
relevant_permissions = set(self._required_permissions.itervalues())
user_permissions = self.get_all_user_permissions(policy, username)
for doc_type, doc_id, permissions in user_permissions:
for deny, perms in groupby(permissions,
key=lambda p: p.startswith('!')):
if deny:
for p in ps.expand_actions([p[1:] for p in perms]):
if p in relevant_permissions:
yield doc_type, doc_id, p, True
else:
for p in ps.expand_actions(perms):
if p in relevant_permissions:
yield doc_type, doc_id, p, False
示例4: check_permission
# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import expand_actions [as 别名]
def check_permission(self, action, username, resource, perm):
if not self.authz_mtime or os.path.getmtime(self.authz_file) != self.authz_mtime:
self.parse_authz()
resource_key = self.normalise_resource(resource)
self.log.debug("Checking %s on %s", action, resource_key)
permissions = self.authz_permissions(resource_key, username)
if permissions is None:
return None # no match, can't decide
elif permissions == []:
return False # all actions are denied
# FIXME: expand all permissions once for all
ps = PermissionSystem(self.env)
for deny, perms in groupby(permissions, key=lambda p: p.startswith("!")):
if deny and action in ps.expand_actions(p[1:] for p in perms):
return False # action is explicitly denied
elif action in ps.expand_actions(perms):
return True # action is explicitly granted
return None # no match for action, can't decide