// Update updates existing user
506786
func (u *UserCommand) Update(client auth.ClientI) error {
	user, err := client.GetUser(u.login)
	if err != nil {
		return trace.Wrap(err)
	}
	roles := strings.Split(u.roles, ",")
	for _, role := range roles {
		if _, err := client.GetRole(role); err != nil {
			return trace.Wrap(err)
		}
	}
	user.SetRoles(roles)
	if err := client.UpsertUser(user); err != nil {
		return trace.Wrap(err)
	}
	fmt.Printf("%v has been updated with roles %v\n", user.GetName(), strings.Join(user.GetRoles(), ","))
	return nil
}
1223059
func (a *API) UpdateUser(user *User) (*User, error) {
	dst := new(User)
	url := a.BuildURL("/v2/user/%d", user.Id)
	err := a.Put(url, Params{}, user, dst)
	return dst, err
}
455666
func (api OrganizationsAPI) UpdateUserGrant(w http.ResponseWriter, r *http.Request) {
	globalid := mux.Vars(r)["globalid"]

	body := struct {
		Username string       `json:"username"`
		OldGrant grants.Grant `json:"oldgrant"`
		NewGrant grants.Grant `json:"newgrant"`
	}{}
	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.OldGrant.Validate(); err != nil {
		log.Debug("Invalid grant: ", err)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	if err := body.NewGrant.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 update grant for user without authorization")
		w.WriteHeader(http.StatusForbidden)
		w.Write([]byte("User does not have an authorization for this organzation"))
		return
	}

	grantMgr := grants.NewManager(r)
	savedGrants, err := grantMgr.GetGrantsForUser(userObj.Username, globalid)
	if err != nil && !db.IsNotFound(err) {
		log.Error("Failed to get user grants: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	if db.IsNotFound(err) {
		log.Debug("Can't update grants if user doesn't have any")
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}
	found := false
	for _, grant := range savedGrants.Grants {
		if grant == body.OldGrant {
			found = true
			break
		}
	}

	if !found {
		log.Debug("Can't update grant if user doesn't have it")
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}

	err = grantMgr.UpdateGrant(userObj.Username, globalid, body.OldGrant, body.NewGrant)
	if err != nil {
		log.Error("Failed to update user grant: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	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.StatusOK)
	json.NewEncoder(w).Encode(grantObj.Grants)
}
980915
func (u *UserResource) updateUser(request *restful.Request, response *restful.Response) {
	usr := new(User)
	err := request.ReadEntity(&usr)
	if err == nil {
		u.users[usr.Id] = *usr
		response.WriteEntity(usr)
	} else {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
	}
}
141133
func (c *QueryController) Update(ctx *app.UpdateQueryContext) error {
	currentUser, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	if ctx.Payload.Data.Attributes.Version == nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data.attributes.version", nil).Expected("not nil"))
	}
	var q *query.Query
	err = application.Transactional(c.db, func(appl application.Application) error {
		var err error
		q, err = appl.Queries().Load(ctx.Context, ctx.QueryID, ctx.SpaceID)
		if err != nil {
			return errs.WithStack(err)
		}
		if q.Creator != *currentUser {
			log.Warn(ctx, map[string]interface{}{
				"query_id":     ctx.QueryID,
				"creator":      q.Creator,
				"current_user": *currentUser,
			}, "user is not the query creator")
			return errors.NewForbiddenError("user is not the query creator")
		}
		if q.Version != *ctx.Payload.Data.Attributes.Version {
			return errors.NewVersionConflictError("version conflict")
		}
		if ctx.Payload.Data.Attributes.Title != "" {
			q.Title = strings.TrimSpace(ctx.Payload.Data.Attributes.Title)
		}
		if strings.TrimSpace(ctx.Payload.Data.Attributes.Fields) != "" {
			q.Fields = strings.TrimSpace(ctx.Payload.Data.Attributes.Fields)
		}
		q, err = appl.Queries().Save(ctx, *q)
		return errs.WithStack(err)
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	result := &app.QuerySingle{
		Data: ConvertQuery(ctx.Request, *q),
	}
	ctx.ResponseData.Header().Set("Location", rest.AbsoluteURL(ctx.Request, app.QueryHref(ctx.SpaceID, result.Data.ID)))
	return ctx.OK(result)
}
810048
func (c *UsersClient) Update(ctx context.Context, id ID, updateUser *UpdateUser) (*User, error) {
	idBytes, err := id.MarshalText()
	if err != nil {
		return nil, err
	}

	p := fmt.Sprintf("/users/%s", string(idBytes))

	req, err := c.backend.NewRequest(http.MethodPatch, p, nil, updateUser)
	if err != nil {
		return nil, err
	}

	var resp User
	_, err = c.backend.Do(ctx, req, &resp, func(code int) error {
		return &Error{}
	})
	if err != nil {
		return nil, err
	}

	return &resp, nil
}
657497
func (c Client) Update(id string, params *stripe.PersonParams) (*stripe.Person, error) {
	path := stripe.FormatURLPath("/v1/accounts/%s/persons/%s",
		stripe.StringValue(params.Account), id)
	person := &stripe.Person{}
	err := c.B.Call(http.MethodPost, path, c.Key, params, person)
	return person, err
}
85816
func (org *Organization) UpdateUser(user UserChange) error {
	var (
		r userUpdateResponse
		b bytes.Buffer
	)
	err := json.NewEncoder(&b).Encode(user)
	if err != nil {
		return err
	}
	err = org.PPE.put(fmt.Sprintf("/orgs/%s/users/%s", org.PrimaryDomain, user.PrimaryEmail), &b, &r)
	if err != nil {
		return err
	}
	if r.ResultCode != 0 {
		return errors.New(r.Message)
	}
	return nil
}
974999
func (c *oAuthClients) Update(oAuthClient *oauth.OAuthClient) (result *oauth.OAuthClient, err error) {
	result = &oauth.OAuthClient{}
	err = c.client.Put().
		Resource("oauthclients").
		Name(oAuthClient.Name).
		Body(oAuthClient).
		Do().
		Into(result)
	return
}
727547
func (c *FakeOAuthAuthorizeTokens) Update(oAuthAuthorizeToken *oauth.OAuthAuthorizeToken) (result *oauth.OAuthAuthorizeToken, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewRootUpdateAction(oauthauthorizetokensResource, oAuthAuthorizeToken), &oauth.OAuthAuthorizeToken{})
	if obj == nil {
		return nil, err
	}
	return obj.(*oauth.OAuthAuthorizeToken), err
}
13297
func (c *Client) UpdateUser(user User) (updateTime time.Time, err error) {
	payload, err := json.Marshal(user)
	uri := fmt.Sprintf("/1/users/%s", user.ObjectID())
	resp, err := c.doWithBody("PUT", uri, bytes.NewReader(payload))
	log.Println("OI", string(payload))
	c.trace("UpdateUser >", uri, string(payload))
	if err != nil {
		return updateTime, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return updateTime, err
	}
	c.trace("UpdateUser < ", uri, string(body))
	updatedAt := &struct {
		Time time.Time `json:"updatedAt"`
	}{}
	err = json.Unmarshal(body, updatedAt)
	return updatedAt.Time, err
}
1333883
func (c *identities) Update(identity *user.Identity) (result *user.Identity, err error) {
	result = &user.Identity{}
	err = c.client.Put().
		Resource("identities").
		Name(identity.Name).
		Body(identity).
		Do().
		Into(result)
	return
}
1300052
func (a Account) Update() error {
	for k, v := range accounts {
		if a.ID == v.ID {
			accounts[k].Name = a.Name
			return nil
		}
	}
	return fmt.Errorf("account id=%d is not found", a.ID)
}
168331
func (c *UsersController) Update(ctx *app.UpdateUsersContext) error {
	return proxy.RouteHTTP(ctx, c.config.GetAuthShortServiceHostName())
}
629162
func (c *userIdentityMappings) Update(userIdentityMapping *user.UserIdentityMapping) (result *user.UserIdentityMapping, err error) {
	result = &user.UserIdentityMapping{}
	err = c.client.Put().
		Resource("useridentitymappings").
		Name(userIdentityMapping.Name).
		Body(userIdentityMapping).
		Do().
		Into(result)
	return
}
595090
func (s *UserService) UpdateUser(ctx context.Context, id influxdb.ID, upd influxdb.UserUpdate) (*influxdb.User, error) {
	url, err := newURL(s.Addr, userIDPath(id))
	if err != nil {
		return nil, err
	}

	octets, err := json.Marshal(upd)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("PATCH", url.String(), bytes.NewReader(octets))
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	SetToken(s.Token, req)

	hc := newClient(url.Scheme, s.InsecureSkipVerify)

	resp, err := hc.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	if err := CheckError(resp); err != nil {
		return nil, err
	}

	var res userResponse
	if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
		return nil, err
	}

	return &res.User, nil
}
577091
func (c *Client) UpdateUser(ctx context.Context, id platform.ID, upd platform.UserUpdate) (*platform.User, error) {
	var u *platform.User
	err := c.db.Update(func(tx *bolt.Tx) error {
		usr, pe := c.updateUser(ctx, tx, id, upd)
		if pe != nil {
			return &platform.Error{
				Err: pe,
				Op:  getOp(platform.OpUpdateUser),
			}
		}
		u = usr
		return nil
	})

	return u, err
}