|
|
|
@ -12,6 +12,7 @@ import ( |
|
|
|
|
"github.com/grafana/grafana/pkg/services/dashboardimport/api" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/dashboardimport/utils" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/folder" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/librarypanels" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/plugindashboards" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/quota" |
|
|
|
@ -21,12 +22,13 @@ func ProvideService(routeRegister routing.RouteRegister, |
|
|
|
|
quotaService quota.Service, |
|
|
|
|
pluginDashboardService plugindashboards.Service, pluginStore plugins.Store, |
|
|
|
|
libraryPanelService librarypanels.Service, dashboardService dashboards.DashboardService, |
|
|
|
|
ac accesscontrol.AccessControl, |
|
|
|
|
ac accesscontrol.AccessControl, folderService folder.Service, |
|
|
|
|
) *ImportDashboardService { |
|
|
|
|
s := &ImportDashboardService{ |
|
|
|
|
pluginDashboardService: pluginDashboardService, |
|
|
|
|
dashboardService: dashboardService, |
|
|
|
|
libraryPanelService: libraryPanelService, |
|
|
|
|
folderService: folderService, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dashboardImportAPI := api.New(s, quotaService, pluginStore, ac) |
|
|
|
@ -39,6 +41,7 @@ type ImportDashboardService struct { |
|
|
|
|
pluginDashboardService plugindashboards.Service |
|
|
|
|
dashboardService dashboards.DashboardService |
|
|
|
|
libraryPanelService librarypanels.Service |
|
|
|
|
folderService folder.Service |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *ImportDashboardService) ImportDashboard(ctx context.Context, req *dashboardimport.ImportDashboardRequest) (*dashboardimport.ImportDashboardResponse, error) { |
|
|
|
@ -80,6 +83,21 @@ func (s *ImportDashboardService) ImportDashboard(ctx context.Context, req *dashb |
|
|
|
|
generatedDash.Del("__inputs") |
|
|
|
|
generatedDash.Del("__requires") |
|
|
|
|
|
|
|
|
|
// here we need to get FolderId from FolderUID if it present in the request, if both exist, FolderUID would overwrite FolderID
|
|
|
|
|
if req.FolderUid != "" { |
|
|
|
|
folder, err := s.folderService.GetFolderByUID(ctx, req.User, req.User.OrgID, req.FolderUid) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
req.FolderId = folder.Id |
|
|
|
|
} else { |
|
|
|
|
folder, err := s.folderService.GetFolderByID(ctx, req.User, req.FolderId, req.User.OrgID) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
req.FolderUid = folder.Uid |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
saveCmd := models.SaveDashboardCommand{ |
|
|
|
|
Dashboard: generatedDash, |
|
|
|
|
OrgId: req.User.OrgID, |
|
|
|
@ -118,6 +136,7 @@ func (s *ImportDashboardService) ImportDashboard(ctx context.Context, req *dashb |
|
|
|
|
Path: req.Path, |
|
|
|
|
Revision: savedDashboard.Data.Get("revision").MustInt64(1), |
|
|
|
|
FolderId: savedDashboard.FolderId, |
|
|
|
|
FolderUID: req.FolderUid, |
|
|
|
|
ImportedUri: "db/" + savedDashboard.Slug, |
|
|
|
|
ImportedUrl: savedDashboard.GetUrl(), |
|
|
|
|
ImportedRevision: savedDashboard.Data.Get("revision").MustInt64(1), |
|
|
|
|