From 31fb38723d9fab836d98c3a84957fc6d37cf05dd Mon Sep 17 00:00:00 2001 From: Kat Yang <69819079+yangkb09@users.noreply.github.com> Date: Thu, 7 Dec 2023 07:56:04 -0500 Subject: [PATCH] Chore: Remove FolderID from DTO Folder (#78420) * Chore: Remove FolderID from DTO Folder * chore: add OrgID field to an instance of SaveDashboardCommand * chore: add another OrgID to pair with the FolderUID: * chore: add OrgId to Folder struct and expectedParentOrgIDs to testCase struct, unsure if last part is necessary * Fix folder test, add expected orgID * chore: regen specs --------- Co-authored-by: Ida Furjesova --- pkg/api/dtos/folder.go | 3 ++- pkg/api/folder_test.go | 9 +++++---- pkg/tests/api/dashboards/api_dashboards_test.go | 4 +++- public/api-merged.json | 4 ++++ public/openapi3.json | 4 ++++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pkg/api/dtos/folder.go b/pkg/api/dtos/folder.go index aa94dac52b2..5830187ce78 100644 --- a/pkg/api/dtos/folder.go +++ b/pkg/api/dtos/folder.go @@ -10,8 +10,9 @@ type Folder struct { // Deprecated: use UID instead ID int64 `json:"id" xorm:"pk autoincr 'id'"` UID string `json:"uid" xorm:"uid"` + OrgID int64 `json:"orgId" xorm:"org_id"` Title string `json:"title"` - URL string `json:"url" xoem:"url"` + URL string `json:"url" xorm:"url"` HasACL bool `json:"hasAcl" xorm:"has_acl"` CanSave bool `json:"canSave"` CanEdit bool `json:"canEdit"` diff --git a/pkg/api/folder_test.go b/pkg/api/folder_test.go index 4939fb01da7..f15978058b9 100644 --- a/pkg/api/folder_test.go +++ b/pkg/api/folder_test.go @@ -145,8 +145,6 @@ func TestFoldersCreateAPIEndpoint(t *testing.T) { require.NoError(t, resp.Body.Close()) if tc.expectedCode == http.StatusOK { - // nolint:staticcheck - assert.Equal(t, int64(1), folder.ID) assert.Equal(t, "uid", folder.UID) assert.Equal(t, "Folder", folder.Title) } @@ -250,8 +248,6 @@ func TestFoldersUpdateAPIEndpoint(t *testing.T) { require.NoError(t, resp.Body.Close()) if tc.expectedCode == http.StatusOK { - // nolint:staticcheck - assert.Equal(t, int64(1), folder.ID) assert.Equal(t, "uid", folder.UID) assert.Equal(t, "Folder upd", folder.Title) } @@ -443,6 +439,7 @@ func TestFolderGetAPIEndpoint(t *testing.T) { features *featuremgmt.FeatureManager expectedCode int expectedParentUIDs []string + expectedParentOrgIDs []int64 expectedParentTitles []string permissions []accesscontrol.Permission g *guardian.FakeDashboardGuardian @@ -454,6 +451,7 @@ func TestFolderGetAPIEndpoint(t *testing.T) { expectedCode: http.StatusOK, features: featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders), expectedParentUIDs: []string{"parent", "subfolder"}, + expectedParentOrgIDs: []int64{0, 0}, expectedParentTitles: []string{"parent title", "subfolder title"}, permissions: []accesscontrol.Permission{ {Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID("uid")}, @@ -466,6 +464,7 @@ func TestFolderGetAPIEndpoint(t *testing.T) { expectedCode: http.StatusOK, features: featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders), expectedParentUIDs: []string{REDACTED, REDACTED}, + expectedParentOrgIDs: []int64{0, 0}, expectedParentTitles: []string{REDACTED, REDACTED}, permissions: []accesscontrol.Permission{ {Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID("uid")}, @@ -478,6 +477,7 @@ func TestFolderGetAPIEndpoint(t *testing.T) { expectedCode: http.StatusOK, features: featuremgmt.WithFeatures(), expectedParentUIDs: []string{}, + expectedParentOrgIDs: []int64{0, 0}, expectedParentTitles: []string{}, permissions: []accesscontrol.Permission{ {Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID("uid")}, @@ -516,6 +516,7 @@ func TestFolderGetAPIEndpoint(t *testing.T) { for i := 0; i < len(tc.expectedParentUIDs); i++ { assert.Equal(t, tc.expectedParentUIDs[i], folder.Parents[i].UID) + assert.Equal(t, tc.expectedParentOrgIDs[i], folder.Parents[i].OrgID) assert.Equal(t, tc.expectedParentTitles[i], folder.Parents[i].Title) } require.NoError(t, resp.Body.Close()) diff --git a/pkg/tests/api/dashboards/api_dashboards_test.go b/pkg/tests/api/dashboards/api_dashboards_test.go index 42a1e18c0f5..d6b9297db4a 100644 --- a/pkg/tests/api/dashboards/api_dashboards_test.go +++ b/pkg/tests/api/dashboards/api_dashboards_test.go @@ -328,6 +328,7 @@ func TestIntegrationCreate(t *testing.T) { buf1 := &bytes.Buffer{} err = json.NewEncoder(buf1).Encode(dashboards.SaveDashboardCommand{ Dashboard: dashboardDataOne, + OrgID: 0, FolderUID: folder.UID, }) require.NoError(t, err) @@ -358,7 +359,8 @@ func TestIntegrationCreate(t *testing.T) { buf1 := &bytes.Buffer{} err = json.NewEncoder(buf1).Encode(dashboards.SaveDashboardCommand{ Dashboard: dashboardDataOne, - FolderID: folder.ID, // nolint:staticcheck + OrgID: 0, + FolderUID: folder.UID, }) require.NoError(t, err) u := fmt.Sprintf("http://admin:admin@%s/api/dashboards/db", grafanaListedAddr) diff --git a/public/api-merged.json b/public/api-merged.json index d6d49536341..e16ec463ff7 100644 --- a/public/api-merged.json +++ b/public/api-merged.json @@ -14143,6 +14143,10 @@ "type": "integer", "format": "int64" }, + "orgId": { + "type": "integer", + "format": "int64" + }, "parentUid": { "description": "only used if nested folders are enabled", "type": "string" diff --git a/public/openapi3.json b/public/openapi3.json index 0a3adae5520..dd65a56f10e 100644 --- a/public/openapi3.json +++ b/public/openapi3.json @@ -5160,6 +5160,10 @@ "format": "int64", "type": "integer" }, + "orgId": { + "format": "int64", + "type": "integer" + }, "parentUid": { "description": "only used if nested folders are enabled", "type": "string"