Skip to content

Commit 254648b

Browse files
authored
Chore: Deprecate FolderID in CreateLibraryElementComand (grafana#77403)
* Chore: Deprecate FolderID in CreateLibraryElementComand * chore: add remaining nolint comments * chore: regen specs to include deprecation notice
1 parent 5f6d15d commit 254648b

File tree

9 files changed

+18
-8
lines changed

9 files changed

+18
-8
lines changed

pkg/services/folder/folderimpl/folder_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,11 @@ func TestIntegrationNestedFolderService(t *testing.T) {
421421
_ = createRule(t, alertStore, parent.UID, "parent alert")
422422
_ = createRule(t, alertStore, subfolder.UID, "sub alert")
423423

424+
// nolint:staticcheck
424425
libraryElementCmd.FolderID = parent.ID
425426
_, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
426427
require.NoError(t, err)
428+
// nolint:staticcheck
427429
libraryElementCmd.FolderID = subfolder.ID
428430
_, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
429431
require.NoError(t, err)
@@ -496,9 +498,11 @@ func TestIntegrationNestedFolderService(t *testing.T) {
496498
_ = createRule(t, alertStore, parent.UID, "parent alert")
497499
_ = createRule(t, alertStore, subfolder.UID, "sub alert")
498500

501+
// nolint:staticcheck
499502
libraryElementCmd.FolderID = parent.ID
500503
_, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
501504
require.NoError(t, err)
505+
// nolint:staticcheck
502506
libraryElementCmd.FolderID = subfolder.ID
503507
_, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
504508
require.NoError(t, err)
@@ -631,11 +635,12 @@ func TestIntegrationNestedFolderService(t *testing.T) {
631635
subfolder, err = serviceWithFlagOn.dashboardFolderStore.GetFolderByUID(context.Background(), orgID, ancestorUIDs[1])
632636
require.NoError(t, err)
633637
_ = createRule(t, alertStore, subfolder.UID, "sub alert")
638+
// nolint:staticcheck
634639
libraryElementCmd.FolderID = subfolder.ID
635640
subPanel, err = lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
636641
require.NoError(t, err)
637642
}
638-
643+
// nolint:staticcheck
639644
libraryElementCmd.FolderID = parent.ID
640645
parentPanel, err := lps.LibraryElementService.CreateElement(context.Background(), &signedInUser, libraryElementCmd)
641646
require.NoError(t, err)

pkg/services/libraryelements/api.go

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) respon
6262

6363
if cmd.FolderUID != nil {
6464
if *cmd.FolderUID == "" {
65+
// nolint:staticcheck
6566
cmd.FolderID = 0
6667
generalFolderUID := ac.GeneralFolderUID
6768
cmd.FolderUID = &generalFolderUID
@@ -70,6 +71,7 @@ func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) respon
7071
if err != nil || folder == nil {
7172
return response.ErrOrFallback(http.StatusBadRequest, "failed to get folder", err)
7273
}
74+
// nolint:staticcheck
7375
cmd.FolderID = folder.ID
7476
}
7577
}

pkg/services/libraryelements/database.go

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func (l *LibraryElementService) createLibraryElement(c context.Context, signedIn
175175
return err
176176
}
177177
} else {
178+
// nolint:staticcheck
178179
if err := l.requireEditPermissionsOnFolder(c, signedInUser, cmd.FolderID); err != nil {
179180
return err
180181
}

pkg/services/libraryelements/libraryelements_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func getCreateVariableCommand(folderID int64, name string) model.CreateLibraryEl
252252

253253
func getCreateCommandWithModel(folderID int64, name string, kind model.LibraryElementKind, byteModel []byte) model.CreateLibraryElementCommand {
254254
command := model.CreateLibraryElementCommand{
255-
FolderID: folderID,
255+
FolderID: folderID, // nolint:staticcheck
256256
Name: name,
257257
Model: byteModel,
258258
Kind: int64(kind),

pkg/services/libraryelements/model/model.go

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ var (
192192
// swagger:model
193193
type CreateLibraryElementCommand struct {
194194
// ID of the folder where the library element is stored.
195+
//
196+
// Deprecated: use FolderUID instead
195197
FolderID int64 `json:"folderId"`
196198
// UID of the folder where the library element is stored.
197199
FolderUID *string `json:"folderUid"`

pkg/services/librarypanels/librarypanels.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func importLibraryPanelsRecursively(c context.Context, service libraryelements.S
164164
}
165165

166166
var cmd = model.CreateLibraryElementCommand{
167-
FolderID: folderID,
167+
FolderID: folderID, // nolint:staticcheck
168168
Name: name,
169169
Model: Model,
170170
Kind: int64(model.PanelElement),

pkg/services/librarypanels/librarypanels_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
9494
scenarioWithLibraryPanel(t, "When an admin tries to store a dashboard with library panels inside and outside of rows, it should connect all",
9595
func(t *testing.T, sc scenarioContext) {
9696
cmd := model.CreateLibraryElementCommand{
97-
FolderID: sc.initialResult.Result.FolderID,
97+
FolderID: sc.initialResult.Result.FolderID, // nolint:staticcheck
9898
Name: "Outside row",
9999
Model: []byte(`
100100
{
@@ -233,7 +233,7 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
233233
scenarioWithLibraryPanel(t, "When an admin tries to store a dashboard with unused/removed library panels, it should disconnect unused/removed library panels",
234234
func(t *testing.T, sc scenarioContext) {
235235
unused, err := sc.elementService.CreateElement(sc.ctx, sc.user, model.CreateLibraryElementCommand{
236-
FolderID: sc.folder.ID,
236+
FolderID: sc.folder.ID, // nolint:staticcheck
237237
Name: "Unused Libray Panel",
238238
Model: []byte(`
239239
{
@@ -762,7 +762,7 @@ func scenarioWithLibraryPanel(t *testing.T, desc string, fn func(t *testing.T, s
762762

763763
testScenario(t, desc, func(t *testing.T, sc scenarioContext) {
764764
command := model.CreateLibraryElementCommand{
765-
FolderID: sc.folder.ID,
765+
FolderID: sc.folder.ID, // nolint:staticcheck
766766
Name: "Text - Library Panel",
767767
Model: []byte(`
768768
{

public/api-merged.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13073,7 +13073,7 @@
1307313073
"type": "object",
1307413074
"properties": {
1307513075
"folderId": {
13076-
"description": "ID of the folder where the library element is stored.",
13076+
"description": "ID of the folder where the library element is stored.\n\nDeprecated: use FolderUID instead",
1307713077
"type": "integer",
1307813078
"format": "int64"
1307913079
},

public/openapi3.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3962,7 +3962,7 @@
39623962
"description": "CreateLibraryElementCommand is the command for adding a LibraryElement",
39633963
"properties": {
39643964
"folderId": {
3965-
"description": "ID of the folder where the library element is stored.",
3965+
"description": "ID of the folder where the library element is stored.\n\nDeprecated: use FolderUID instead",
39663966
"format": "int64",
39673967
"type": "integer"
39683968
},

0 commit comments

Comments
 (0)