[v11.0.x] Add FolderUID for library elements (#86280)
Add FolderUID for library elements (#83819)
(cherry picked from commit 5c4a2de59b)
Co-authored-by: idafurjes <36131195+idafurjes@users.noreply.github.com>
This commit is contained in:
co-authored by
idafurjes
parent
c968ff62a1
commit
df2fee63a5
@@ -141,7 +141,7 @@ func (s *ImportDashboardService) ImportDashboard(ctx context.Context, req *dashb
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.DashboardImport).Inc()
|
||||
// nolint:staticcheck
|
||||
err = s.libraryPanelService.ImportLibraryPanelsForDashboard(ctx, req.User, libraryElements, generatedDash.Get("panels").MustArray(), req.FolderId)
|
||||
err = s.libraryPanelService.ImportLibraryPanelsForDashboard(ctx, req.User, libraryElements, generatedDash.Get("panels").MustArray(), req.FolderId, req.FolderUid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestImportDashboardService(t *testing.T) {
|
||||
importLibraryPanelsForDashboard := false
|
||||
connectLibraryPanelsForDashboardCalled := false
|
||||
libraryPanelService := &libraryPanelServiceMock{
|
||||
importLibraryPanelsForDashboardFunc: func(ctx context.Context, signedInUser identity.Requester, libraryPanels *simplejson.Json, panels []any, folderID int64) error {
|
||||
importLibraryPanelsForDashboardFunc: func(ctx context.Context, signedInUser identity.Requester, libraryPanels *simplejson.Json, panels []any, folderID int64, folderUID string) error {
|
||||
importLibraryPanelsForDashboard = true
|
||||
return nil
|
||||
},
|
||||
@@ -75,9 +75,8 @@ func TestImportDashboardService(t *testing.T) {
|
||||
Inputs: []dashboardimport.ImportDashboardInput{
|
||||
{Name: "*", Type: "datasource", Value: "prom"},
|
||||
},
|
||||
User: &user.SignedInUser{UserID: 2, OrgRole: org.RoleAdmin, OrgID: 3},
|
||||
// FolderId: 5,
|
||||
FolderUid: "123",
|
||||
User: &user.SignedInUser{UserID: 2, OrgRole: org.RoleAdmin, OrgID: 3},
|
||||
FolderUid: "folderUID",
|
||||
}
|
||||
resp, err := s.ImportDashboard(context.Background(), req)
|
||||
require.NoError(t, err)
|
||||
@@ -91,7 +90,7 @@ func TestImportDashboardService(t *testing.T) {
|
||||
require.Equal(t, int64(3), importDashboardArg.OrgID)
|
||||
require.Equal(t, int64(2), userID)
|
||||
require.Equal(t, "prometheus", importDashboardArg.Dashboard.PluginID)
|
||||
require.Equal(t, "123", importDashboardArg.Dashboard.FolderUID)
|
||||
require.Equal(t, "folderUID", importDashboardArg.Dashboard.FolderUID)
|
||||
|
||||
panel := importDashboardArg.Dashboard.Data.Get("panels").GetIndex(0)
|
||||
require.Equal(t, "prom", panel.Get("datasource").MustString())
|
||||
@@ -143,7 +142,7 @@ func TestImportDashboardService(t *testing.T) {
|
||||
{Name: "*", Type: "datasource", Value: "prom"},
|
||||
},
|
||||
User: &user.SignedInUser{UserID: 2, OrgRole: org.RoleAdmin, OrgID: 3},
|
||||
FolderUid: "123",
|
||||
FolderUid: "folderUID",
|
||||
}
|
||||
resp, err := s.ImportDashboard(context.Background(), req)
|
||||
require.NoError(t, err)
|
||||
@@ -157,7 +156,7 @@ func TestImportDashboardService(t *testing.T) {
|
||||
require.Equal(t, int64(3), importDashboardArg.OrgID)
|
||||
require.Equal(t, int64(2), userID)
|
||||
require.Equal(t, "", importDashboardArg.Dashboard.PluginID)
|
||||
require.Equal(t, "123", importDashboardArg.Dashboard.FolderUID)
|
||||
require.Equal(t, "folderUID", importDashboardArg.Dashboard.FolderUID)
|
||||
|
||||
panel := importDashboardArg.Dashboard.Data.Get("panels").GetIndex(0)
|
||||
require.Equal(t, "prom", panel.Get("datasource").MustString())
|
||||
@@ -211,7 +210,7 @@ func (s *dashboardServiceMock) ImportDashboard(ctx context.Context, dto *dashboa
|
||||
type libraryPanelServiceMock struct {
|
||||
librarypanels.Service
|
||||
connectLibraryPanelsForDashboardFunc func(c context.Context, signedInUser identity.Requester, dash *dashboards.Dashboard) error
|
||||
importLibraryPanelsForDashboardFunc func(c context.Context, signedInUser identity.Requester, libraryPanels *simplejson.Json, panels []any, folderID int64) error
|
||||
importLibraryPanelsForDashboardFunc func(c context.Context, signedInUser identity.Requester, libraryPanels *simplejson.Json, panels []any, folderID int64, folderUID string) error
|
||||
}
|
||||
|
||||
var _ librarypanels.Service = (*libraryPanelServiceMock)(nil)
|
||||
@@ -224,9 +223,9 @@ func (s *libraryPanelServiceMock) ConnectLibraryPanelsForDashboard(ctx context.C
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *libraryPanelServiceMock) ImportLibraryPanelsForDashboard(ctx context.Context, signedInUser identity.Requester, libraryPanels *simplejson.Json, panels []any, folderID int64) error {
|
||||
func (s *libraryPanelServiceMock) ImportLibraryPanelsForDashboard(ctx context.Context, signedInUser identity.Requester, libraryPanels *simplejson.Json, panels []any, folderID int64, folderUID string) error {
|
||||
if s.importLibraryPanelsForDashboardFunc != nil {
|
||||
return s.importLibraryPanelsForDashboardFunc(ctx, signedInUser, libraryPanels, panels, folderID)
|
||||
return s.importLibraryPanelsForDashboardFunc(ctx, signedInUser, libraryPanels, panels, folderID, folderUID)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user