def grant_member(context, request):
    """Grant member roles in the group."""
    mapping = request.json['mapping']
    for entry in mapping:
        user = entry['user']
        roles = entry['roles']
        username = user.get('username', None)
        userid = user.get('userid', None)
        if userid:
            u = context.get_user_by_userid(userid)
        elif username:
            u = context.get_user_by_username(username)
        else:
            u = None
        if u is None:
            raise UnprocessableError(
                'User %s does not exists' % (userid or username))
        for rolename in roles:
            context.grant_member_role(u.userid, rolename)
    return {'status': 'success'}
def grant_member ( context , request ) : mapping = request . json [ 'mapping' ] for entry in mapping : user = entry [ 'user' ] roles = entry [ 'roles' ] username = user . get ( 'username' , None ) userid = user . get ( 'userid' , None ) if userid : u = context . get_user_by_userid ( userid ) elif username : u = context . get_user_by_username ( username ) else : u = None if u is None : raise UnprocessableError ( 'User %s does not exists' % ( userid or username ) ) for rolename in roles : context . grant_member_role ( u . userid , rolename ) return { 'status' : 'success' }
Grant member roles in the group.