// FindUsers searches for users that match the given filter criteria.
347784
func (a *API) FindUsers(filter string) ([]User, error) {
	params := Params{}
	if filter != EmptyFilter {
		params["q"] = filter
	}

	dst := make([]User, 0)
	url := a.BuildURL("/v2/user")
	err := a.Get(url, params, &dst)
	return dst, err
}
1345367
func (c *Client) FindUserResourceMappings(ctx context.Context, filter platform.UserResourceMappingFilter, opt ...platform.FindOptions) ([]*platform.UserResourceMapping, int, error) {
	ms := []*platform.UserResourceMapping{}
	err := c.db.View(func(tx *bolt.Tx) error {
		mappings, err := c.findUserResourceMappings(ctx, tx, filter)
		if err != nil {
			return err
		}
		ms = mappings
		return nil
	})

	if err != nil {
		return nil, 0, err
	}

	return ms, len(ms), nil
}
37564
func (u *UserStats) GetAdminUsers() int {
	if u == nil || u.AdminUsers == nil {
		return 0
	}
	return *u.AdminUsers
}
1059840
func (u Util) userLookup(name string) (*user.User, error) {
	res := &C.lookup_res_t{}

	if ret, err := C.user_lookup(C.CString(u.DestDir),
		C.CString(name), res); ret < 0 {
		return nil, fmt.Errorf("lookup failed: %v", err)
	}

	if res.name == nil {
		return nil, fmt.Errorf("user %q not found", name)
	}

	homedir, err := u.JoinPath(C.GoString(res.home))
	if err != nil {
		return nil, err
	}

	usr := &user.User{
		Name:    C.GoString(res.name),
		Uid:     fmt.Sprintf("%d", int(res.uid)),
		Gid:     fmt.Sprintf("%d", int(res.gid)),
		HomeDir: homedir,
	}

	C.user_lookup_res_free(res)

	return usr, nil
}
1075798
func (e *PGPKeyfinder) loadUsers(m libkb.MetaContext) {
	if e.runerr != nil {
		return
	}

	for _, u := range e.arg.Usernames {
		arg := libkb.NewLoadUserByNameArg(e.G(), u)
		user, err := libkb.LoadUser(arg)
		if err != nil {
			e.runerr = err
			return
		}
		e.addUser(user, false)
	}

}
731623
func (s *UserService) FindUser(ctx context.Context, filter influxdb.UserFilter) (*influxdb.User, error) {
	o, err := s.s.FindUser(ctx, filter)
	if err != nil {
		return nil, err
	}

	if err := authorizeReadUser(ctx, o.ID); err != nil {
		return nil, err
	}

	return o, nil
}
663797
func MemberMatchesPredicates(member Member, predicates ...MemberPredicate) bool {
	for _, p := range predicates {
		if !p(member) {
			return false
		}
	}
	return true
}
850835
func (s *Service) FindUser(ctx context.Context, filter influxdb.UserFilter) (*influxdb.User, error) {
	if filter.ID != nil {
		u, err := s.FindUserByID(ctx, *filter.ID)
		if err != nil {
			return nil, err
		}
		return u, nil
	}

	if filter.Name != nil {
		return s.FindUserByName(ctx, *filter.Name)
	}

	return nil, ErrUserNotFound
}
114963
func (s *UserService) FindUsers(ctx context.Context, filter platform.UserFilter, opt ...platform.FindOptions) ([]*platform.User, int, error) {
	url, err := newURL(s.Addr, usersPath)
	if err != nil {
		return nil, 0, err
	}

	query := url.Query()

	req, err := http.NewRequest("GET", url.String(), nil)
	if err != nil {
		return nil, 0, err
	}
	if filter.ID != nil {
		query.Add("id", filter.ID.String())
	}
	if filter.Name != nil {
		query.Add("name", *filter.Name)
	}

	req.URL.RawQuery = query.Encode()
	SetToken(s.Token, req)

	hc := newClient(url.Scheme, s.InsecureSkipVerify)
	resp, err := hc.Do(req)
	if err != nil {
		return nil, 0, err
	}

	if err := CheckError(resp, true); err != nil {
		return nil, 0, err
	}

	var r usersResponse
	if err := json.NewDecoder(resp.Body).Decode(&r); err != nil {
		return nil, 0, err
	}

	us := r.ToPlatform()
	return us, len(us), nil
}
1145924
func (c *Client) FindViews(ctx context.Context, filter platform.ViewFilter) ([]*platform.View, int, error) {
	ds := []*platform.View{}
	op := getOp(platform.OpFindViews)
	if filter.ID != nil {
		d, err := c.FindViewByID(ctx, *filter.ID)
		if err != nil && platform.ErrorCode(err) != platform.ENotFound {
			return nil, 0, &platform.Error{
				Err: err,
				Op:  op,
			}
		}
		if d != nil {
			ds = append(ds, d)
		}

		return ds, 1, nil
	}

	err := c.db.View(func(tx *bolt.Tx) error {
		dashs, err := c.findViews(ctx, tx, filter)
		if err != nil {
			return &platform.Error{
				Err: err,
				Op:  op,
			}
		}
		ds = dashs
		return nil
	})

	return ds, len(ds), err
}
462706
func (c *Crowd) GetGroups(user string, donested bool) ([]*Group, error) {
	groupList := listGroups{}

	v := url.Values{}
	v.Set("username", user)
	var endpoint string

	if donested {
		endpoint = "nested"
	} else {
		endpoint = "direct"
	}

	url := c.url + "rest/usermanagement/1/user/group/" + endpoint + "?" + v.Encode()
	c.Client.Jar = c.cookies
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return groupList.Groups, err
	}
	req.SetBasicAuth(c.user, c.passwd)
	req.Header.Set("Accept", "application/json")
	resp, err := c.Client.Do(req)
	if err != nil {
		return groupList.Groups, err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case 404:
		return groupList.Groups, fmt.Errorf("user not found")
	case 200:
		// fall through switch without returning
	default:
		return groupList.Groups, fmt.Errorf("request failed: %s", resp.Status)
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return groupList.Groups, err
	}

	err = json.Unmarshal(body, &groupList)
	if err != nil {
		return groupList.Groups, err
	}

	return groupList.Groups, nil
}
511877
func (s *AuthorizationService) FindAuthorizations(ctx context.Context, filter platform.AuthorizationFilter, opt ...platform.FindOptions) ([]*platform.Authorization, int, error) {
	u, err := newURL(s.Addr, authorizationPath)
	if err != nil {
		return nil, 0, err
	}

	query := u.Query()

	req, err := http.NewRequest("GET", u.String(), nil)
	if err != nil {
		return nil, 0, err
	}

	if filter.ID != nil {
		query.Add("id", filter.ID.String())
	}

	if filter.UserID != nil {
		query.Add("userID", filter.UserID.String())
	}

	if filter.User != nil {
		query.Add("user", *filter.User)
	}

	if filter.OrgID != nil {
		query.Add("orgID", filter.OrgID.String())
	}

	if filter.Org != nil {
		query.Add("org", *filter.Org)
	}

	req.URL.RawQuery = query.Encode()
	SetToken(s.Token, req)

	hc := newClient(u.Scheme, s.InsecureSkipVerify)
	resp, err := hc.Do(req)
	if err != nil {
		return nil, 0, err
	}
	defer resp.Body.Close()

	if err := CheckError(resp); err != nil {
		return nil, 0, err
	}

	var as authsResponse
	if err := json.NewDecoder(resp.Body).Decode(&as); err != nil {
		return nil, 0, err
	}

	auths := make([]*platform.Authorization, 0, len(as.Auths))
	for _, a := range as.Auths {
		auths = append(auths, a.toPlatform())
	}

	return auths, len(auths), nil
}
542681
func (m modelShim) Users() ([]permission.UserAccess, error) {
	stateUsers, err := m.Model.Users()
	if err != nil {
		return nil, err
	}
	users := make([]permission.UserAccess, len(stateUsers))
	for i, user := range stateUsers {
		users[i] = user
	}
	return users, nil
}
453751
func (c *Client) SearchMembers(query string, args Arguments) (members []*Member, err error) {
	args["query"] = query
	err = c.Get("search/members", args, &members)
	return
}
1215769
func (s *Service) FindViews(ctx context.Context, filter platform.ViewFilter) ([]*platform.View, int, error) {
	var ds []*platform.View
	if filter.ID != nil {
		d, err := s.FindViewByID(ctx, *filter.ID)
		if err != nil && platform.ErrorCode(err) != platform.ENotFound {
			return nil, 0, &platform.Error{
				Err: err,
				Op:  OpPrefix + platform.OpFindViews,
			}
		}
		if d != nil {
			ds = append(ds, d)
		}

		return ds, len(ds), nil
	}

	var err error
	filterF := filterViewFn(filter)
	s.viewKV.Range(func(k, v interface{}) bool {
		d, ok := v.(*platform.View)
		if !ok {
			return false
		}

		if filterF(d) {
			ds = append(ds, d)
		}
		return true
	})
	return ds, len(ds), err
}
96103
func (bot *Bot) usersLookup(ids []int64) (*apiResult, error) {
	if len(ids) > 100 {
		return nil, errors.New("Too many ids!")
	}
	strIds := make([]string, len(ids))
	for i, id := range ids {
		strIds[i] = strconv.FormatInt(id, 10)
	}
	query := url.Values{}
	query.Set("user_id", strings.Join(strIds, ","))

	// get users
	users := make([]User, len(ids))
	rateLimit, err := bot.request(post, "/users/lookup.json", query, &users)
	if err != nil {
		return nil, err
	}
	return &apiResult{
		results:   users,
		rateLimit: rateLimit,
	}, nil
}
657715
func (s UserResource) FindAll(r api2go.Request) (api2go.Responder, error) {
	var result []model.User
	users := s.UserStorage.GetAll()

	for _, user := range users {
		// get all sweets for the user
		user.Chocolates = []*model.Chocolate{}
		for _, chocolateID := range user.ChocolatesIDs {
			choc, err := s.ChocStorage.GetOne(chocolateID)
			if err != nil {
				return &Response{}, err
			}
			user.Chocolates = append(user.Chocolates, &choc)
		}
		result = append(result, *user)
	}

	return &Response{Res: result}, nil
}