Changeset 6157 for main/waeup.sirp/trunk
- Timestamp:
- 20 May 2011, 08:52:48 (14 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py
r6147 r6157 9 9 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm 10 10 11 12 11 class FatalCSVError(Exception): 13 12 """Some row could not be processed. … … 24 23 class RoleSource(BasicSourceFactory): 25 24 def getValues(self): 25 # late import: in interfaces we should not import local modules 26 from waeup.sirp.permissions import getWAeUPRoleNames 27 return getWAeUPRoleNames() 28 29 def getTitle(self, value): 30 # late import: in interfaces we should not import local modules 26 31 from waeup.sirp.permissions import getRoles 27 return getRoles() 28 def getTitle(self, value): 29 if isinstance(value, basestring): 30 return value.split('.', 2)[1] 32 roles = dict(getRoles()) 33 if value in roles.keys(): 34 title = roles[value].title 35 if '.' in title: 36 title = title.split('.', 2)[1] 37 return title 31 38 32 39 class IWAeUPObject(Interface): -
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): -
main/waeup.sirp/trunk/src/waeup/sirp/permissions.txt
r6059 r6157 7 7 .. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer 8 8 9 We can get all roles defined in a WAeUP portal (except 'local' roles 10 that are meant not to be assigned globally): 9 Convenience functions 10 ===================== 11 12 :mod:`waeup.sirp` offers some convenience functions to handle security 13 roles. 14 15 :func:`getRoles` 16 ---------------- 17 18 Gives us all roles defined in a WAeUP SIRP portal. We get tuples of 19 kind 20 21 ``(<ROLE-NAME>, <ROLE>)`` 22 23 where ``<ROLE-NAME>`` is the name under which a role was registered 24 with the ZCA (a string) and ``<ROLE>`` is the real role object. 11 25 12 26 >>> from waeup.sirp.permissions import getRoles 13 27 >>> getRoles() 14 ['waeup.PortalManager', 'waeup.PortalUser']28 <generator object at 0x...> 15 29 30 >>> sorted(list(getRoles())) 31 [(u'waeup.PortalManager', <waeup...PortalManager object at 0x...>), ...] 32 33 :func:`getWAeUPRoles` 34 --------------------- 35 36 Gives us all roles, except the WAeUP specific roles. We can get a list 37 with or without local roles: 38 39 >>> from waeup.sirp.permissions import getWAeUPRoles 40 >>> len(list(getWAeUPRoles())) 41 2 42 43 >>> len(list(getWAeUPRoles(also_local=True))) 44 4 45 46 47 :func:`getRoleNames` 48 -------------------- 49 50 We can get all role names defined in a WAeUP portal (except 'local' 51 roles that are meant not to be assigned globally): 52 53 >>> from waeup.sirp.permissions import getWAeUPRoleNames 54 >>> list(getWAeUPRoleNames()) 55 [u'waeup.PortalManager', u'waeup.PortalUser']
Note: See TracChangeset for help on using the changeset viewer.