// IterateUserTypes calls the given iterator passing in each user type sorted in alphabetical order.
// Iteration stops if an iterator returns an error and in this case IterateUserTypes returns that
// error.
543250
func (a *APIDefinition) IterateUserTypes(it UserTypeIterator) error {
	names := make([]string, len(a.Types))
	i := 0
	for n := range a.Types {
		names[i] = n
		i++
	}
	sort.Strings(names)
	for _, n := range names {
		if err := it(a.Types[n]); err != nil {
			return err
		}
	}
	return nil
}
1199764
func identifyUsers(
	ctx context.Context, nug idutil.NormalizedUsernameGetter,
	identifier idutil.Identifier,
	names map[keybase1.UserOrTeamID]kbname.NormalizedUsername,
	t tlf.Type, offline keybase1.OfflineAvailability) error {
	eg, ctx := errgroup.WithContext(ctx)

	// TODO: limit the number of concurrent identifies?
	// TODO: implement a version of errgroup with limited concurrency.
	for id, name := range names {
		// Capture range variables.
		id, name := id, name
		eg.Go(func() error {
			return identifyUser(ctx, nug, identifier, name, id, t, offline)
		})
	}

	return eg.Wait()
}
1271151
func (kv *KV) Iterator(f func([]byte, []byte) bool) error {
	for k := range kv.db.Keys(nil) {
		v, err := kv.db.Read(k)
		if err != nil {
			return err
		}
		if !f(gkv.Stob(k), v) {
			break
		}
	}
	return nil
}
816328
func (sd *StorageGroupDefinition) IterateSets(iterator dslengine.SetIterator) {
	// First run the top level StorageGroup

	iterator([]dslengine.Definition{sd})
	sd.IterateStores(func(store *RelationalStoreDefinition) error {
		iterator([]dslengine.Definition{store})
		store.IterateModels(func(model *RelationalModelDefinition) error {
			iterator([]dslengine.Definition{model})
			model.IterateFields(func(field *RelationalFieldDefinition) error {
				iterator([]dslengine.Definition{field})
				return nil
			})
			model.IterateBuildSources(func(bs *BuildSource) error {
				iterator([]dslengine.Definition{bs})
				return nil
			})

			return nil
		})
		return nil
	})
}
480079
func LoadUsers(engine Engine) (map[int64]datamodels.User, error) {
	if engine != Memory {
		return nil, errors.New("for the shake of simplicity we're using a simple map as the data source")
	}

	return make(map[int64]datamodels.User), nil
}
948289
func (c *SearchController) Users(ctx *app.UsersSearchContext) error {

	_, err := c.app.UserService().LoadContextIdentityIfNotBanned(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error()))
	}

	q := ctx.Q
	if len(q) == 0 {
		return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("", "search query should be longer"))
	}

	var result []account.Identity
	var count int

	exceeded := false
	offset, limit := computePagingLimits(ctx.PageOffset, ctx.PageLimit)

	r, err := regexp.Compile(`\w`) // check for A-Z a-z 0-9

	searchLimit := limit
	// Don't return more users than allowed by configuration
	if offset >= c.configuration.GetMaxUsersListLimit() {
		exceeded = true
	} else if offset+limit > c.configuration.GetMaxUsersListLimit() {
		searchLimit = c.configuration.GetMaxUsersListLimit() - offset
	}

	if r.MatchString(q) && len(q) > 1 { // 2 or more characters
		err = transaction.Transactional(c.app, func(tr transaction.TransactionalResources) error {
			result, count, err = tr.Identities().Search(ctx, q, offset, searchLimit)
			return err
		})
		if err != nil {
			log.Error(ctx, map[string]interface{}{
				"err": err,
			}, "unable to run search query on users.")
			return jsonapi.JSONErrorResponse(ctx, err)
		}
	}

	if exceeded {
		result = []account.Identity{}
	}
	if count > c.configuration.GetMaxUsersListLimit() {
		// Hide the real count if it's more than the max allowed limit
		count = c.configuration.GetMaxUsersListLimit()
	}

	var users []*app.UserData
	for i := range result {
		ident := result[i]
		id := ident.ID.String()
		userID := ident.User.ID.String()

		email := ident.User.Email
		if ident.User.EmailPrivate {
			email = ""
		}

		users = append(users, &app.UserData{
			Type: "identities",
			ID:   &id,
			Attributes: &app.UserDataAttributes{
				CreatedAt:    &ident.User.CreatedAt,
				UpdatedAt:    &ident.User.UpdatedAt,
				Username:     &ident.Username,
				FullName:     &ident.User.FullName,
				ImageURL:     &ident.User.ImageURL,
				Bio:          &ident.User.Bio,
				URL:          &ident.User.URL,
				UserID:       &userID,
				IdentityID:   &id,
				Email:        &email,
				EmailPrivate: &ident.User.EmailPrivate,
				Company:      &ident.User.Company,
			},
		})
	}

	// If there are no search results ensure that the 'data' section of the jsonapi
	// response is not null, rather [] (empty array)
	if users == nil {
		users = []*app.UserData{}
	}
	response := app.UserList{
		Data:  users,
		Links: &app.PagingLinks{},
		Meta:  &app.UserListMeta{TotalCount: count},
	}
	setPagingLinks(response.Links, buildAbsoluteURL(ctx.RequestData), len(result), offset, limit, count, "q="+q)

	return ctx.OK(&response)

}
1200386
func (c *collectorImpl) GetUserRecords() map[string]*collector.UserRecord {
	c.Lock()
	defer c.Unlock()

	if len(c.Users) == 0 {
		return nil
	}

	retval := c.Users
	c.Users = map[string]*collector.UserRecord{}
	return retval
}
346647
func Users(ids []uint64) []*User {
	var users []*User
	for _, elem := range ids {
		user, _ := NewUser(elem)
		users = append(users, user)
	}
	return users
}
765157
func (c *Client) ListUserIDs(opts ...interface{}) (res ListUserIDsRes, err error) {
	opts = opt.InsertExtraURLParam(opts, "page", iopt.ExtractPage(opts...).Get())
	opts = opt.InsertExtraURLParam(opts, "hitsPerPage", iopt.ExtractHitsPerPage(opts...).Get())
	err = c.transport.Request(&res, http.MethodGet, "/1/clusters/mapping", nil, call.Read, opts...)
	return
}
104468
func (ListUsers) Each(resp interface{}, callback IterateItemFunc) {
	items, ok := resp.(*ListUsersResponse)
	if !ok {
		callback(nil, fmt.Errorf("wrong type, ListUsersResponse was expected, got %T", resp))
		return
	}

	for i := range items.User {
		if !callback(&items.User[i], nil) {
			break
		}
	}
}
434247
func (d *DismissalRestrictionsRequest) GetUsers() []string {
	if d == nil || d.Users == nil {
		return nil
	}
	return *d.Users
}
1265563
func (a *ActionDefinition) UserTypes() map[string]*UserTypeDefinition {
	types := make(map[string]*UserTypeDefinition)
	allp := a.AllParams().Type.ToObject()
	if a.Payload != nil {
		allp["__payload__"] = &AttributeDefinition{Type: a.Payload}
	}
	for n, ut := range UserTypes(allp) {
		types[n] = ut
	}
	for _, r := range a.Responses {
		if mt := Design.MediaTypeWithIdentifier(r.MediaType); mt != nil {
			types[mt.TypeName] = mt.UserTypeDefinition
			for n, ut := range UserTypes(mt.UserTypeDefinition) {
				types[n] = ut
			}
		}
	}
	if len(types) == 0 {
		return nil
	}
	return types
}
534705
func (c *Conn) ListUsers() ([]User, error) {
	out := [][]interface{}{}
	if err := c.object.Call(dbusInterface+".ListUsers", 0).Store(&out); err != nil {
		return nil, err
	}

	ret := []User{}
	for _, el := range out {
		user, err := userFromInterfaces(el)
		if err != nil {
			return nil, err
		}
		ret = append(ret, *user)
	}
	return ret, nil
}
1228354
func (db *CLevelDB) Iterator(start, end []byte) Iterator {
	itr := db.db.NewIterator(db.ro)
	return newCLevelDBIterator(itr, start, end, false)
}
920639
func (s *UsersStore) All(ctx context.Context) ([]chronograf.User, error) {
	var users []chronograf.User
	if err := s.client.db.View(func(tx *bolt.Tx) error {
		return tx.Bucket(UsersBucket).ForEach(func(k, v []byte) error {
			var user chronograf.User
			if err := internal.UnmarshalUser(v, &user); err != nil {
				return err
			}
			users = append(users, user)
			return nil
		})
	}); err != nil {
		return nil, err
	}

	return users, nil
}
196329
func (g *Generator) generateUserTypes() (err error) {
	var (
		utFile string
		utWr   *UserTypesWriter
	)
	{
		utFile = filepath.Join(g.OutDir, "user_types.go")
		utWr, err = NewUserTypesWriter(utFile)
		if err != nil {
			return
		}
	}
	defer func() {
		utWr.Close()
		if err == nil {
			err = utWr.FormatCode()
		}
	}()
	title := fmt.Sprintf("%s: Application User Types", g.API.Context())
	imports := []*codegen.ImportSpec{
		codegen.SimpleImport("fmt"),
		codegen.SimpleImport("mime/multipart"),
		codegen.SimpleImport("time"),
		codegen.SimpleImport("unicode/utf8"),
		codegen.SimpleImport("github.com/goadesign/goa"),
		codegen.NewImport("uuid", "github.com/gofrs/uuid"),
	}
	for _, v := range g.API.Types {
		imports = codegen.AttributeImports(v.AttributeDefinition, imports, nil)
	}
	if err = utWr.WriteHeader(title, g.Target, imports); err != nil {
		return err
	}
	g.genfiles = append(g.genfiles, utFile)
	err = g.API.IterateUserTypes(func(t *design.UserTypeDefinition) error {
		return utWr.Execute(t)
	})
	return
}
1235028
func (a *APIDefinition) IterateResources(it ResourceIterator) error {
	res := make([]*ResourceDefinition, len(a.Resources))
	i := 0
	for _, r := range a.Resources {
		res[i] = r
		i++
	}
	// Iterate parent resources first so that action parameters are
	// finalized prior to child actions needing them.
	isParent := func(p, c *ResourceDefinition) bool {
		par := c.Parent()
		for par != nil {
			if par == p {
				return true
			}
			par = par.Parent()
		}
		return false
	}
	sort.Slice(res, func(i, j int) bool {
		if isParent(res[i], res[j]) {
			return true
		}
		if isParent(res[j], res[i]) {
			return false
		}
		return res[i].Name < res[j].Name
	})
	for _, r := range res {
		if err := it(r); err != nil {
			return err
		}
	}
	return nil
}