// List collaborators for the given space ID.
504587
func (c *CollaboratorsController) List(ctx *app.ListCollaboratorsContext) error {
	err := c.checkSpaceExist(ctx, ctx.SpaceID.String())
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}

	isServiceAccount := token.IsSpecificServiceAccount(ctx, token.Notification)

	var currentIdentity *account.Identity
	if !isServiceAccount {
		currentIdentity, err = c.app.UserService().LoadContextIdentityIfNotBanned(ctx)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
	}

	cm := make(map[uuid.UUID]account.Identity) // Use map to check duplications
	var collaborators []account.Identity
	// Collect all contributors and admins of the space
	contributors, err := c.listRoles(ctx, currentIdentity, authorization.SpaceContributorRole, isServiceAccount)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	for _, c := range contributors {
		cm[c.IdentityID] = c.Identity
		collaborators = append(collaborators, c.Identity)
	}
	admins, err := c.listRoles(ctx, currentIdentity, authorization.SpaceAdminRole, isServiceAccount)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	for _, a := range admins {
		if _, found := cm[a.IdentityID]; !found { // Add admins only if they are not already added as contributors
			collaborators = append(collaborators, a.Identity)
		}
	}

	count := len(collaborators)
	offset, limit := computePagingLimits(ctx.PageOffset, ctx.PageLimit)
	pageOffset := offset
	pageLimit := offset + limit
	if offset > count {
		pageOffset = count
	}
	if offset+limit > count {
		pageLimit = count
	}
	page := collaborators[pageOffset:pageLimit]
	resultIdentities := make([]account.Identity, len(page))
	resultUsers := make([]account.User, len(page))
	for i, idn := range page {
		user, err := c.app.Users().Load(ctx, idn.UserID.UUID)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, autherrors.NewInternalError(ctx, err))
		}
		idn.User = *user
		resultUsers[i] = idn.User
		resultIdentities[i] = idn
	}
	log.Debug(ctx, map[string]interface{}{"offset": offset, "limit": limit, "page_offset": pageOffset, "page_limit": pageLimit, "count": len(resultIdentities), "resource_id": ctx.SpaceID.String()}, "listed collaborators for resource")

	return ctx.ConditionalEntities(resultUsers, c.config.GetCacheControlCollaborators, func() error {
		data := make([]*app.UserData, len(page))
		for i := range resultUsers {
			appUser := ConvertToAppUser(ctx.RequestData, &resultUsers[i], &resultIdentities[i], isServiceAccount)
			data[i] = appUser.Data
		}
		response := app.UserList{
			Links: &app.PagingLinks{},
			Meta:  &app.UserListMeta{TotalCount: count},
			Data:  data,
		}
		setPagingLinks(response.Links, buildAbsoluteURL(ctx.RequestData), len(page), offset, limit, count)
		return ctx.OK(&response)
	})
}
765127
func (a *Account) AppCollaborators(appID string) ([]Collaborator, error) {
	collaborators := make([]Collaborator, 0)
	err := a.get(a.auth.WithScope(scope.App(appID)), fmt.Sprintf("/api/v2/applications/%s/collaborators", appID), &collaborators)
	if err != nil {
		return nil, err
	}

	return collaborators, nil
}
694284
func (s endpointsNamespaceLister) List(selector labels.Selector) (ret []*v1.Endpoints, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1.Endpoints))
	})
	return ret, err
}
399080
func (c *CollaboratorsController) Add(ctx *app.AddCollaboratorsContext) error {
	currentIdentity, err := c.app.UserService().LoadContextIdentityIfNotBanned(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}

	identityIDs := []*app.UpdateUserID{{ID: ctx.IdentityID}}
	// Assign contributor role to the collaborator
	err = c.addContributors(ctx, currentIdentity.ID, identityIDs, ctx.SpaceID.String())
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err":      err,
			"space_id": ctx.SpaceID,
		}, "unable to add contributors to space resource: resource not found; that's OK for old spaces")
		return jsonapi.JSONErrorResponse(ctx, err)
	}

	return ctx.OK([]byte{})
}
246911
func (t *TeamsClient) List(ctx context.Context, orgID *identity.ID, name string, teamType primitive.TeamType) ([]envelope.Team, error) {
	v := &url.Values{}

	if orgID != nil {
		v.Set("org_id", orgID.String())
	}
	if name != "" {
		v.Set("name", name)
	}
	if teamType != primitive.AnyTeamType {
		v.Set("type", string(teamType))
	}

	var teams []envelope.Team
	err := t.client.RoundTrip(ctx, "GET", "/teams", v, nil, &teams)
	return teams, err
}
292261
func (s podNamespaceLister) List(selector labels.Selector) (ret []*v1.Pod, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1.Pod))
	})
	return ret, err
}
900749
func (api *API) ListSpaces() ([]params.Space, error) {
	var response params.ListSpacesResults
	err := api.facade.FacadeCall("ListSpaces", nil, &response)
	if params.IsCodeNotSupported(err) {
		return response.Results, errors.NewNotSupported(nil, err.Error())
	}
	return response.Results, err
}
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)
}
715692
func (c *Client) CollaboratorInfo(appIdentity string, collaboratorIdentity string) (*Collaborator, error) {
	var collaborator Collaborator
	return &collaborator, c.Get(&collaborator, "/apps/"+appIdentity+"/collaborators/"+collaboratorIdentity)
}
1362872
func (s serviceNamespaceLister) List(selector labels.Selector) (ret []*v1.Service, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1.Service))
	})
	return ret, err
}
679142
func (s serviceAccountNamespaceLister) List(selector labels.Selector) (ret []*v1.ServiceAccount, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1.ServiceAccount))
	})
	return ret, err
}
750443
func (env *maasEnviron) subnetToSpaceIds(ctx context.ProviderCallContext) (map[string]network.Id, error) {
	subnetsMap := make(map[string]network.Id)
	spaces, err := env.Spaces(ctx)
	if err != nil {
		return subnetsMap, errors.Trace(err)
	}
	for _, space := range spaces {
		for _, subnet := range space.Subnets {
			subnetsMap[subnet.CIDR] = space.ProviderId
		}
	}
	return subnetsMap, nil
}
780752
func (s appProjectNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.AppProject, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1alpha1.AppProject))
	})
	return ret, err
}
1241287
func (s persistentVolumeClaimNamespaceLister) List(selector labels.Selector) (ret []*v1.PersistentVolumeClaim, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1.PersistentVolumeClaim))
	})
	return ret, err
}
518397
func (m *Helper) List(namespace, apiVersion string, selector labels.Selector) (runtime.Object, error) {
	return m.RESTClient.Get().
		NamespaceIfScoped(namespace, m.NamespaceScoped).
		Resource(m.Resource).
		LabelsSelectorParam(selector).
		Do().
		Get()
}
456437
func (c *cluster) membersList(status memberStatus) []string {
	c.RLock()
	defer c.RUnlock()
	var list []string
	for _, m := range c.members {
		if m.status == status {
			list = append(list, m.endpoint)
		}
	}

	return list
}
413229
func (s podDisruptionBudgetNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.PodDisruptionBudget, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1beta1.PodDisruptionBudget))
	})
	return ret, err
}