def control_panel_permission_filter(session_user, *sections):
    """
        takes a blazeweb.user:User object and ControlPanelSections for *args
        and sets the user_has_perm attribute on the ControlPanelSection,
        ControlPanelGroup, and ControlPanelList objects as appropriate.
    """
    retval = []
    for sec in sections:
        sec_groups = []
        if sec.has_perm and not session_user.has_any_perm(sec.has_perm):
            continue
        for lg in sec.groups:
            group_links = []
            if lg.has_perm and not session_user.has_perm(lg.has_perm):
                continue
            for link in lg.links:
                if session_user.has_perm(link.has_perm) or not link.has_perm:
                    group_links.append(link)
            if group_links:
                sec_groups.append({'group': lg, 'group_links': group_links})
        if sec_groups:
            retval.append({'sec': sec, 'sec_groups': sec_groups})
    return retval
