本文整理汇总了Python中AccessControl.Permission.Permission.setRoles方法的典型用法代码示例。如果您正苦于以下问题:Python Permission.setRoles方法的具体用法?Python Permission.setRoles怎么用?Python Permission.setRoles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AccessControl.Permission.Permission
的用法示例。
在下文中一共展示了Permission.setRoles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: manage_changePermissions
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def manage_changePermissions(self, REQUEST):
"""Change all permissions settings, called by management screen."""
valid_roles = self.valid_roles()
have = REQUEST.__contains__
permissions = self.ac_inherited_permissions(1)
fails = []
for ip in range(len(permissions)):
permission_name = permissions[ip][0]
permission_hash = _string_hash(permission_name)
roles = []
for role in valid_roles:
role_name = role
role_hash = _string_hash(role_name)
if have("permission_%srole_%s" % (permission_hash, role_hash)):
roles.append(role)
name, value = permissions[ip][:2]
try:
p = Permission(name, value, self)
if not have('acquire_%s' % permission_hash):
roles = tuple(roles)
p.setRoles(roles)
except Exception:
fails.append(name)
if fails:
raise BadRequest('Some permissions had errors: '
+ escape(', '.join(fails), True))
if REQUEST is not None:
return self.manage_access(REQUEST)
示例2: manage_changePermissions
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def manage_changePermissions(self, REQUEST):
"""Change all permissions settings, called by management screen.
"""
valid_roles=self.valid_roles()
indexes=range(len(valid_roles))
have=REQUEST.has_key
permissions=self.ac_inherited_permissions(1)
fails = []
for ip in range(len(permissions)):
roles = []
for ir in indexes:
if have("p%dr%d" % (ip, ir)):
roles.append(valid_roles[ir])
name, value = permissions[ip][:2]
try:
p = Permission(name, value, self)
if not have('a%d' % ip):
roles=tuple(roles)
p.setRoles(roles)
except:
fails.append(name)
if fails:
return MessageDialog(title="Warning!",
message="Some permissions had errors: "
+ escape(', '.join(fails)),
action='manage_access')
return MessageDialog(
title = 'Success!',
message = 'Your changes have been saved',
action = 'manage_access')
示例3: testChangeUseOpenFlowPermission
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def testChangeUseOpenFlowPermission(self):
from AccessControl.Permission import Permission
perms = self.of.ac_inherited_permissions(1)
name, value = [p for p in perms if p[0]=='Use OpenFlow'][0][:2]
p=Permission(name,value,self.of)
roles = ['Authenticated']
p.setRoles(roles)
示例4: update
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def update(app):
catalog = getattr(app, 'Catalog')
brains = catalog(meta_type='Report Document')
for brain in brains:
doc = brain.getObject()
valid_roles = doc.valid_roles()
if 'Auditor' in valid_roles:
permissions = doc.ac_inherited_permissions(1)
for perm in permissions:
name, value = perm[:2]
if name == 'View':
p = Permission(name, value, doc)
roles = list(p.getRoles())
if 'Auditor' not in roles:
roles.append('Auditor')
roles = tuple(roles)
try:
p.setRoles(roles)
print "Added Auditor to View permission for %s" % doc.absolute_url()
except:
print "Failed"
transaction.commit()
示例5: _modifyPermissionMappings
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def _modifyPermissionMappings(ob, map):
"""
Modifies multiple role to permission mappings.
"""
# This mimics what AccessControl/Role.py does.
# Needless to say, it's crude. :-(
something_changed = 0
perm_info = _ac_inherited_permissions(ob, 1)
for name, settings in map.items():
cur_roles = rolesForPermissionOn(name, ob)
if isinstance(cur_roles, basestring):
cur_roles = [cur_roles]
else:
cur_roles = list(cur_roles)
changed = 0
for (role, allow) in settings.items():
if not allow:
if role in cur_roles:
changed = 1
cur_roles.remove(role)
else:
if role not in cur_roles:
changed = 1
cur_roles.append(role)
if changed:
data = () # The list of methods using this permission.
for perm in perm_info:
n, d = perm[:2]
if n == name:
data = d
break
p = Permission(name, data, ob)
p.setRoles(tuple(cur_roles))
something_changed = 1
return something_changed
示例6: _update
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def _update(self, portal):
layout_permission = Permission(view, (), portal.portal_layout)
layout_permission.setRoles(portal.validRoles())
dyn_permission = Permission(view, (), portal.portal_dynamicproperties)
dyn_permission.setRoles(portal.validRoles())
self.log.info('Done')
return True
示例7: setPermissionMapping
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def setPermissionMapping(self, mapping):
"""
Change the permission mapping for the object.
This leaves the other permissions (not in mapping.keys()) unchanged
"""
for permission in mapping:
permission_object = Permission(permission, (), self.getObject())
permission_object.setRoles(mapping[permission])
示例8: _update
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def _update(self, portal):
layout_tool = portal.getLayoutTool()
view_perm = Permission(view, (), layout_tool)
if 'Anonymous' not in view_perm.getRoles():
view_perm.setRoles(['Anonymous',])
self.log.info("View Permission set for Anonymous on portal_layout.")
else:
self.log.info("Already has it, nothing to do.")
return True
示例9: setPermissionMapping
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def setPermissionMapping(self, mapping):
"""
Change the permission mapping for the parent.
This leaves the other permissions (not in mapping.keys()) unchanged
"""
for zope_perm in mapping:
permission = Permission(zope_perm, (), self.aq_parent)
permission.setRoles(mapping[zope_perm])
transaction.commit()
示例10: manage_addLayoutTool
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def manage_addLayoutTool(self, REQUEST=None):
""" """
ob = LayoutTool(ID_LAYOUTTOOL, TITLE_LAYOUTTOOL)
self._setObject(ID_LAYOUTTOOL, ob)
ob_aq = self._getOb(ID_LAYOUTTOOL)
ob_aq.loadDefaultData()
view_perm = Permission(view, (), ob_aq)
view_perm.setRoles(['Anonymous',])
if REQUEST:
return self.manage_main(self, REQUEST, update_menu=1)
示例11: _update
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def _update(self, portal):
skip_captcha_perm = Permission('Naaya - Skip Captcha', (), portal)
roles_with_skip_captcha = skip_captcha_perm.getRoles()
if 'Authenticated' not in roles_with_skip_captcha:
roles_with_skip_captcha.append('Authenticated')
skip_captcha_perm.setRoles(roles_with_skip_captcha)
self.log.debug('Skip Captcha permission assigned to Authenticated')
else:
self.log.debug('Authenticated already has the permission')
return True
示例12: set_acl_for_roles
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def set_acl_for_roles(ob, roles):
permission_object = Permission(view, (), ob)
current_roles = permission_object.getRoles()
is_tuple = isinstance(current_roles, tuple)
current_roles = list(current_roles)
new_roles = set(roles + current_roles)
if is_tuple:
new_roles = tuple(new_roles)
else:
new_roles = list(new_roles)
permission_object.setRoles(new_roles)
示例13: _update
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def _update(self, portal):
review_perm = Permission('Naaya - Review TalkBack Consultation',
(), portal)
for role in ['Administrator', 'Owner', 'Reviewer']:
roles = review_perm.getRoles()
if role not in roles:
roles.append(role)
review_perm.setRoles(roles)
self.log.info("Review Permission set for %s on %s" %
(role, portal.absolute_url()))
return True
示例14: tearDown
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def tearDown(self):
self.browser_do_logout()
self.auth_tool.manage_revokeUserRole(user=self.user_obj.name,
location='/portal/info')
# reset portal roles with view
view_perm = Permission(view, (), self.portal)
view_perm.setRoles(self.site_roles_with_view)
transaction.commit()
super(UserWithRolesOnlyOnFolderTestSetup, self).tearDown()
示例15: manage_acquiredPermissions
# 需要导入模块: from AccessControl.Permission import Permission [as 别名]
# 或者: from AccessControl.Permission.Permission import setRoles [as 别名]
def manage_acquiredPermissions(self, permissions=[]):
"""Change the permissions that acquire.
"""
for p in self.ac_inherited_permissions(1):
name, value = p[:2]
p = Permission(name, value, self)
roles = p.getRoles()
if roles is None:
continue
if name in permissions:
p.setRoles(list(roles))
else:
p.setRoles(tuple(roles))