Ignore:
Timestamp:
20 May 2011, 12:01:50 (13 years ago)
Author:
uli
Message:

Move get_users_with_local_roles and shorten it.

File:
1 edited

Legend:

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

    r6162 r6163  
    22from zope.component import getUtilitiesFor
    33from zope.interface import Interface
    4 from zope.securitypolicy.interfaces import IRole
     4from zope.securitypolicy.interfaces import IRole, IPrincipalRoleMap
    55from waeup.sirp.interfaces import ILocalRolesAssignable
    66
     
    136136                name=name,
    137137                title=role.title,
    138                 description =role.description)
     138                description=role.description)
    139139            for name, role in self._roles]
    140140
     
    143143        """
    144144        return [name for name, role in self._roles]
     145
     146def get_users_with_local_roles(context):
     147    """Get a list of dicts representing the local roles set for `context`.
     148
     149    Each dict returns `user_name`, `user_title`, `local_role`,
     150    `local_role_title`, and `setting` for each entry in the local
     151    roles map of the `context` object.
     152    """
     153    role_map = IPrincipalRoleMap(context)
     154    for local_role, user_name, setting in role_map.getPrincipalsAndRoles():
     155        user = grok.getSite()['users'].get(user_name,None)
     156        user_title = getattr(user, 'description', user_name)
     157        local_role_title = getRoles()[local_role].title
     158        yield dict(user_name = user_name,
     159                   user_title = user_title,
     160                   local_role = local_role,
     161                   local_role_title = local_role_title,
     162                   setting = setting)
Note: See TracChangeset for help on using the changeset viewer.