Ignore:
Timestamp:
7 Oct 2012, 21:49:12 (12 years ago)
Author:
Henrik Bettermann
Message:

Add function get_users_with_role. We need this for collecting email addresses.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 edited

Legend:

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

    r9303 r9309  
    360360                   local_role_title = local_role_title,
    361361                   setting = setting)
     362
     363def get_users_with_role(role, context):
     364    """Get a list of dicts representing the usres who have been granted
     365    a role for `context`.
     366    """
     367    try:
     368        role_map = IPrincipalRoleMap(context)
     369    except TypeError:
     370        # no map no roles.
     371        raise StopIteration
     372    for user_name, setting in role_map.getPrincipalsForRole(role):
     373        user = grok.getSite()['users'].get(user_name,None)
     374        user_title = getattr(user, 'title', user_name)
     375        user_email = getattr(user, 'email', None)
     376        yield dict(user_name = user_name,
     377                   user_title = user_title,
     378                   user_email = user_email,
     379                   setting = setting)
  • main/waeup.kofa/trunk/src/waeup/kofa/permissions.txt

    r9300 r9309  
    8989    >>> people_and_roles
    9090    []
     91
     92:func:`get_users_with_role`
     93---------------------------
     94
     95We can get all users with a specific role for a certain context
     96object:
     97
     98    >>> from waeup.kofa.permissions import get_users_with_role
     99    >>> mycontext = object()
     100    >>> people = get_users_with_role('waeup.portalManager', mycontext)
     101    >>> people
     102    <generator object...at 0x...>
     103
     104In this case, the result is empty:
     105
     106    >>> people = list(people)
     107    >>> people
     108    []
Note: See TracChangeset for help on using the changeset viewer.