Add FolderUID for library elements (#79572)
* Add FolderUID in missing places for libraryelements * Add migration for FolderUID in library elements table * Add Folder UIDs tolibrary panels * Adjust dashboard import with folder uid * Fix lint * Rename back FolderUID to UID * Remove default * Check if folderUID is nil * Add unique indes on org_id,folder_uid,name and kind * Update pkg/services/libraryelements/database.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Fix folder integration test, with unique index on library elements * Make folder uids nullable and rewrite migration query * Use dashboard uid instead of folder_uid * Adjust test --------- Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
co-authored by
Sofia Papagiannaki
parent
2182cc47ac
commit
2532047e7a
@@ -39,7 +39,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all panel elements and both panels and variables exist, it should only return panels",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreateVariableCommand(sc.folder.ID, "query0")
|
||||
command := getCreateVariableCommand(sc.folder.ID, sc.folder.UID, "query0")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -64,6 +64,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -106,7 +107,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all variable elements and both panels and variables exist, it should only return panels",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreateVariableCommand(sc.folder.ID, "query0")
|
||||
command := getCreateVariableCommand(sc.folder.ID, sc.folder.UID, "query0")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -131,6 +132,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "query0",
|
||||
Kind: int64(model.VariableElement),
|
||||
@@ -172,7 +174,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist, it should succeed",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -193,6 +195,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -228,6 +231,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -270,7 +274,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and sort desc is set, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -294,6 +298,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -329,6 +334,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -371,7 +377,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and typeFilter is set to existing types, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Gauge - Library Panel", model.PanelElement, []byte(`
|
||||
command := getCreateCommandWithModel(sc.folder.ID, sc.folder.UID, "Gauge - Library Panel", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -385,7 +391,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
require.Equal(t, 200, resp.Status())
|
||||
|
||||
// nolint:staticcheck
|
||||
command = getCreateCommandWithModel(sc.folder.ID, "BarGauge - Library Panel", model.PanelElement, []byte(`
|
||||
command = getCreateCommandWithModel(sc.folder.ID, sc.folder.UID, "BarGauge - Library Panel", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -417,6 +423,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 3,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "BarGauge - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -452,6 +459,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Gauge - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -494,7 +502,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and typeFilter is set to a nonexistent type, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Gauge - Library Panel", model.PanelElement, []byte(`
|
||||
command := getCreateCommandWithModel(sc.folder.ID, sc.folder.UID, "Gauge - Library Panel", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -529,25 +537,24 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and folderFilter is set to existing folders, it should succeed and the result should be correct",
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and folderFilterUIDs is set to existing folders, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
newFolder := createFolder(t, sc, "NewFolder")
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(newFolder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(newFolder.ID, newFolder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
// nolint:staticcheck
|
||||
folderFilter := strconv.FormatInt(newFolder.ID, 10)
|
||||
|
||||
folderFilterUID := newFolder.UID
|
||||
err := sc.reqContext.Req.ParseForm()
|
||||
require.NoError(t, err)
|
||||
sc.reqContext.Req.Form.Add("folderFilter", folderFilter)
|
||||
sc.reqContext.Req.Form.Add("folderFilterUIDs", folderFilterUID)
|
||||
resp = sc.service.getAllHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
|
||||
var result libraryElementsSearch
|
||||
err = json.Unmarshal(resp.Body(), &result)
|
||||
|
||||
require.NoError(t, err)
|
||||
var expected = libraryElementsSearch{
|
||||
Result: libraryElementsSearchResult{
|
||||
@@ -559,6 +566,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: newFolder.ID, // nolint:staticcheck
|
||||
FolderUID: newFolder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -602,15 +610,15 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
newFolder := createFolder(t, sc, "NewFolder")
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(newFolder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(newFolder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
folderFilter := "2020,2021"
|
||||
folderFilterUIDs := "2020,2021"
|
||||
|
||||
err := sc.reqContext.Req.ParseForm()
|
||||
require.NoError(t, err)
|
||||
sc.reqContext.Req.Form.Add("folderFilter", folderFilter)
|
||||
sc.reqContext.Req.Form.Add("folderFilterUIDs", folderFilterUIDs)
|
||||
resp = sc.service.getAllHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
|
||||
@@ -633,7 +641,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and folderFilter is set to General folder, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -658,6 +666,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -693,6 +702,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -735,7 +745,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and excludeUID is set, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -759,6 +769,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -801,7 +812,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and perPage is 1, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -825,6 +836,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -867,7 +879,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and perPage is 1 and page is 2, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -892,6 +904,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -934,7 +947,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and searchString exists in the description, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Text - Library Panel2", model.PanelElement, []byte(`
|
||||
command := getCreateCommandWithModel(sc.folder.ID, sc.folder.UID, "Text - Library Panel2", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -968,6 +981,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -1010,7 +1024,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and searchString exists in both name and description, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Some Other", model.PanelElement, []byte(`
|
||||
command := getCreateCommandWithModel(sc.folder.ID, sc.folder.UID, "Some Other", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -1042,6 +1056,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Some Other",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -1077,6 +1092,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -1119,7 +1135,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and perPage is 1 and page is 1 and searchString is panel2, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -1145,6 +1161,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
ID: 2,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -1187,7 +1204,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and perPage is 1 and page is 3 and searchString is panel, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -1219,7 +1236,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and perPage is 1 and page is 3 and searchString does not exist, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel2")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel2")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
|
||||
Reference in New Issue
Block a user