// DeleteOrg deletes the organization identified by the organization id
// Reflects DELETE /api/orgs/:orgId
334752
func (r *Client) DeleteOrg(oid uint) (StatusMessage, error) {
	var (
		raw  []byte
		resp StatusMessage
		err  error
	)
	if raw, _, err = r.delete(fmt.Sprintf("api/orgs/%d", oid)); err != nil {
		return StatusMessage{}, err
	}
	if err = json.Unmarshal(raw, &resp); err != nil {
		return StatusMessage{}, err
	}
	return resp, nil
}
916853
func (s *DisassociateDelegateFromResourceInput) SetOrganizationId(v string) *DisassociateDelegateFromResourceInput {
	s.OrganizationId = &v
	return s
}
1358149
func (s *Service) DeleteOrganizationBuckets(ctx context.Context, id platform.ID) error {
	bucks, err := s.findBuckets(ctx, platform.BucketFilter{
		OrganizationID: &id,
	})
	if err != nil {
		return err
	}
	for _, buck := range bucks {
		s.bucketKV.Delete(buck.ID.String())
	}
	return nil
}
328470
func (s *OrganizationsStore) Delete(ctx context.Context, o *chronograf.Organization) error {
	if o.ID == string(DefaultOrganizationID) {
		return chronograf.ErrCannotDeleteDefaultOrganization
	}
	_, err := s.get(ctx, o.ID)
	if err != nil {
		return err
	}
	if err := s.client.db.Update(func(tx *bolt.Tx) error {
		return tx.Bucket(OrganizationsBucket).Delete([]byte(o.ID))
	}); err != nil {
		return err
	}

	// Dependent Delete of all resources

	// Each of the associated organization stores expects organization to be
	// set on the context.
	ctx = context.WithValue(ctx, organizations.ContextKey, o.ID)

	sourcesStore := organizations.NewSourcesStore(s.client.SourcesStore, o.ID)
	sources, err := sourcesStore.All(ctx)
	if err != nil {
		return err
	}
	for _, source := range sources {
		if err := sourcesStore.Delete(ctx, source); err != nil {
			return err
		}
	}

	serversStore := organizations.NewServersStore(s.client.ServersStore, o.ID)
	servers, err := serversStore.All(ctx)
	if err != nil {
		return err
	}
	for _, server := range servers {
		if err := serversStore.Delete(ctx, server); err != nil {
			return err
		}
	}

	dashboardsStore := organizations.NewDashboardsStore(s.client.DashboardsStore, o.ID)
	dashboards, err := dashboardsStore.All(ctx)
	if err != nil {
		return err
	}
	for _, dashboard := range dashboards {
		if err := dashboardsStore.Delete(ctx, dashboard); err != nil {
			return err
		}
	}

	usersStore := organizations.NewUsersStore(s.client.UsersStore, o.ID)
	users, err := usersStore.All(ctx)
	if err != nil {
		return err
	}
	for _, user := range users {
		if err := usersStore.Delete(ctx, &user); err != nil {
			return err
		}
	}

	mappings, err := s.client.MappingsStore.All(ctx)
	if err != nil {
		return err
	}
	for _, mapping := range mappings {
		if mapping.Organization == o.ID {
			if err := s.client.MappingsStore.Delete(ctx, &mapping); err != nil {
				return err
			}
		}
	}

	return nil
}
640562
func (o *Organizations) findOrg(query chronograf.OrganizationQuery) (*chronograf.Organization, string, error) {
	// Because the entire org information is not known at this point, we need
	// to try to find the name of the file through matching the ID or name in the org
	// content with the ID passed.
	files, err := o.ReadDir(o.Dir)
	if err != nil {
		return nil, "", err
	}

	for _, f := range files {
		if path.Ext(f.Name()) != OrgExt {
			continue
		}
		file := path.Join(o.Dir, f.Name())
		var org chronograf.Organization
		if err := o.Load(file, &org); err != nil {
			return nil, "", err
		}
		if query.ID != nil && org.ID == *query.ID {
			return &org, file, nil
		}
		if query.Name != nil && org.Name == *query.Name {
			return &org, file, nil
		}
	}

	return nil, "", chronograf.ErrOrganizationNotFound
}
953909
func (c *Client) OrganizationUpdate(organizationIdentity string, options *OrganizationUpdateOpts) (*Organization, error) {
	var organizationRes Organization
	return &organizationRes, c.Patch(&organizationRes, "/organizations/"+organizationIdentity, options)
}
1067532
func (ppe *PPE) Organization(domain string) (*Organization, error) {
	var o orgResource
	err := ppe.get(fmt.Sprintf("/orgs/%s", domain), &o)
	if err != nil {
		return &Organization{}, err
	}
	return orgFromOrgResource(ppe, o), nil
}
862937
func (m *Manager) AllByOrgs(globalIDs []string) ([]Organization, error) {
	var organizations []Organization

	condition := []interface{}{
		bson.M{"orgmembers": bson.M{"$in": globalIDs}},
		bson.M{"orgowners": bson.M{"$in": globalIDs}},
	}

	err := m.collection.Find(bson.M{"$or": condition}).All(&organizations)

	return organizations, err
}
1258386
func UpdateOrg(c *m.ReqContext, form dtos.UpdateOrgForm) Response {
	return updateOrgHelper(form, c.ParamsInt64(":orgId"))
}
872716
func (s *DeleteUserInput) SetOrganizationId(v string) *DeleteUserInput {
	s.OrganizationId = &v
	return s
}
1017979
func (s *Service) OrganizationMemberDelete(ctx context.Context, organizationIdentity string, organizationMemberIdentity string) (*OrganizationMember, error) {
	var organizationMember OrganizationMember
	return &organizationMember, s.Delete(ctx, &organizationMember, fmt.Sprintf("/organizations/%v/members/%v", organizationIdentity, organizationMemberIdentity))
}
626069
func DeleteWebhookOfOrgByID(orgID, id int64) error {
	return deleteWebhook(&Webhook{
		ID:    id,
		OrgID: orgID,
	})
}
268700
func (o *OrgsClient) RemoveMember(ctx context.Context, orgID identity.ID,
	userID identity.ID) error {

	path := "/orgs/" + orgID.String() + "/members/" + userID.String()
	return o.client.RoundTrip(ctx, "DELETE", path, nil, nil, nil)
}
346008
func (m *Manager) DeleteOrgGrants(globalID string) error {
	_, err := m.collection.RemoveAll(bson.M{"globalid": globalID})
	return err
}
400058
func (u HubUser) GetOrgByID(orgID string) (model.Org, error) {
	for _, org := range u.Orgs {
		if org.ID == orgID {
			return org, nil
		}
	}
	return model.Org{}, fmt.Errorf("org %s not found", orgID)
}
1044771
func (api OrganizationsAPI) actualOrganizationDeletion(r *http.Request, globalid string) error {
	orgMgr := organization.NewManager(r)
	logoMgr := organization.NewLogoManager(r)
	// If the organization does not exist then it should be completely cleaned up already.
	// Since the goal of this method is to make sure it does not exist anymore, that goal is already complete
	if !orgMgr.Exists(globalid) {
		return nil
	}
	if err := orgMgr.Remove(globalid); err != nil {
		return err
	}
	// Remove the organizations as a member/ an owner of other organizations
	organizations, err := orgMgr.AllByOrg(globalid)
	if err != nil {
		return err
	}
	for _, org := range organizations {
		if err = orgMgr.RemoveOrganization(org.Globalid, globalid); err != nil {
			return err
		}
	}
	if logoMgr.Exists(globalid) {
		if err = logoMgr.Remove(globalid); err != nil {
			return err
		}
	}
	orgReqMgr := invitations.NewInvitationManager(r)
	if err = orgReqMgr.RemoveAll(globalid); err != nil {
		return err
	}

	oauthMgr := oauthservice.NewManager(r)
	if err = oauthMgr.RemoveTokensByGlobalID(globalid); err != nil {
		return err
	}
	if err = oauthMgr.DeleteAllForOrganization(globalid); err != nil {
		return err
	}
	if err = oauthMgr.RemoveClientsByID(globalid); err != nil {
		return err
	}
	userMgr := user.NewManager(r)
	if err = userMgr.DeleteAllAuthorizations(globalid); err != nil {
		return err
	}
	if err = oauthMgr.RemoveClientsByID(globalid); err != nil {
		return err
	}
	l2faMgr := organization.NewLast2FAManager(r)
	if err = l2faMgr.RemoveByOrganization(globalid); err != nil {
		return err
	}
	descriptionMgr := organization.NewDescriptionManager(r)
	if err = descriptionMgr.Remove(globalid); err != nil {
		if !db.IsNotFound(err) {
			return err
		}
	}
	if iyoid.NewManager(r).DeleteForClient(globalid); err != nil && !db.IsNotFound(err) {
		return err
	}
	if grants.NewManager(r).DeleteOrgGrants(globalid); err != nil && !db.IsNotFound(err) {
		return err
	}
	return nil
}
135223
func CreateOrg(c *context.APIContext, form api.CreateOrgOption) {
	org.CreateOrgForUser(c, form, user.GetUserByParams(c))
}