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
}
parentName := meta.GetFolder()
if parentName == "" {
switch meta.GetFolder() {
case "", folder.GeneralFolderUID:
return nil // OK, we do not need to validate the tree
}
if parentName == f.Name {
case folder.SharedWithMeFolderUID:
return fmt.Errorf("can not save shared with me")
case f.Name:
return folder.ErrFolderCannotBeParentOfItself
}
@@ -94,14 +94,15 @@ func validateOnUpdate(ctx context.Context,
// Validate the move operation
newParent := folderObj.GetFolder()
// If we move to root, we don't need to validate the depth.
if newParent == folder.RootFolderUID {
return nil
}
// folder cannot be moved to a k6 folder
if newParent == accesscontrol.K6FolderUID {
switch newParent {
case "", folder.GeneralFolderUID:
return nil // OK, we do not need to validate the tree
case folder.SharedWithMeFolderUID:
return fmt.Errorf("can not save shared with me")
case accesscontrol.K6FolderUID:
return fmt.Errorf("k6 project may not be moved")
case folderObj.GetName():
return folder.ErrFolderCannotBeParentOfItself
}
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
}
if dash.FolderUID == folder.GeneralFolderUID {
dash.FolderUID = "" // general is the same as root
}
if dash.FolderUID != "" {
if _, err := s.dashboardFolderStore.GetFolderByUID(ctx, dash.OrgID, dash.FolderUID); err != nil {
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")
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 {
require.True(t, found, "dashboard should have a folder annotation")
require.NotEmpty(t, folder, "dashboard should be in a non-empty folder")
require.NotEmpty(t, folderName, "dashboard should be in a non-empty folder")
} 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")