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:
committed by
Bryan Frimin
parent
1e08a23ddc
commit
affed3c781
@@ -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)
|
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 {
|
type ErrLastActiveOwner struct {
|
||||||
MembershipID gid.GID
|
MembershipID gid.GID
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5/pgconn"
|
|
||||||
"go.gearno.de/crypto/uuid"
|
"go.gearno.de/crypto/uuid"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
"go.probo.inc/probo/packages/emails"
|
"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 err := profile.Delete(ctx, tx, scope, profileID); err != nil {
|
||||||
if isUserRemovalDependencyError(err) {
|
|
||||||
return NewUserReferencedByRecordsError(profileID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("cannot delete profile: %w", err)
|
return fmt.Errorf("cannot delete profile: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := membership.Delete(ctx, tx, scope, membership.ID); err != nil {
|
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)
|
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(
|
func (s *OrganizationService) InviteUser(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *CreateInvitationRequest,
|
req *CreateInvitationRequest,
|
||||||
|
|||||||
@@ -144,10 +144,6 @@ func (r *mutationResolver) RemoveUser(ctx context.Context, input types.RemoveUse
|
|||||||
return nil, gqlutils.Conflictf(ctx, "cannot remove last active owner")
|
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))
|
r.logger.ErrorCtx(ctx, "cannot remove user from organization", log.Error(err))
|
||||||
|
|
||||||
return nil, gqlutils.Internal(ctx)
|
return nil, gqlutils.Internal(ctx)
|
||||||
|
|||||||
@@ -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)
|
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)
|
return nil, types.RemoveUserOutput{}, fmt.Errorf("remove user: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user