func (c *Client) modifyModelUser(action params.ModelAction, user, access string, modelUUIDs []string) error { var args params.ModifyModelAccessRequest if !names.IsValidUser(user) { return errors.Errorf("invalid username: %q", user) } userTag := names.NewUserTag(user) modelAccess := permission.Access(access) if err := permission.ValidateModelAccess(modelAccess); err != nil { return errors.Trace(err) } for _, model := range modelUUIDs { if !names.IsValidModel(model) { return errors.Errorf("invalid model: %q", model) } modelTag := names.NewModelTag(model) args.Changes = append(args.Changes, params.ModifyModelAccess{ UserTag: userTag.String(), Action: action, Access: params.UserAccessPermission(modelAccess), ModelTag: modelTag.String(), }) } var result params.ErrorResults err := c.facade.FacadeCall("ModifyModelAccess", args, &result) if err != nil { return errors.Trace(err) } if len(result.Results) != len(args.Changes) { return errors.Errorf("expected %d results, got %d", len(args.Changes), len(result.Results)) } for i, r := range result.Results { if r.Error != nil && r.Error.Code == params.CodeAlreadyExists { logger.Warningf("model %q is already shared with %q", modelUUIDs[i], userTag.Canonical()) result.Results[i].Error = nil } } return result.Combine() }
func (s *userManagerSuite) TestAddUser(c *gc.C) { s.assertAddUser(c, params.UserAccessPermission(""), nil) }