remove general folder in legacy api

This commit is contained in:
Ryan McKinley
2025-12-02 14:48:02 +03:00
parent 3cb29d02ad
commit b1ff3eb2f1
3 changed files with 21 additions and 16 deletions
+13 -12
View File
@@ -44,12 +44,12 @@ func validateOnCreate(ctx context.Context, f *folders.Folder, getter parentsGett
return dashboards.ErrFolderTitleEmpty return dashboards.ErrFolderTitleEmpty
} }
parentName := meta.GetFolder() switch meta.GetFolder() {
if parentName == "" { case "", folder.GeneralFolderUID:
return nil // OK, we do not need to validate the tree return nil // OK, we do not need to validate the tree
} case folder.SharedWithMeFolderUID:
return fmt.Errorf("can not save shared with me")
if parentName == f.Name { case f.Name:
return folder.ErrFolderCannotBeParentOfItself return folder.ErrFolderCannotBeParentOfItself
} }
@@ -94,14 +94,15 @@ func validateOnUpdate(ctx context.Context,
// Validate the move operation // Validate the move operation
newParent := folderObj.GetFolder() newParent := folderObj.GetFolder()
// If we move to root, we don't need to validate the depth. switch newParent {
if newParent == folder.RootFolderUID { case "", folder.GeneralFolderUID:
return nil return nil // OK, we do not need to validate the tree
} case folder.SharedWithMeFolderUID:
return fmt.Errorf("can not save shared with me")
// folder cannot be moved to a k6 folder case accesscontrol.K6FolderUID:
if newParent == accesscontrol.K6FolderUID {
return fmt.Errorf("k6 project may not be moved") return fmt.Errorf("k6 project may not be moved")
case folderObj.GetName():
return folder.ErrFolderCannotBeParentOfItself
} }
parentObj, err := getter.Get(ctx, newParent, &metav1.GetOptions{}) parentObj, err := getter.Get(ctx, newParent, &metav1.GetOptions{})
+4
View File
@@ -1283,6 +1283,10 @@ func (s *Service) buildSaveDashboardCommand(ctx context.Context, dto *dashboards
return nil, dashboards.ErrDashboardFolderNameExists return nil, dashboards.ErrDashboardFolderNameExists
} }
if dash.FolderUID == folder.GeneralFolderUID {
dash.FolderUID = "" // general is the same as root
}
if dash.FolderUID != "" { if dash.FolderUID != "" {
if _, err := s.dashboardFolderStore.GetFolderByUID(ctx, dash.OrgID, dash.FolderUID); err != nil { if _, err := s.dashboardFolderStore.GetFolderByUID(ctx, dash.OrgID, dash.FolderUID); err != nil {
return nil, err return nil, err
+4 -4
View File
@@ -534,12 +534,12 @@ func (h *provisioningTestHelper) validateManagedDashboardsFolderMetadata(t *test
sourcePath, _, _ := unstructured.NestedString(d.Object, "metadata", "annotations", "grafana.app/sourcePath") sourcePath, _, _ := unstructured.NestedString(d.Object, "metadata", "annotations", "grafana.app/sourcePath")
isNested := strings.Contains(sourcePath, "/") isNested := strings.Contains(sourcePath, "/")
folder, found, _ := unstructured.NestedString(d.Object, "metadata", "annotations", "grafana.app/folder") folderName, found, _ := unstructured.NestedString(d.Object, "metadata", "annotations", "grafana.app/folder")
require.True(t, found, "dashboard will always have a folder annotation")
if isNested { if isNested {
require.True(t, found, "dashboard should have a folder annotation") require.NotEmpty(t, folderName, "dashboard should be in a non-empty folder")
require.NotEmpty(t, folder, "dashboard should be in a non-empty folder")
} else { } else {
require.False(t, found, "dashboard should not have a folder annotation") require.Equal(t, folderName, "general", "non nested folder is in general")
} }
managerID, _, _ := unstructured.NestedString(d.Object, "metadata", "annotations", "grafana.app/managerId") managerID, _, _ := unstructured.NestedString(d.Object, "metadata", "annotations", "grafana.app/managerId")