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.

File:
1 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)
Note: See TracChangeset for help on using the changeset viewer.