// ListOrganizations lists organizations of the logged-in user.
//
// API reference: https://api.cloudflare.com/#user-s-organizations-list-organizations
546274
func (api *API) ListOrganizations() ([]Organization, ResultInfo, error) {
	var r organizationResponse
	res, err := api.makeRequest("GET", "/user/organizations", nil)
	if err != nil {
		return []Organization{}, ResultInfo{}, errors.Wrap(err, errMakeRequestError)
	}

	err = json.Unmarshal(res, &r)
	if err != nil {
		return []Organization{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError)
	}

	return r.Result, r.ResultInfo, nil
}
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
}
1056274
func (u *User) GetOrganizations(showPrivate bool) error {
	orgIDs, err := GetOrgIDsByUserID(u.ID, showPrivate)
	if err != nil {
		return fmt.Errorf("GetOrgIDsByUserID: %v", err)
	}
	if len(orgIDs) == 0 {
		return nil
	}

	u.Orgs = make([]*User, 0, len(orgIDs))
	if err = x.Where("type = ?", USER_TYPE_ORGANIZATION).In("id", orgIDs).Find(&u.Orgs); err != nil {
		return err
	}
	return nil
}
834964
func (s *Service) OrganizationInvitationList(ctx context.Context, organizationName string, lr *ListRange) (OrganizationInvitationListResult, error) {
	var organizationInvitation OrganizationInvitationListResult
	return organizationInvitation, s.Get(ctx, &organizationInvitation, fmt.Sprintf("/organizations/%v/invitations", organizationName), nil, lr)
}
598104
func (api OrganizationsAPI) AddOrganizationOwner(w http.ResponseWriter, r *http.Request) {
	api.inviteUser(w, r, invitations.RoleOwner)
}
345979
func (c *ApiController) GetAccountOrganizations() {
	fmt.Println("Start get account organizations")

	client := github.NewClient(oauthCfg.Client(oauth2.NoContext, tkn))

	organizations, _, err := client.Organizations.List("", nil)
	if err != nil {
		fmt.Println("error getting organizations")
		fmt.Println(nil)
	}

	c.Data["json"] = organizations
	c.ServeJson()
}
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
}
982018
func (s *OrganizationsService) ListOrgMemberships(ctx context.Context, opt *ListOrgMembershipsOptions) ([]*Membership, *Response, error) {
	u := "user/memberships/orgs"
	u, err := addOptions(u, opt)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	var memberships []*Membership
	resp, err := s.client.Do(ctx, req, &memberships)
	if err != nil {
		return nil, resp, err
	}

	return memberships, resp, nil
}
1265917
func NewOrganizations(dir string, logger chronograf.Logger) chronograf.OrganizationsStore {
	return &Organizations{
		Dir:     dir,
		Load:    load,
		ReadDir: ioutil.ReadDir,
		Logger:  logger,
	}
}
325389
func (s *UsersService) LeaveOrganization(globalid, username string, headers, queryParams map[string]interface{}) (*http.Response, error) {
	var err error

	resp, err := s.client.doReqNoBody("DELETE", s.client.BaseURI+"/users/"+username+"/organizations/"+globalid+"/leave", headers, queryParams)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case 404:
		var respBody404 Error
		err = goraml.NewAPIError(resp, &respBody404)
	default:
		err = goraml.NewAPIError(resp, nil)
	}

	return resp, err
}
892076
func (c *Client) OrganizationAppListForOrganization(organizationIdentity string, lr *ListRange) ([]OrganizationApp, error) {
	req, err := c.NewRequest("GET", "/organizations/"+organizationIdentity+"/apps", nil, nil)
	if err != nil {
		return nil, err
	}

	if lr != nil {
		lr.SetHeader(req)
	}

	var organizationAppsRes []OrganizationApp
	return organizationAppsRes, c.DoReq(req, &organizationAppsRes)
}
594829
func DeleteOrganization(org *User) (err error) {
	if err := DeleteUser(org); err != nil {
		return err
	}

	sess := x.NewSession()
	defer sess.Close()
	if err = sess.Begin(); err != nil {
		return err
	}

	if err = deleteBeans(sess,
		&Team{OrgID: org.ID},
		&OrgUser{OrgID: org.ID},
		&TeamUser{OrgID: org.ID},
	); err != nil {
		return fmt.Errorf("deleteBeans: %v", err)
	}

	if err = deleteUser(sess, org); err != nil {
		return fmt.Errorf("deleteUser: %v", err)
	}

	return sess.Commit()
}
1172342
func (g *OrganizationService) YourOrganizations(uri *Hyperlink, params M) (
	organizations []Organization, result *Result) {
	if uri == nil {
		uri = &YourOrganizationsURL
	}
	url, err := uri.Expand(params)
	if err != nil {
		return nil, &Result{Err: err}
	}
	result = g.client.get(url, &organizations)
	return
}
1021643
func CountOrganizations() int64 {
	count, _ := x.Where("type=1").Count(new(User))
	return count
}
1107680
func (s *Service) OrganizationAppCollaboratorList(ctx context.Context, organizationAppIdentity string, lr *ListRange) (OrganizationAppCollaboratorListResult, error) {
	var organizationAppCollaborator OrganizationAppCollaboratorListResult
	return organizationAppCollaborator, s.Get(ctx, &organizationAppCollaborator, fmt.Sprintf("/organizations/apps/%v/collaborators", organizationAppIdentity), nil, lr)
}
1030571
func UsingOrganization(orgID string) Option {
	return func(api *API) error {
		api.OrganizationID = orgID
		return nil
	}
}
724081
func NewOrganizationService(context servicecontext.ServiceContext) service.OrganizationService {
	return &organizationServiceImpl{base.NewBaseService(context)}
}