def METHOD_NAME(self, ldap_user, group_search):
    """Get groups which user belongs to."""
    group_map = []
    def handle_groups(groups_dns):
        """
        Compare user groups with groups accepted by Ralph
        (`self.ldap_groups`) and for each in common get LDAP group
        Args:
            groups_dns: set of user groups DNs
        """
        for group_dn in groups_dns & set(self.ldap_groups.keys()):
            group = self._get_group(group_dn, ldap_user, group_search)
            group_map.append(group)
    username = ldap_user.attrs[settings.AUTH_LDAP_USER_USERNAME_ATTR][0]
    # handle flat groups first (to which user belongs directly)
    try:
        flat_groups_dns = set(map(force_text, ldap_user.attrs['memberOf']))
    except KeyError:
        flat_groups_dns = set()
    logger.info('Flat groups DNs for {}: {}'.format(
        username, flat_groups_dns
    ))
    handle_groups(flat_groups_dns)
    # handle nested groups
    nested_groups_dns = get_nested_groups()[1].get(username, set())
    logger.info('Nested groups DNs for {}: {}'.format(
        username, nested_groups_dns
    ))
    handle_groups(nested_groups_dns)
    return group_map