Chore: Deprecate FolderID in CreateLibraryElementComand (#77403)

* Chore: Deprecate FolderID in CreateLibraryElementComand

* chore: add remaining nolint comments

* chore: regen specs to include deprecation notice
This commit is contained in:
Kat Yang 2023-10-31 13:24:16 -04:00 committed by GitHub
parent 5f6d15d912
commit 254648b96b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 18 additions and 8 deletions

View File

@ -421,9 +421,11 @@ func TestIntegrationNestedFolderService(t *testing.T) {
_ = createRule(t, alertStore, parent.UID, "parent alert")
_ = createRule(t, alertStore, subfolder.UID, "sub alert")
// nolint:staticcheck
libraryElementCmd.FolderID = parent.ID
_, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
require.NoError(t, err)
// nolint:staticcheck
libraryElementCmd.FolderID = subfolder.ID
_, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
require.NoError(t, err)
@ -496,9 +498,11 @@ func TestIntegrationNestedFolderService(t *testing.T) {
_ = createRule(t, alertStore, parent.UID, "parent alert")
_ = createRule(t, alertStore, subfolder.UID, "sub alert")
// nolint:staticcheck
libraryElementCmd.FolderID = parent.ID
_, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
require.NoError(t, err)
// nolint:staticcheck
libraryElementCmd.FolderID = subfolder.ID
_, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
require.NoError(t, err)
@ -631,11 +635,12 @@ func TestIntegrationNestedFolderService(t *testing.T) {
subfolder, err = serviceWithFlagOn.dashboardFolderStore.GetFolderByUID(context.Background(), orgID, ancestorUIDs[1])
require.NoError(t, err)
_ = createRule(t, alertStore, subfolder.UID, "sub alert")
// nolint:staticcheck
libraryElementCmd.FolderID = subfolder.ID
subPanel, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
require.NoError(t, err)
}
// nolint:staticcheck
libraryElementCmd.FolderID = parent.ID
parentPanel, err := lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
require.NoError(t, err)

View File

@ -62,6 +62,7 @@ func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) respon
if cmd.FolderUID != nil {
if *cmd.FolderUID == "" {
// nolint:staticcheck
cmd.FolderID = 0
generalFolderUID := ac.GeneralFolderUID
cmd.FolderUID = &generalFolderUID
@ -70,6 +71,7 @@ func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) respon
if err != nil || folder == nil {
return response.ErrOrFallback(http.StatusBadRequest, "failed to get folder", err)
}
// nolint:staticcheck
cmd.FolderID = folder.ID
}
}

View File

@ -175,6 +175,7 @@ func (l *LibraryElementService) createLibraryElement(c context.Context, signedIn
return err
}
} else {
// nolint:staticcheck
if err := l.requireEditPermissionsOnFolder(c, signedInUser, cmd.FolderID); err != nil {
return err
}

View File

@ -252,7 +252,7 @@ func getCreateVariableCommand(folderID int64, name string) model.CreateLibraryEl
func getCreateCommandWithModel(folderID int64, name string, kind model.LibraryElementKind, byteModel []byte) model.CreateLibraryElementCommand {
command := model.CreateLibraryElementCommand{
FolderID: folderID,
FolderID: folderID, // nolint:staticcheck
Name: name,
Model: byteModel,
Kind: int64(kind),

View File

@ -192,6 +192,8 @@ var (
// swagger:model
type CreateLibraryElementCommand struct {
// ID of the folder where the library element is stored.
//
// Deprecated: use FolderUID instead
FolderID int64 `json:"folderId"`
// UID of the folder where the library element is stored.
FolderUID *string `json:"folderUid"`

View File

@ -164,7 +164,7 @@ func importLibraryPanelsRecursively(c context.Context, service libraryelements.S
}
var cmd = model.CreateLibraryElementCommand{
FolderID: folderID,
FolderID: folderID, // nolint:staticcheck
Name: name,
Model: Model,
Kind: int64(model.PanelElement),

View File

@ -94,7 +94,7 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
scenarioWithLibraryPanel(t, "When an admin tries to store a dashboard with library panels inside and outside of rows, it should connect all",
func(t *testing.T, sc scenarioContext) {
cmd := model.CreateLibraryElementCommand{
FolderID: sc.initialResult.Result.FolderID,
FolderID: sc.initialResult.Result.FolderID, // nolint:staticcheck
Name: "Outside row",
Model: []byte(`
{
@ -233,7 +233,7 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
scenarioWithLibraryPanel(t, "When an admin tries to store a dashboard with unused/removed library panels, it should disconnect unused/removed library panels",
func(t *testing.T, sc scenarioContext) {
unused, err := sc.elementService.CreateElement(sc.ctx, sc.user, model.CreateLibraryElementCommand{
FolderID: sc.folder.ID,
FolderID: sc.folder.ID, // nolint:staticcheck
Name: "Unused Libray Panel",
Model: []byte(`
{
@ -762,7 +762,7 @@ func scenarioWithLibraryPanel(t *testing.T, desc string, fn func(t *testing.T, s
testScenario(t, desc, func(t *testing.T, sc scenarioContext) {
command := model.CreateLibraryElementCommand{
FolderID: sc.folder.ID,
FolderID: sc.folder.ID, // nolint:staticcheck
Name: "Text - Library Panel",
Model: []byte(`
{

View File

@ -13073,7 +13073,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

@ -3962,7 +3962,7 @@
"description": "CreateLibraryElementCommand is the command for adding 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"
},