Fix organization deletion error messages (#107380)
* Fix organization deletion error messages - Improve error message clarity when attempting to delete active organization - Fix incorrect 'Failed to update organization' message to 'Failed to delete organization' - Update comment to be more precise about the check being performed Fixes #92792 * Improve error handling in organization deletion service - Add contextual error message when dashboard deletion fails during org deletion - Include organization ID in error message for better debugging - Import fmt package for error formatting This helps administrators understand which specific organization failed during the deletion process when dashboard cleanup encounters issues. * Fix typo in unified resource access error message Change 'Namespace missmatch' to 'Namespace mismatch' for correct spelling.
This commit is contained in:
+3
-3
@@ -292,16 +292,16 @@ func (hs *HTTPServer) DeleteOrgByID(c *contextmodel.ReqContext) response.Respons
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "orgId is invalid", err)
|
||||
}
|
||||
// before deleting an org, check if user does not belong to the current org
|
||||
// before deleting an org, check if user is not active in the org
|
||||
if c.GetOrgID() == orgID {
|
||||
return response.Error(http.StatusBadRequest, "Can not delete org for current user", nil)
|
||||
return response.Error(http.StatusBadRequest, "Cannot delete your active organization. Please switch to a different organization first.", nil)
|
||||
}
|
||||
|
||||
if err := hs.orgDeletionService.Delete(c.Req.Context(), &org.DeleteOrgCommand{ID: orgID}); err != nil {
|
||||
if errors.Is(err, org.ErrOrgNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Failed to delete organization. ID not found", nil)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Failed to update organization", err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to delete organization", err)
|
||||
}
|
||||
return response.Success("Organization deleted")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package orgimpl
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
@@ -59,7 +60,7 @@ func (s *DeletionService) Delete(ctx context.Context, cmd *org.DeleteOrgCommand)
|
||||
ctx, _ = identity.WithServiceIdentity(ctx, cmd.ID)
|
||||
err = s.dashSvc.DeleteAllDashboards(ctx, cmd.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to delete dashboards for org %d: %w", cmd.ID, err)
|
||||
}
|
||||
|
||||
return s.store.Delete(ctx, cmd)
|
||||
|
||||
@@ -136,7 +136,7 @@ func (c authzLimitedClient) Check(ctx context.Context, id claims.AuthInfo, req c
|
||||
|
||||
if !claims.NamespaceMatches(id.GetNamespace(), req.Namespace) {
|
||||
span.SetAttributes(attribute.Bool("allowed", false))
|
||||
span.SetStatus(codes.Error, "Namespace missmatch")
|
||||
span.SetStatus(codes.Error, "Namespace mismatch")
|
||||
span.RecordError(claims.ErrNamespaceMissmatch)
|
||||
return claims.CheckResponse{Allowed: false}, claims.ErrNamespaceMissmatch
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func (c authzLimitedClient) Compile(ctx context.Context, id claims.AuthInfo, req
|
||||
}
|
||||
if !claims.NamespaceMatches(id.GetNamespace(), req.Namespace) {
|
||||
span.SetAttributes(attribute.Bool("allowed", false))
|
||||
span.SetStatus(codes.Error, "Namespace missmatch")
|
||||
span.SetStatus(codes.Error, "Namespace mismatch")
|
||||
span.RecordError(claims.ErrNamespaceMissmatch)
|
||||
return nil, claims.ErrNamespaceMissmatch
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user