// Update `userLog` with the membership in roleUpdates.
// The `NONE` list removes users.
// The other lists add users.
554222
func (t *teamSigchainPlayer) updateMembership(stateToUpdate *TeamSigChainState, roleUpdates chainRoleUpdates, sigMeta keybase1.SignatureMetadata) {
	for role, uvs := range roleUpdates {
		for _, uv := range uvs {
			stateToUpdate.inform(uv, role, sigMeta)
		}
	}
}
847847
func (a *accounter) Update() {
	c := atomic.LoadInt64(&a.current)
	if c != a.currentValue {
		a.write(c)
		a.currentValue = c
	}
}
28738
func (mg *MailgunImpl) UpdateMember(ctx context.Context, s, l string, prototype Member) (Member, error) {
	r := newHTTPRequest(generateMemberApiUrl(mg, listsEndpoint, l) + "/" + s)
	r.setClient(mg.Client())
	r.setBasicAuth(basicAuthUser, mg.APIKey())
	p := newFormDataPayload()
	if prototype.Address != "" {
		p.addValue("address", prototype.Address)
	}
	if prototype.Name != "" {
		p.addValue("name", prototype.Name)
	}
	if prototype.Vars != nil {
		vs, err := json.Marshal(prototype.Vars)
		if err != nil {
			return Member{}, err
		}
		p.addValue("vars", string(vs))
	}
	if prototype.Subscribed != nil {
		p.addValue("subscribed", yesNo(*prototype.Subscribed))
	}
	response, err := makePutRequest(ctx, r, p)
	if err != nil {
		return Member{}, err
	}
	var envelope struct {
		Member Member `json:"member"`
	}
	err = response.parseFromJSON(&envelope)
	return envelope.Member, err
}
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
}
849209
func (s *RoleService) UpdateRole(p *UpdateRoleParams) (*UpdateRoleResponse, error) {
	resp, err := s.cs.newRequest("updateRole", p.toURLValues())
	if err != nil {
		return nil, err
	}

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

	return &r, nil
}
164842
func (r *Client) UpdateOrgUser(user UserRole, oid, uid uint) (StatusMessage, error) {
	var (
		raw   []byte
		reply StatusMessage
		err   error
	)
	if raw, err = json.Marshal(user); err != nil {
		return StatusMessage{}, err
	}
	if raw, _, err = r.patch(fmt.Sprintf("api/orgs/%d/users/%d", oid, uid), nil, raw); err != nil {
		return StatusMessage{}, err
	}
	err = json.Unmarshal(raw, &reply)
	return reply, err
}
313138
func (client *Client) UpdateOrganizationManagerByUsername(guid string, username string) (Warnings, error) {
	requestBody := updateOrgManagerByUsernameRequestBody{
		Username: username,
	}

	body, err := json.Marshal(requestBody)
	if err != nil {
		return nil, err
	}

	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.PutOrganizationManagerByUsernameRequest,
		Body:        bytes.NewReader(body),
		URIParams:   Params{"organization_guid": guid},
	})
	if err != nil {
		return nil, err
	}

	response := cloudcontroller.Response{}
	err = client.connection.Make(request, &response)

	return response.Warnings, err
}
695605
func (r *SdkRoleManager) Update(
	ctx context.Context,
	req *api.SdkRoleUpdateRequest,
) (*api.SdkRoleUpdateResponse, error) {
	if req.GetRole() == nil {
		return nil, status.Error(codes.InvalidArgument, "Must supply a role")
	}
	if err := r.validateRole(req.GetRole()); err != nil {
		return nil, err
	}

	// Determine if there is collision with default roles
	if _, ok := defaultRoles[req.GetRole().GetName()]; ok {
		return nil, status.Errorf(
			codes.InvalidArgument,
			"System role %s cannot be updated", req.GetRole().GetName())
	}

	_, err := r.kv.Update(prefixWithName(req.GetRole().GetName()), req.GetRole(), 0)
	if err == kvdb.ErrNotFound {
		return nil, status.Errorf(codes.NotFound, "Role %s not found", req.GetRole())
	} else if err != nil {
		return nil, status.Errorf(codes.Internal, "Failed to get role %s information: %v", req.GetRole().GetName(), err)
	}

	return &api.SdkRoleUpdateResponse{
		Role: req.GetRole(),
	}, nil
}
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
}
710199
func (u *user) Update(ctx context.Context, options UserOptions) error {
	req, err := u.conn.NewRequest("PATCH", u.relPath())
	if err != nil {
		return WithStack(err)
	}
	if _, err := req.SetBody(options); err != nil {
		return WithStack(err)
	}
	resp, err := u.conn.Do(ctx, req)
	if err != nil {
		return WithStack(err)
	}
	if err := resp.CheckStatus(200); err != nil {
		return WithStack(err)
	}
	var data userData
	if err := resp.ParseBody("", &data); err != nil {
		return WithStack(err)
	}
	u.data = data
	return nil
}
228295
func (c *UserServiceController) Update(ctx *app.UpdateUserServiceContext) error {
	c.UpdateTenant(ctx)
	return ctx.OK([]byte{})
}
504667
func (b *BigIP) UpdatePoolMembers(pool string, pm *[]PoolMember) error {
	config := &poolMembers{
		Members: *pm,
	}
	return b.put(config, uriLtm, uriPool, pool)
}
494061
func (s *UserService) UpdateUser(ctx context.Context, id influxdb.ID, upd influxdb.UserUpdate) (*influxdb.User, error) {
	if err := authorizeWriteUser(ctx, id); err != nil {
		return nil, err
	}

	return s.s.UpdateUser(ctx, id, upd)
}
950889
func (u *modelUserEntity) UpdateLastLogin() error {
	var err error

	if !permission.IsEmptyUserAccess(u.modelUser) {
		if u.modelUser.Object.Kind() != names.ModelTagKind {
			return errors.NotValidf("%s as model user", u.modelUser.Object.Kind())
		}

		model, err := u.st.Model()
		if err != nil {
			return errors.Trace(err)
		}

		err = model.UpdateLastModelConnection(u.modelUser.UserTag)
	}

	if u.user != nil {
		err1 := u.user.UpdateLastLogin()
		if err == nil {
			return err1
		}
	}
	if err != nil {
		return errors.Trace(err)
	}
	return nil
}
332391
func (s *RolesStore) Update(ctx context.Context, u *chronograf.Role) error {
	return s.UpdateF(ctx, u)
}
599646
func (c *IterationController) Update(ctx *app.UpdateIterationContext) error {
	currentUser, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	id, err := uuid.FromString(ctx.IterationID)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
	}

	var itr *iteration.Iteration
	var sp *space.Space
	err = application.Transactional(c.db, func(appl application.Application) error {
		itr, err = appl.Iterations().Load(ctx.Context, id)
		if err != nil {
			return err
		}
		sp, err = appl.Spaces().Load(ctx, itr.SpaceID)
		return err
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	authorized, spaceOwner, err := verifyUser(ctx, *currentUser, sp)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error()))
	}
	if !authorized && !spaceOwner {
		log.Error(ctx, map[string]interface{}{
			"space_id":     sp.ID,
			"space_owner":  sp.OwnerID,
			"current_user": *currentUser,
		}, "user is not the space owner")
		if !authorized {
			// unauthorized
			return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError("user is not allowed to create an iteration in this space"))
		}
		// forbidden:
		// Ideally we never hit following error
		// But written following line to make it verbose 401 vs 403
		return jsonapi.JSONErrorResponse(ctx, errors.NewForbiddenError("user is not allowed to create an iteration in this space"))
	}
	var iterations []iteration.Iteration
	var wiCounts map[string]workitem.WICountsPerIteration
	err = application.Transactional(c.db, func(appl application.Application) error {
		if ctx.Payload.Data.Attributes.Name != nil {
			itr.Name = *ctx.Payload.Data.Attributes.Name
		}
		if ctx.Payload.Data.Attributes.StartAt != nil {
			if ctx.Payload.Data.Attributes.StartAt.IsZero() {
				itr.StartAt = nil
			} else {
				itr.StartAt = ctx.Payload.Data.Attributes.StartAt
			}
		}
		if ctx.Payload.Data.Attributes.EndAt != nil {
			if ctx.Payload.Data.Attributes.EndAt.IsZero() {
				itr.EndAt = nil
			} else {
				itr.EndAt = ctx.Payload.Data.Attributes.EndAt
			}
		}
		if ctx.Payload.Data.Attributes.Description != nil {
			itr.Description = ctx.Payload.Data.Attributes.Description
		}
		if ctx.Payload.Data.Attributes.State != nil {
			if *ctx.Payload.Data.Attributes.State == iteration.StateStart.String() {
				res, err := appl.Iterations().CanStart(ctx, itr)
				if res == false && err != nil {
					return err
				}
			}
			itr.State = iteration.State(*ctx.Payload.Data.Attributes.State)
		}
		if ctx.Payload.Data.Attributes.UserActive != nil {
			itr.UserActive = *ctx.Payload.Data.Attributes.UserActive
		}
		var oldSubtree []iteration.Iteration
		if ctx.Payload.Data.Relationships != nil && ctx.Payload.Data.Relationships.Parent != nil {
			// update parent of Iteration
			// do not allow root-iteraiton to update its parent
			if itr.IsRoot(itr.SpaceID) {
				return errors.NewForbiddenError("Parent of root iteration can not be updated")
			}
			newParentID := ctx.Payload.Data.Relationships.Parent.Data.ID
			if newParentID == nil {
				return errors.NewBadParameterError("Data.Relationships.Parent.ID", newParentID).Expected("not nil")
			}
			pid, err := uuid.FromString(*newParentID)
			if err != nil {
				return errors.NewBadParameterError("Data.Relationships.Parent.ID", newParentID)
			}
			// Iteration itself can not be parent of self
			if pid == itr.ID {
				return errors.NewForbiddenError("Parent must be different than subject iteration")
			}
			newParentIteration, err := appl.Iterations().Load(ctx.Context, pid)
			if err != nil {
				return err
			}
			// New parent iteraiton must be from same sapce as that of subject iteration
			if newParentIteration.SpaceID != itr.SpaceID {
				return errors.NewForbiddenError("Parent must be from same space")
			}
			// we need subtree to update later
			oldSubtree, err = appl.Iterations().LoadChildren(ctx, itr.ID)
			if err != nil {
				return err
			}
			// New parent must not be one of existing children of subject iteration
			for _, childItr := range oldSubtree {
				if newParentIteration.ID == childItr.ID {
					return errors.NewForbiddenError("Parent must not be existing child")
				}
			}
			itr.MakeChildOf(*newParentIteration)
		}
		itr, err = appl.Iterations().Save(ctx.Context, *itr)
		if err != nil {
			return err
		}
		if ctx.Payload.Data.Relationships != nil && ctx.Payload.Data.Relationships.Parent != nil {
			// update all child iterations's parent as well
			for _, x := range oldSubtree {
				x.MakeChildOf(*itr)
				_, err = appl.Iterations().Save(ctx.Context, x)
				if err != nil {
					log.Error(ctx, map[string]interface{}{
						"iteration_id": x.ID,
						"err":          err.Error(),
					}, "unable to update child iteration from subtree")
					return err
				}
			}
		}
		wiCounts, err = appl.WorkItems().GetCountsForIteration(ctx, itr)
		if err != nil {
			return err
		}
		allParentsUUIDs := itr.Path
		iterations, err = appl.Iterations().LoadMultiple(ctx, allParentsUUIDs)
		return err
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	itrMap := make(iterationIDMap)
	for _, itr := range iterations {
		itrMap[itr.ID] = itr
	}
	responseData := ConvertIteration(ctx.Request, *itr, parentPathResolver(itrMap), updateIterationsWithCounts(wiCounts))
	return ctx.OK(&app.IterationSingle{
		Data: responseData,
	})
}
484634
func (m *Manager) UpdateMembership(globalid string, username string, oldrole string, newrole string) error {
	qry := bson.M{"globalid": globalid}
	pull := bson.M{
		"$pull": bson.M{oldrole: username},
	}
	push := bson.M{
		"$addToSet": bson.M{newrole: username},
	}
	err := m.collection.Update(qry, pull)
	if err != nil {
		return err
	}
	return m.collection.Update(qry, push)
}