Chore: Deprecate FolderID in PatchLibraryElementCommand (#77472)

* Chore: Deprecate FolderID in PatchLibraryElementCommand

* chore: regen specs
This commit is contained in:
Kat Yang 2023-11-06 11:31:01 -05:00 committed by GitHub
parent dd5314c6a8
commit 2c7f364067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 16 deletions

View File

@ -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
}
}

View File

@ -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),
}

View File

@ -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)

View File

@ -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"`

View File

@ -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"
},

View File

@ -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"
},