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:
@@ -89,7 +89,7 @@ func TestDeleteLibraryPanelsInFolder(t *testing.T) {
|
||||
Data: simplejson.NewFromAny(dashJSON),
|
||||
}
|
||||
// nolint:staticcheck
|
||||
dashInDB := createDashboard(t, sc.sqlStore, sc.user, &dash, sc.folder.ID)
|
||||
dashInDB := createDashboard(t, sc.sqlStore, sc.user, &dash, sc.folder.ID, sc.folder.UID)
|
||||
err := sc.service.ConnectElementsToDashboard(sc.reqContext.Req.Context(), sc.reqContext.SignedInUser, []string{sc.initialResult.Result.UID}, dashInDB.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -106,7 +106,7 @@ func TestDeleteLibraryPanelsInFolder(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to delete a folder that contains disconnected elements, it should delete all disconnected elements too",
|
||||
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())
|
||||
@@ -164,7 +164,7 @@ func TestGetLibraryPanelConnections(t *testing.T) {
|
||||
Data: simplejson.NewFromAny(dashJSON),
|
||||
}
|
||||
// nolint:staticcheck
|
||||
dashInDB := createDashboard(t, sc.sqlStore, sc.user, &dash, sc.folder.ID)
|
||||
dashInDB := createDashboard(t, sc.sqlStore, sc.user, &dash, sc.folder.ID, sc.folder.UID)
|
||||
err := sc.service.ConnectElementsToDashboard(sc.reqContext.Req.Context(), sc.reqContext.SignedInUser, []string{sc.initialResult.Result.UID}, dashInDB.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -203,6 +203,7 @@ type libraryElement struct {
|
||||
OrgID int64 `json:"orgId"`
|
||||
// Deprecated: use FolderUID instead
|
||||
FolderID int64 `json:"folderId"`
|
||||
FolderUID string `json:"folderUid"`
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Kind int64 `json:"kind"`
|
||||
@@ -232,8 +233,8 @@ type libraryElementsSearchResult struct {
|
||||
PerPage int `json:"perPage"`
|
||||
}
|
||||
|
||||
func getCreatePanelCommand(folderID int64, name string) model.CreateLibraryElementCommand {
|
||||
command := getCreateCommandWithModel(folderID, name, model.PanelElement, []byte(`
|
||||
func getCreatePanelCommand(folderID int64, folderUID string, name string) model.CreateLibraryElementCommand {
|
||||
command := getCreateCommandWithModel(folderID, folderUID, name, model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -246,8 +247,8 @@ func getCreatePanelCommand(folderID int64, name string) model.CreateLibraryEleme
|
||||
return command
|
||||
}
|
||||
|
||||
func getCreateVariableCommand(folderID int64, name string) model.CreateLibraryElementCommand {
|
||||
command := getCreateCommandWithModel(folderID, name, model.VariableElement, []byte(`
|
||||
func getCreateVariableCommand(folderID int64, folderUID, name string) model.CreateLibraryElementCommand {
|
||||
command := getCreateCommandWithModel(folderID, folderUID, name, model.VariableElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"name": "query0",
|
||||
@@ -259,12 +260,12 @@ func getCreateVariableCommand(folderID int64, name string) model.CreateLibraryEl
|
||||
return command
|
||||
}
|
||||
|
||||
func getCreateCommandWithModel(folderID int64, name string, kind model.LibraryElementKind, byteModel []byte) model.CreateLibraryElementCommand {
|
||||
func getCreateCommandWithModel(folderID int64, folderUID, name string, kind model.LibraryElementKind, byteModel []byte) model.CreateLibraryElementCommand {
|
||||
command := model.CreateLibraryElementCommand{
|
||||
FolderID: folderID, // nolint:staticcheck
|
||||
Name: name,
|
||||
Model: byteModel,
|
||||
Kind: int64(kind),
|
||||
FolderUID: &folderUID,
|
||||
Name: name,
|
||||
Model: byteModel,
|
||||
Kind: int64(kind),
|
||||
}
|
||||
|
||||
return command
|
||||
@@ -281,9 +282,10 @@ type scenarioContext struct {
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func createDashboard(t *testing.T, sqlStore db.DB, user user.SignedInUser, dash *dashboards.Dashboard, folderID int64) *dashboards.Dashboard {
|
||||
func createDashboard(t *testing.T, sqlStore db.DB, user user.SignedInUser, dash *dashboards.Dashboard, folderID int64, folderUID string) *dashboards.Dashboard {
|
||||
// nolint:staticcheck
|
||||
dash.FolderID = folderID
|
||||
dash.FolderUID = folderUID
|
||||
dashItem := &dashboards.SaveDashboardDTO{
|
||||
Dashboard: dash,
|
||||
Message: "",
|
||||
@@ -398,7 +400,7 @@ func scenarioWithPanel(t *testing.T, desc string, fn func(t *testing.T, sc scena
|
||||
|
||||
testScenario(t, desc, func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
sc.initialResult = validateAndUnMarshalResponse(t, resp)
|
||||
|
||||
Reference in New Issue
Block a user