Ignore:
Timestamp:
20 May 2011, 08:52:48 (13 years ago)
Author:
uli
Message:

Zope roles come with a title attribute. Start making use of it and simplify role lookup in w.s.permissions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/permissions.py

    r6155 r6157  
    11import grok
     2from zope.component import getUtilitiesFor
    23from zope.interface import Interface
     4from zope.securitypolicy.interfaces import IRole
    35from waeup.sirp.interfaces import ILocalRolesAssignable
    46
     
    5557
    5658def 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
     63def 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.'):
    7077            # Ignore non-WAeUP roles...
    7178            continue
    72         if item[1].startswith('waeup.local.'):
     79        if not also_local and name.startswith('waeup.local.'):
     80            # Ignore local roles...
    7381            continue
    74         result[item[1]] = True
    75     return sorted(result.keys())
     82        yield item
     83
     84def 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
    7693
    7794class LocalRolesAssignable(grok.Adapter):
Note: See TracChangeset for help on using the changeset viewer.