From 2c7f3640672c312f5e8054dee40388c1d853fff5 Mon Sep 17 00:00:00 2001 From: Kat Yang <69819079+yangkb09@users.noreply.github.com> Date: Mon, 6 Nov 2023 11:31:01 -0500 Subject: [PATCH] Chore: Deprecate FolderID in PatchLibraryElementCommand (#77472) * Chore: Deprecate FolderID in PatchLibraryElementCommand * chore: regen specs --- pkg/services/libraryelements/api.go | 2 ++ .../libraryelements_patch_test.go | 29 ++++++++++--------- .../libraryelements_permissions_test.go | 4 +++ pkg/services/libraryelements/model/model.go | 2 ++ public/api-merged.json | 2 +- public/openapi3.json | 2 +- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/pkg/services/libraryelements/api.go b/pkg/services/libraryelements/api.go index 54bfdf9b423..de6c7237d4f 100644 --- a/pkg/services/libraryelements/api.go +++ b/pkg/services/libraryelements/api.go @@ -209,12 +209,14 @@ func (l *LibraryElementService) patchHandler(c *contextmodel.ReqContext) respons if cmd.FolderUID != nil { if *cmd.FolderUID == "" { + // nolint:staticcheck cmd.FolderID = 0 } else { folder, err := l.folderService.Get(c.Req.Context(), &folder.GetFolderQuery{OrgID: c.SignedInUser.GetOrgID(), UID: cmd.FolderUID, SignedInUser: c.SignedInUser}) if err != nil || folder == nil { return response.Error(http.StatusBadRequest, "failed to get folder", err) } + // nolint:staticcheck cmd.FolderID = folder.ID } } diff --git a/pkg/services/libraryelements/libraryelements_patch_test.go b/pkg/services/libraryelements/libraryelements_patch_test.go index e693a8202c2..40247307497 100644 --- a/pkg/services/libraryelements/libraryelements_patch_test.go +++ b/pkg/services/libraryelements/libraryelements_patch_test.go @@ -26,7 +26,7 @@ func TestPatchLibraryElement(t *testing.T) { func(t *testing.T, sc scenarioContext) { newFolder := createFolder(t, sc, "NewFolder") cmd := model.PatchLibraryElementCommand{ - FolderID: newFolder.ID, + FolderID: newFolder.ID, // nolint:staticcheck Name: "Panel - New name", Model: []byte(` { @@ -91,7 +91,7 @@ func TestPatchLibraryElement(t *testing.T) { func(t *testing.T, sc scenarioContext) { newFolder := createFolder(t, sc, "NewFolder") cmd := model.PatchLibraryElementCommand{ - FolderID: newFolder.ID, + FolderID: newFolder.ID, // nolint:staticcheck Kind: int64(model.PanelElement), Version: 1, } @@ -115,7 +115,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel with name only, it should change name successfully and return correct result", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: -1, + FolderID: -1, // nolint:staticcheck Name: "New Name", Kind: int64(model.PanelElement), Version: 1, @@ -138,7 +138,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel with a nonexistent UID, it should change UID successfully and return correct result", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: -1, + FolderID: -1, // nolint:staticcheck UID: util.GenerateShortUID(), Kind: int64(model.PanelElement), Version: 1, @@ -161,7 +161,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel with an invalid UID, it should fail", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: -1, + FolderID: -1, // nolint:staticcheck UID: "Testing an invalid UID", Kind: int64(model.PanelElement), Version: 1, @@ -175,7 +175,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel with an UID that is too long, it should fail", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: -1, + FolderID: -1, // nolint:staticcheck UID: "j6T00KRZzj6T00KRZzj6T00KRZzj6T00KRZzj6T00K", Kind: int64(model.PanelElement), Version: 1, @@ -194,7 +194,7 @@ func TestPatchLibraryElement(t *testing.T) { resp := sc.service.createHandler(sc.reqContext) require.Equal(t, 200, resp.Status()) cmd := model.PatchLibraryElementCommand{ - FolderID: -1, + FolderID: -1, // nolint:staticcheck UID: command.UID, Kind: int64(model.PanelElement), Version: 1, @@ -208,7 +208,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel with model only, it should change model successfully, sync type and description fields and return correct result", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: -1, + FolderID: -1, // nolint:staticcheck Model: []byte(`{ "title": "New Model Title", "name": "New Model Name", "type":"graph", "description": "New description" }`), Kind: int64(model.PanelElement), Version: 1, @@ -237,7 +237,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel with model.description only, it should change model successfully, sync type and description fields and return correct result", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: -1, + FolderID: -1, // nolint:staticcheck Model: []byte(`{ "description": "New description" }`), Kind: int64(model.PanelElement), Version: 1, @@ -264,7 +264,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel with model.type only, it should change model successfully, sync type and description fields and return correct result", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: -1, + FolderID: -1, // nolint:staticcheck Model: []byte(`{ "type": "graph" }`), Kind: int64(model.PanelElement), Version: 1, @@ -290,6 +290,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When another admin tries to patch a library panel, it should change UpdatedBy successfully and return correct result", func(t *testing.T, sc scenarioContext) { + // nolint:staticcheck cmd := model.PatchLibraryElementCommand{FolderID: -1, Version: 1, Kind: int64(model.PanelElement)} sc.reqContext.UserID = 2 sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": sc.initialResult.Result.UID}) @@ -331,7 +332,7 @@ func TestPatchLibraryElement(t *testing.T) { resp := sc.service.createHandler(sc.reqContext) var result = validateAndUnMarshalResponse(t, resp) cmd := model.PatchLibraryElementCommand{ - FolderID: 1, + FolderID: 1, // nolint:staticcheck Version: 1, Kind: int64(model.PanelElement), } @@ -344,7 +345,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel in another org, it should fail", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: sc.folder.ID, + FolderID: sc.folder.ID, // nolint:staticcheck Version: 1, Kind: int64(model.PanelElement), } @@ -358,7 +359,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel with an old version number, it should fail", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: sc.folder.ID, + FolderID: sc.folder.ID, // nolint:staticcheck Version: 1, Kind: int64(model.PanelElement), } @@ -374,7 +375,7 @@ func TestPatchLibraryElement(t *testing.T) { scenarioWithPanel(t, "When an admin tries to patch a library panel with an other kind, it should succeed but panel should not change", func(t *testing.T, sc scenarioContext) { cmd := model.PatchLibraryElementCommand{ - FolderID: sc.folder.ID, + FolderID: sc.folder.ID, // nolint:staticcheck Version: 1, Kind: int64(model.VariableElement), } diff --git a/pkg/services/libraryelements/libraryelements_permissions_test.go b/pkg/services/libraryelements/libraryelements_permissions_test.go index 662f823e649..cae26a941be 100644 --- a/pkg/services/libraryelements/libraryelements_permissions_test.go +++ b/pkg/services/libraryelements/libraryelements_permissions_test.go @@ -45,6 +45,7 @@ func TestLibraryElementPermissionsGeneralFolder(t *testing.T) { result := validateAndUnMarshalResponse(t, resp) sc.reqContext.SignedInUser.OrgRole = testCase.role + // nolint:staticcheck cmd := model.PatchLibraryElementCommand{FolderID: 0, Version: 1, Kind: int64(model.PanelElement)} sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": result.Result.UID}) sc.ctx.Req.Body = mockRequestBody(cmd) @@ -61,6 +62,7 @@ func TestLibraryElementPermissionsGeneralFolder(t *testing.T) { result := validateAndUnMarshalResponse(t, resp) sc.reqContext.SignedInUser.OrgRole = testCase.role + // nolint:staticcheck cmd := model.PatchLibraryElementCommand{FolderID: folder.ID, Version: 1, Kind: int64(model.PanelElement)} sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": result.Result.UID}) sc.ctx.Req.Body = mockRequestBody(cmd) @@ -242,6 +244,7 @@ func TestLibraryElementPatchPermissions(t *testing.T) { 1: testCase.permissions, } + // nolint:staticcheck cmd := model.PatchLibraryElementCommand{FolderID: toFolder.ID, Version: 1, Kind: int64(model.PanelElement)} sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": result.Result.UID}) sc.reqContext.Req.Body = mockRequestBody(cmd) @@ -324,6 +327,7 @@ func TestLibraryElementsWithMissingFolders(t *testing.T) { resp := sc.service.createHandler(sc.reqContext) result := validateAndUnMarshalResponse(t, resp) + // nolint:staticcheck cmd := model.PatchLibraryElementCommand{FolderID: -100, Version: 1, Kind: int64(model.PanelElement)} sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": result.Result.UID}) sc.reqContext.Req.Body = mockRequestBody(cmd) diff --git a/pkg/services/libraryelements/model/model.go b/pkg/services/libraryelements/model/model.go index 3b047c6f452..88a2dcfa545 100644 --- a/pkg/services/libraryelements/model/model.go +++ b/pkg/services/libraryelements/model/model.go @@ -216,6 +216,8 @@ type CreateLibraryElementCommand struct { // PatchLibraryElementCommand is the command for patching a LibraryElement type PatchLibraryElementCommand struct { // ID of the folder where the library element is stored. + // + // Deprecated: use FolderUID instead FolderID int64 `json:"folderId" binding:"Default(-1)"` // UID of the folder where the library element is stored. FolderUID *string `json:"folderUid"` diff --git a/public/api-merged.json b/public/api-merged.json index c66757a097b..0d285367524 100644 --- a/public/api-merged.json +++ b/public/api-merged.json @@ -16593,7 +16593,7 @@ "type": "object", "properties": { "folderId": { - "description": "ID of the folder where the library element is stored.", + "description": "ID of the folder where the library element is stored.\n\nDeprecated: use FolderUID instead", "type": "integer", "format": "int64" }, diff --git a/public/openapi3.json b/public/openapi3.json index 8348a396917..3581fd150c7 100644 --- a/public/openapi3.json +++ b/public/openapi3.json @@ -7505,7 +7505,7 @@ "description": "PatchLibraryElementCommand is the command for patching a LibraryElement", "properties": { "folderId": { - "description": "ID of the folder where the library element is stored.", + "description": "ID of the folder where the library element is stored.\n\nDeprecated: use FolderUID instead", "format": "int64", "type": "integer" },