code: def get_user_groups(self, user):
          
  
          conn = self.bind
          try:
              if current_app.config['LDAP_OPENLDAP']:
                  fields = \
                      [str(current_app.config['LDAP_GROUP_MEMBER_FILTER_FIELD'])]
                  records = conn.search_s(
                      current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE,
                      ldap_filter.filter_format(
                          current_app.config['LDAP_GROUP_MEMBER_FILTER'],
                          (self.get_object_details(user, dn_only=True),)),
                      fields)
              else:
                  records = conn.search_s(
                      current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE,
                      ldap_filter.filter_format(
                          current_app.config['LDAP_USER_OBJECT_FILTER'],
                          (user,)),
                      [current_app.config['LDAP_USER_GROUPS_FIELD']])
  
              conn.unbind_s()
              if records:
                  if current_app.config['LDAP_OPENLDAP']:
                      group_member_filter = \
                          current_app.config['LDAP_GROUP_MEMBER_FILTER_FIELD']
                      if sys.version_info[0] > 2:
                          groups = [record[1][group_member_filter][0].decode(
                              'utf-8') for record in records]
                      else:
                          groups = [record[1][group_member_filter][0] for
                                    record in records]
                      return groups
                  else:
                      if current_app.config['LDAP_USER_GROUPS_FIELD'] in \
                              records[0][1]:
                          groups = records[0][1][
                              current_app.config['LDAP_USER_GROUPS_FIELD']]
                          result = [re.findall(b'(?:cn=|CN=)(.*?),', group)[0]
                                    for group in groups]
                          if sys.version_info[0] > 2:
                              result = [r.decode('utf-8') for r in result]
                          return result
          except ldap.LDAPError as e:
              raise LDAPException(self.error(e.args))
docs: Returns a ``list`` with the user's groups or ``None`` if
          unsuccessful.
  
          :param str user: User we want groups for.