// ListUsersWithGrant lists all users with a given grant
766073
func (api OrganizationsAPI) ListUsersWithGrant(w http.ResponseWriter, r *http.Request) {
	globalID := mux.Vars(r)["globalid"]
	grantString := mux.Vars(r)["grant"]

	grant := grants.Grant(grantString)
	if err := grant.Validate(); err != nil {
		log.Debug("Invalid grant: ", err)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	grantMgr := grants.NewManager(r)
	grantObjs, err := grantMgr.GetByGrant(grant, globalID)
	if err != nil && !db.IsNotFound(err) {
		log.Error("Failed to look up users with grant: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	usernames := []string{}
	for _, grantObj := range grantObjs {
		usernames = append(usernames, grantObj.Username)
	}

	log.Debug("filtering users to those with an open authorization")
	usernames, err = user.NewManager(r).FilterUsersWithAuthorizations(usernames, globalID)
	if handleServerError(w, "filtering out users without authorization", err) {
		return
	}

	userIdentifiers, err := organization.ConvertUsernamesToIdentifiers(usernames, validationdb.NewManager(r))
	if err != nil {
		log.Error("Failed to convert usernames to identifiers: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	json.NewEncoder(w).Encode(userIdentifiers)
}
547063
func (c *APIClient) UsersList() ([]*User, error) {
	dest := UsersList{}
	if err := c.slackMethodAndParse("users.list", &dest); err != nil {
		return nil, err
	}

	return dest.Users, nil
}
804658
func (s *UserService) FindUsers(ctx context.Context, filter platform.UserFilter, opts ...platform.FindOptions) ([]*platform.User, int, error) {
	return s.FindUsersFn(ctx, filter, opts...)
}
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
}
1279896
func (s *UpdateUserInput) SetGrantPoweruserPrivileges(v string) *UpdateUserInput {
	s.GrantPoweruserPrivileges = &v
	return s
}
586067
func (api OrganizationsAPI) CreateUserGrant(w http.ResponseWriter, r *http.Request) {
	globalid := mux.Vars(r)["globalid"]

	body := struct {
		Username string       `json:"username"`
		Grant    grants.Grant `json:"grant"`
	}{}
	if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
		log.Debug("Error decoding create grant body:", err)
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	if err := body.Grant.Validate(); err != nil {
		log.Debug("Invalid grant: ", err)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	userObj, err := SearchUser(r, body.Username)
	if err != nil && !db.IsNotFound(err) {
		log.Error("Failed to look up user identifier: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	if err != nil {
		// We can't give a grant to a user that doesn't exist
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}

	hasAuth, err := hasAuthorization(r, userObj.Username, globalid)
	if handleServerError(w, "checking if user has an authorization for the organization", err) {
		return
	}
	if !hasAuth {
		log.Debug("Refusing to give a grant to a user without authorization")
		w.WriteHeader(http.StatusForbidden)
		w.Write([]byte("User does not have an authorization for this organzation"))
		return
	}

	grantMgr := grants.NewManager(r)
	err = grantMgr.UpserGrant(userObj.Username, globalid, body.Grant)
	if err != nil && err != grants.ErrGrantLimitReached {
		log.Error("Failed to create user grant: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	if err != nil {
		log.Debug("Max amount of grants reached")
		http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict)
	}

	grantObj, err := grantMgr.GetGrantsForUser(userObj.Username, globalid)
	if err != nil {
		log.Error("Failed to look up user grants: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusCreated)
	json.NewEncoder(w).Encode(grantObj.Grants)
}
827895
func (ls *ListUsers) ListRequest() (ListCommand, error) {
	if ls == nil {
		return nil, fmt.Errorf("%T cannot be nil", ls)
	}
	return ls, nil
}
47792
func (c *CloudPersister) ListUsers() ([]*models.User, error) {
	ctx := context.Background()
	Users := make([]*models.User, 0)
	q := datastore.NewQuery("User")

	keys, err := c.DatastoreClient().GetAll(ctx, q, &Users)

	if err != nil {
		return nil, fmt.Errorf("datastoredb: could not list Users: %v", err)
	}

	for i, k := range keys {
		Users[i].ID = k.ID()
	}

	return Users, nil
}
1209075
func List(c *client.Client, results int) (api.Users, int, error) {
	body, count, err := c.LimitedRequest("/v1/users/", results)

	if err != nil {
		return []api.User{}, -1, err
	}

	var users []api.User
	if err = json.Unmarshal([]byte(body), &users); err != nil {
		return []api.User{}, -1, err
	}

	return users, count, nil
}
140475
func (s *UserService) ListUsers(p *ListUsersParams) (*ListUsersResponse, error) {
	resp, err := s.cs.newRequest("listUsers", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ListUsersResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
137496
func (rtm *Client) UsersList() ([]User, error) {
	res := usersListResponse{}
	err := NewExternalRequest().
		AsPost().
		WithScheme(APIScheme).
		WithHost(APIEndpoint).
		WithPath("api/users.list").
		WithPostData("token", rtm.Token).
		JSON(&res)

	if err != nil {
		return nil, err
	}

	if !IsEmpty(res.Error) {
		return nil, exception.New(res.Error)
	}

	return res.Users, nil
}
1062816
func (r *usersResource) getAllUsers(request *restful.Request, response *restful.Response, user schema.User) (error, interface{}) {
	users, err := r.users.GetAll()
	return err, users
}
1247823
func (p *UserPrivileges) ShowGrants(ctx sessionctx.Context, user *auth.UserIdentity, roles []*auth.RoleIdentity) (grants []string, err error) {
	mysqlPrivilege := p.Handle.Get()
	u := user.Username
	h := user.Hostname
	if len(user.AuthUsername) > 0 && len(user.AuthHostname) > 0 {
		u = user.AuthUsername
		h = user.AuthHostname
	}
	grants = mysqlPrivilege.showGrants(u, h, roles)
	if len(grants) == 0 {
		err = errNonexistingGrant.GenWithStackByArgs(u, h)
	}

	return
}
270491
func ListAdmins(c *deis.Client, results int) ([]string, int, error) {
	body, count, reqErr := c.LimitedRequest("/v2/admin/perms/", results)

	if reqErr != nil && !deis.IsErrAPIMismatch(reqErr) {
		return []string{}, -1, reqErr
	}

	var users []api.PermsRequest
	if err := json.Unmarshal([]byte(body), &users); err != nil {
		return []string{}, -1, err
	}

	usersList := []string{}

	for _, user := range users {
		usersList = append(usersList, user.Username)
	}

	return usersList, count, reqErr
}
1229361
func (s *MigrationService) ListUserMigrations(ctx context.Context) ([]*UserMigration, *Response, error) {
	u := "user/migrations"

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

	// TODO: remove custom Accept header when this API fully launches.
	req.Header.Set("Accept", mediaTypeMigrationsPreview)

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

	return m, resp, nil
}
952081
func ToGrant(username string, perm chronograf.Permission) string {
	if len(perm.Allowed) == 0 {
		return ""
	}
	return ToInfluxQL("GRANT", "TO", username, perm)
}
1336407
func (r *KeyResource) List(account string) ([]*Key, error) {
	keys := []*Key{}
	path := fmt.Sprintf("/users/%s/ssh-keys", account)

	if err := r.client.do("GET", path, nil, nil, &keys); err != nil {
		return nil, err
	}

	return keys, nil
}