fix(folders): check for library panels on delete (legacy) (#109848)

This commit is contained in:
Jean-Philippe Quéméner
2025-08-19 17:32:35 +02:00
committed by GitHub
parent 537ac8ec68
commit e157dbaa4f
2 changed files with 187 additions and 0 deletions
+13
View File
@@ -938,6 +938,19 @@ func (s *Service) DeleteLegacy(ctx context.Context, cmd *folder.DeleteFolderComm
if alertRulesInFolder > 0 {
return folder.ErrFolderNotEmpty.Errorf("folder contains %d alert rules", alertRulesInFolder)
}
libraryPanelSrv, ok := s.registry[entity.StandardKindLibraryPanel]
if !ok {
return folder.ErrInternal.Errorf("no library panel service found in registry")
}
libraryPanelsInFolder, err := libraryPanelSrv.CountInFolders(ctx, cmd.OrgID, folders, cmd.SignedInUser)
if err != nil {
s.log.Error("failed to count library panels in folder", "error", err)
return err
}
if libraryPanelsInFolder > 0 {
return folder.ErrFolderNotEmpty.Errorf("folder contains %d library panels", libraryPanelsInFolder)
}
}
err = s.store.Delete(ctx, []string{cmd.UID}, cmd.OrgID)