这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/provider/resource_usergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r *UserGroupResource) ModifyPlan(ctx context.Context, req resource.ModifyP
if err != nil {
resp.Diagnostics.AddError(
"Conflict",
fmt.Sprintf("PreventConflicts = true: %v", err),
fmt.Sprintf("PreventConflicts = true:\n%v", err),
)
}
}
Expand Down
36 changes: 21 additions & 15 deletions internal/provider/usergroup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,31 @@ func (s *userGroupServiceImpl) DeleteGroup(ctx context.Context, id string) error
}

func (s *userGroupServiceImpl) CheckConflicts(ctx context.Context, resourceID, name, handle string, includeDisabled bool) error {
existingByName, errNameLookup := s.queries.FindUserGroupByField(ctx, "name", name, includeDisabled)
if errNameLookup == nil {
if existingByName.ID != resourceID {
return fmt.Errorf("conflict: existing enabled group with same name\nAn enabled user group named %q already exists (ID: %s)", existingByName.Name, existingByName.ID)
conflict := func(field, val string) error {
existing, errLookup := s.queries.FindUserGroupByField(ctx, field, val, includeDisabled)
if errLookup != nil {
if !strings.Contains(errLookup.Error(), "no usergroup with "+field) {
return fmt.Errorf("error checking %s conflict\n%s", field, errLookup.Error())
}
return nil
}
} else if !strings.Contains(errNameLookup.Error(), "no usergroup with name") {
return fmt.Errorf("error checking name conflict\n%s", errNameLookup.Error())
}

existingByHandle, errHandleLookup := s.queries.FindUserGroupByField(ctx, "handle", handle, includeDisabled)
if errHandleLookup == nil {
if existingByHandle.ID != resourceID {
return fmt.Errorf("conflict: existing enabled group with same handle\nAn enabled user group with handle %q already exists (ID: %s)", existingByHandle.Handle, existingByHandle.ID)
if existing.ID != resourceID {
return fmt.Errorf("conflict: existing usergroup with same %s\nA usergroup with %s %q already exists (ID: %s)", field, field, val, existing.ID)
}
} else if !strings.Contains(errHandleLookup.Error(), "no usergroup with handle") {
return fmt.Errorf("error checking handle conflict\n%s", errHandleLookup.Error())
return nil
}

return nil
var errs []string
if err := conflict("name", name); err != nil {
errs = append(errs, err.Error())
}
if err := conflict("handle", handle); err != nil {
errs = append(errs, err.Error())
}
if len(errs) == 0 {
return nil
}
return fmt.Errorf("%s", strings.Join(errs, "\n\n"))
}

func (s *userGroupServiceImpl) UpdateUserGroupMembership(ctx context.Context, groupID string, users []string) error {
Expand Down
Loading