Remove extra delete error mapping

Drop the additional RemoveUser dependency-error handling that was added\noutside this PR scope.\n\nKeep the separate remove and archive operations, but let delete failures\npropagate through existing wrapped errors without the custom helper and\nreferenced-records error type.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
Cursor Agent
2026-05-27 18:44:27 +00:00
committed by Bryan Frimin
parent 1e08a23ddc
commit affed3c781
4 changed files with 0 additions and 42 deletions

View File

@@ -157,18 +157,6 @@ func (e ErrUserManagedBySCIM) Error() string {
return fmt.Sprintf("user %q is managed by SCIM and cannot be deleted manually", e.ProfileID)
}
type ErrUserReferencedByRecords struct {
ProfileID gid.GID
}
func NewUserReferencedByRecordsError(profileID gid.GID) error {
return &ErrUserReferencedByRecords{ProfileID: profileID}
}
func (e ErrUserReferencedByRecords) Error() string {
return "cannot remove user because they are referenced by existing records (for example signatures, tasks, assets, or risks)"
}
type ErrLastActiveOwner struct {
MembershipID gid.GID
}

View File

@@ -21,7 +21,6 @@ import (
"io"
"time"
"github.com/jackc/pgx/v5/pgconn"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
"go.probo.inc/probo/packages/emails"
@@ -351,18 +350,10 @@ func (s *OrganizationService) RemoveUser(
}
if err := profile.Delete(ctx, tx, scope, profileID); err != nil {
if isUserRemovalDependencyError(err) {
return NewUserReferencedByRecordsError(profileID)
}
return fmt.Errorf("cannot delete profile: %w", err)
}
if err := membership.Delete(ctx, tx, scope, membership.ID); err != nil {
if isUserRemovalDependencyError(err) {
return NewUserReferencedByRecordsError(profileID)
}
return fmt.Errorf("cannot delete membership: %w", err)
}
@@ -442,19 +433,6 @@ func (s *OrganizationService) ArchiveUser(
)
}
func isUserRemovalDependencyError(err error) bool {
if errors.Is(err, coredata.ErrResourceInUse) {
return true
}
pgErr, ok := errors.AsType[*pgconn.PgError](err)
if !ok {
return false
}
return pgErr.Code == "23503"
}
func (s *OrganizationService) InviteUser(
ctx context.Context,
req *CreateInvitationRequest,

View File

@@ -144,10 +144,6 @@ func (r *mutationResolver) RemoveUser(ctx context.Context, input types.RemoveUse
return nil, gqlutils.Conflictf(ctx, "cannot remove last active owner")
}
if _, ok := errors.AsType[*iam.ErrUserReferencedByRecords](err); ok {
return nil, gqlutils.Conflictf(ctx, "cannot remove user because they are referenced by existing records (for example signatures, tasks, assets, or risks)")
}
r.logger.ErrorCtx(ctx, "cannot remove user from organization", log.Error(err))
return nil, gqlutils.Internal(ctx)

View File

@@ -2930,10 +2930,6 @@ func (r *Resolver) RemoveUserTool(ctx context.Context, req *mcp.CallToolRequest,
return nil, types.RemoveUserOutput{}, fmt.Errorf("cannot remove last active owner: %w", err)
}
if _, ok := errors.AsType[*iam.ErrUserReferencedByRecords](err); ok {
return nil, types.RemoveUserOutput{}, fmt.Errorf("cannot remove user because they are referenced by existing records: %w", err)
}
return nil, types.RemoveUserOutput{}, fmt.Errorf("remove user: %w", err)
}