Display LDAP group membership sorted by user.
540458
def by_user(config):
        """"""
        client = Client()
        client.prepare_connection()
        audit_api = API(client)
        CLI.parse_membership('Groups by User', audit_api.by_user())
882045
def list_users(self):
    '''
    ''' 
    folders = glob('%s/*' %(self.database))
    folders.sort()
    return [self.print_user(x) for x in folders]
79998
def organization_membership_show(self, id, **kwargs):
        ""
        api_path = "/api/v2/organization_memberships/{id}.json"
        api_path = api_path.format(id=id)
        return self.call(api_path, **kwargs)
1136043
def get_role_members(self, role):
        """"""
        targetRoleDb = AuthGroup.objects(creator=self.client, role=role)
        members = AuthMembership.objects(groups__in=targetRoleDb).only('user')
        return json.loads(members.to_json())
1308038
def is_member(self, ldap_user, group_dn):
        
        try:
            user_uid = ldap_user.attrs["uid"][0]

            try:
                is_member = ldap_user.connection.compare_s(
                    group_dn, "memberUid", user_uid.encode()
                )
            except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
                is_member = False

            if not is_member:
                try:
                    user_gid = ldap_user.attrs["gidNumber"][0]
                    is_member = ldap_user.connection.compare_s(
                        group_dn, "gidNumber", user_gid.encode()
                    )
                except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
                    is_member = False
        except (KeyError, IndexError):
            is_member = False

        return is_member
1334830
def members(self):
        """"""
        result = list()
        for member in self.run_command(command="replSetGetStatus", is_eval=False)['members']:
            result.append({
                "_id": member['_id'],
                "host": member["name"],
                "server_id": self._servers.host_to_server_id(member["name"]),
                "state": member['state']
            })
        return result
71752
def _get_groups(self):
        
        if self._groups is None:
            self._groups = _LDAPUserGroups(self)

        return self._groups
1102853
def in_group(self, group, dn=False):
        
        if dn:
            return group in self.groups()
        return group.check_member(self)
1250331
def groups(self, user, include=None):
        
        return self._query_zendesk(self.endpoint.groups, 'group', id=user, include=include)
1275618
def by_group(self):  # pragma: no cover
        
        group_membership = {}
        for record in self.__get_groups_with_membership():
            group_membership[record.cn.value] = [
                i for i in record.memberUid.values
            ]
        return group_membership
119020
def _listAttrGroupMembers(self, attrGroup):
        
        from inspect import getmembers, ismethod
        methods = getmembers(self, ismethod)
        group_prefix = attrGroup + '_'
        group_len = len(group_prefix)
        group_members = [method[0][group_len:]
                         for method in methods
                         if method[0].startswith(group_prefix)]
        return group_members
770421
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))
347085
def listMemberHelps(TargetGroup):
  
  """
  Members = []

  for Member in TargetGroup.Members.values(): # get unique children (by discarding aliases)
    if Member not in Members:
      Members.append(Member)

  Ret = []

  for Member in Members:
    Config = Member.Config
    Ret.append(('%s%s' % (Config['name'], ', %s' % Config['alias'] if 'alias' in Config else ''), Config.get('desc', '')))

  return Ret
485052
def user_group_memberships(self, user_id, **kwargs):
        ""
        api_path = "/api/v2/users/{user_id}/group_memberships.json"
        api_path = api_path.format(user_id=user_id)
        return self.call(api_path, **kwargs)
1119936
def check_membership(self, groups):
        '''  '''
        if not groups or groups == ['']:
            return True
        if self.request.user.is_superuser:
            return True
        user_groups = self.request.user.groups.values_list("name", flat=True)
        return set(groups).intersection(set(user_groups))
1307128
def get_gid_list(user, include_default=True):
    '''
    
    '''
    if HAS_GRP is False or HAS_PWD is False:
        return []
    gid_list = list(
        six.itervalues(
            get_group_dict(user, include_default=include_default)
        )
    )
    return sorted(set(gid_list))
1254643
def get_user_roles(self, user):
        """"""
        memberShipRecords = AuthMembership.objects(creator=self.client, user=user).only('groups')
        results = []
        for each in memberShipRecords:
            for group in each.groups:
                results.append({'role':group.role})
        return results