[release-12.0.1] Dashboards: Fix moving to general folder (#104719)

Dashboards: Fix moving to general folder
pull/104743/head
Stephanie Hingtgen 3 months ago committed by GitHub
parent 7287b4958f
commit 18a9cd3636
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      pkg/registry/apis/dashboard/register.go
  2. 16
      pkg/tests/apis/dashboard/integration/api_validation_test.go

@ -332,7 +332,7 @@ func (b *DashboardsAPIBuilder) validateUpdate(ctx context.Context, a admission.A
}
// Validate folder existence if specified and changed
if !a.IsDryRun() && newAccessor.GetFolder() != oldAccessor.GetFolder() {
if !a.IsDryRun() && newAccessor.GetFolder() != oldAccessor.GetFolder() && newAccessor.GetFolder() != "" {
id, err := identity.GetRequester(ctx)
if err != nil {
return fmt.Errorf("error getting requester: %w", err)

@ -246,6 +246,20 @@ func runDashboardValidationTests(t *testing.T, ctx TestContext) {
_, err := createDashboard(t, adminClient, "Dashboard in Non-existent Folder", &nonExistentFolderUID, nil)
ctx.Helper.EnsureStatusError(err, http.StatusNotFound, "folders.folder.grafana.app \"non-existent-folder-uid\" not found")
})
t.Run("allow moving folder to general folder", func(t *testing.T) {
folder1 := createFolderObject(t, "folder1", "default", "")
folder1UID := folder1.GetName()
dash, err := createDashboard(t, adminClient, "Dashboard in a Folder", &folder1UID, nil)
require.NoError(t, err)
generalFolderUID := ""
_, err = updateDashboard(t, adminClient, dash, "Move dashboard into the General Folder", &generalFolderUID)
require.NoError(t, err)
err = adminClient.Resource.Delete(context.Background(), dash.GetName(), v1.DeleteOptions{})
require.NoError(t, err)
})
})
t.Run("Dashboard schema validations", func(t *testing.T) {
@ -942,7 +956,7 @@ func createDashboard(t *testing.T, client *apis.K8sResourceClient, title string,
t.Helper()
var folderUIDStr string
if folderUID != nil && *folderUID != "" {
if folderUID != nil {
folderUIDStr = *folderUID
}

Loading…
Cancel
Save