def filter_grantable_permissions(session, grants, all_permissions=None):

    if all_permissions is None:
        all_permissions = {permission.name: permission for permission in
                Permission.get_all(session)}

    result = []
    for grant in grants:
        assert grant.name == PERMISSION_GRANT

        grantable = grant.argument.split('/', 1)
        if not grantable:
            continue
        for name, permission_obj in all_permissions.iteritems():
            if matches_glob(grantable[0], name):
                result.append((permission_obj,
                               grantable[1] if len(grantable) > 1 else '*', ))

    return sorted(result, key=lambda x: x[0].name + x[1])
For a given set of PERMISSION_GRANT permissions, return all permissions
dataset/ETHPy150Open dropbox/grouper/grouper/permissions.py/filter_grantable_permissions