Changeset 6157 for main/waeup.sirp/trunk/src/waeup/sirp/permissions.py
- Timestamp:
- 20 May 2011, 08:52:48 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/permissions.py
r6155 r6157 1 1 import grok 2 from zope.component import getUtilitiesFor 2 3 from zope.interface import Interface 4 from zope.securitypolicy.interfaces import IRole 3 5 from waeup.sirp.interfaces import ILocalRolesAssignable 4 6 … … 55 57 56 58 def getRoles(): 57 app = grok.getSite() 58 app = None 59 manager = None 60 if app is not None: 61 from zope.securitypolicy.interfaces import IRolePermissionManager 62 manager = IRolePermissionManager(app, None) 63 else: 64 from zope.securitypolicy.rolepermission import ( 65 rolePermissionManager as manager) 66 role_permission_map = manager.getRolesAndPermissions() 67 result = dict() 68 for item in role_permission_map: 69 if not item[1].startswith('waeup.'): 59 """Return a list of tuples ``<ROLE-NAME>, <ROLE>``. 60 """ 61 return getUtilitiesFor(IRole) 62 63 def getWAeUPRoles(also_local=False): 64 """Get all WAeUP roles. 65 66 WAeUP roles are ordinary roles whose id by convention starts with 67 a ``waeup.`` prefix. 68 69 If `also_local` is ``True`` (``False`` by default), also local 70 roles are returned. Local WAeUP roles are such whose id starts 71 with ``waeup.local.`` prefix (this is also a convention). 72 73 Returns a generator of the found roles. 74 """ 75 for name, item in getRoles(): 76 if not name.startswith('waeup.'): 70 77 # Ignore non-WAeUP roles... 71 78 continue 72 if item[1].startswith('waeup.local.'): 79 if not also_local and name.startswith('waeup.local.'): 80 # Ignore local roles... 73 81 continue 74 result[item[1]] = True 75 return sorted(result.keys()) 82 yield item 83 84 def getWAeUPRoleNames(): 85 """Get the ids of all WAeUP roles. 86 87 See :func:`getWAeUPRoles` for what a 'WAeUPRole' is. 88 89 This function returns a sorted list of WAeUP role names. 90 """ 91 return sorted([x.id for x in getWAeUPRoles()]) 92 76 93 77 94 class LocalRolesAssignable(grok.Adapter):
Note: See TracChangeset for help on using the changeset viewer.