//FindOrganizationByID calls FindOrganizationByIDF.
329482
func (s *OrganizationService) FindOrganizationByID(ctx context.Context, id platform.ID) (*platform.Organization, error) {
	return s.FindOrganizationByIDF(ctx, id)
}
1136598
func (api OrganizationsAPI) GetOrganization(w http.ResponseWriter, r *http.Request) {
	globalid := mux.Vars(r)["globalid"]
	orgMgr := organization.NewManager(r)

	org, err := orgMgr.GetByName(globalid)
	if err != nil {
		if err == mgo.ErrNotFound {
			http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		} else {
			handleServerError(w, "getting organization", err)
		}
		return
	}

	// replace owners and members usernames
	orgView, err := org.ConvertToView(user.NewManager(r), validationdb.NewManager(r))
	if handleServerError(w, "converting organization to organization view", err) {
		return
	}
	json.NewEncoder(w).Encode(orgView)
}
1238983
func (s *Service) FindOrganizations(ctx context.Context, filter influxdb.OrganizationFilter, opt ...influxdb.FindOptions) ([]*influxdb.Organization, int, error) {
	if filter.ID != nil {
		o, err := s.FindOrganizationByID(ctx, *filter.ID)
		if err != nil {
			return nil, 0, &influxdb.Error{
				Err: err,
			}
		}

		return []*influxdb.Organization{o}, 1, nil
	}

	if filter.Name != nil {
		o, err := s.FindOrganizationByName(ctx, *filter.Name)
		if err != nil {
			return nil, 0, &influxdb.Error{
				Err: err,
			}
		}

		return []*influxdb.Organization{o}, 1, nil
	}

	os := []*influxdb.Organization{}
	filterFn := filterOrganizationsFn(filter)
	err := s.kv.View(ctx, func(tx Tx) error {
		return forEachOrganization(ctx, tx, func(o *influxdb.Organization) bool {
			if filterFn(o) {
				os = append(os, o)
			}
			return true
		})
	})

	if err != nil {
		return nil, 0, &influxdb.Error{
			Err: err,
		}
	}

	return os, len(os), nil
}
90532
func (s *DescribeUsersInput) SetOrganizationId(v string) *DescribeUsersInput {
	s.OrganizationId = &v
	return s
}
171593
func (s *OrganizationSummary) SetOrganizationId(v string) *OrganizationSummary {
	s.OrganizationId = &v
	return s
}
1032722
func (s *CreateAliasInput) SetOrganizationId(v string) *CreateAliasInput {
	s.OrganizationId = &v
	return s
}
1263380
func (i *DocumentIndex) FindOrganizationByName(org string) (influxdb.ID, error) {
	o, err := i.service.findOrganizationByName(i.ctx, i.tx, org)
	if err != nil {
		return influxdb.InvalidID(), err
	}
	return o.ID, nil
}
775277
func (m *Manager) GetOrganizationAuthorizations(globalId string) (authorizations []Authorization, err error) {
	qry := bson.M{"grantedto": globalId}
	err = m.getAuthorizationCollection().Find(qry).All(&authorizations)
	if authorizations == nil {
		authorizations = []Authorization{}
	}
	return
}
1083841
func (s *User) SetOrganizationId(v string) *User {
	s.OrganizationId = &v
	return s
}
1346539
func (s *OrgService) FindOrganizations(ctx context.Context, filter influxdb.OrganizationFilter, opt ...influxdb.FindOptions) ([]*influxdb.Organization, int, error) {
	// TODO: we'll likely want to push this operation into the database eventually since fetching the whole list of data
	// will likely be expensive.
	os, _, err := s.s.FindOrganizations(ctx, filter, opt...)
	if err != nil {
		return nil, 0, err
	}

	// This filters without allocating
	// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
	orgs := os[:0]
	for _, o := range os {
		err := authorizeReadOrg(ctx, o.ID)
		if err != nil && influxdb.ErrorCode(err) != influxdb.EUnauthorized {
			return nil, 0, err
		}

		if influxdb.ErrorCode(err) == influxdb.EUnauthorized {
			continue
		}

		orgs = append(orgs, o)
	}

	return orgs, len(orgs), nil
}
808536
func (s *DeleteResourceInput) SetOrganizationId(v string) *DeleteResourceInput {
	s.OrganizationId = &v
	return s
}
577865
func (s *DescribeResourceInput) SetOrganizationId(v string) *DescribeResourceInput {
	s.OrganizationId = &v
	return s
}
977424
func (c *Client) FindOrganizations(ctx context.Context, filter influxdb.OrganizationFilter, opt ...influxdb.FindOptions) ([]*influxdb.Organization, int, error) {
	op := getOp(influxdb.OpFindOrganizations)
	if filter.ID != nil {
		o, err := c.FindOrganizationByID(ctx, *filter.ID)
		if err != nil {
			return nil, 0, &influxdb.Error{
				Err: err,
				Op:  op,
			}
		}

		return []*influxdb.Organization{o}, 1, nil
	}

	if filter.Name != nil {
		o, err := c.FindOrganizationByName(ctx, *filter.Name)
		if err != nil {
			return nil, 0, &influxdb.Error{
				Err: err,
				Op:  op,
			}
		}

		return []*influxdb.Organization{o}, 1, nil
	}

	os := []*influxdb.Organization{}
	filterFn := filterOrganizationsFn(filter)
	err := c.db.View(func(tx *bolt.Tx) error {
		return forEachOrganization(ctx, tx, func(o *influxdb.Organization) bool {
			if filterFn(o) {
				os = append(os, o)
			}
			return true
		})
	})

	if err != nil {
		return nil, 0, &influxdb.Error{
			Err: err,
			Op:  op,
		}
	}

	return os, len(os), nil
}
1014832
func (s *AppsService) FindOrganizationInstallation(ctx context.Context, org string) (*Installation, *Response, error) {
	return s.getInstallation(ctx, fmt.Sprintf("orgs/%v/installation", org))
}
422859
func (s *Service) FindOrganizations(ctx context.Context, filter platform.OrganizationFilter, opt ...platform.FindOptions) ([]*platform.Organization, int, error) {
	op := OpPrefix + platform.OpFindOrganizations
	if filter.ID != nil {
		o, err := s.FindOrganizationByID(ctx, *filter.ID)
		if err != nil {
			return nil, 0, &platform.Error{
				Op:  op,
				Err: err,
			}
		}

		return []*platform.Organization{o}, 1, nil
	}

	filterFunc := func(o *platform.Organization) bool { return true }
	if filter.Name != nil {
		filterFunc = func(o *platform.Organization) bool {
			return o.Name == *filter.Name
		}
	}

	orgs, pe := s.filterOrganizations(ctx, filterFunc)
	if pe != nil {
		return nil, 0, &platform.Error{
			Err: pe,
			Op:  op,
		}
	}

	if len(orgs) == 0 {
		return orgs, 0, &platform.Error{
			Code: platform.ENotFound,
			Op:   op,
			Msg:  errOrganizationNotFound,
		}
	}

	return orgs, len(orgs), nil
}
1271663
func (s *ListResourceDelegatesInput) SetOrganizationId(v string) *ListResourceDelegatesInput {
	s.OrganizationId = &v
	return s
}
1207749
func (i *DocumentIndex) FindOrganizationByID(id influxdb.ID) error {
	_, err := i.service.findOrganizationByID(i.ctx, i.tx, id)
	if err != nil {
		return err
	}
	return nil
}