Public Dashboards: Pubdash panels get data from pubdash api (#50556)
* Public dashboard query API * Create new API on service for building metric request * Flesh out testing, implement BuildPublicDashboardMetricRequest * Test for errors and missing panels * WIP: Test for multiple datasources * Refactor tests, add supporting code for multiple datasources * Gets the panel data from the pubdash query api * Adds tests to make sure we get the correct api url from retrieving panel data * Public dashboard query API * Create new API on service for building metric request * Flesh out testing, implement BuildPublicDashboardMetricRequest * Test for errors and missing panels * WIP: Test for multiple datasources * Refactor tests, add supporting code for multiple datasources * Handle queries from multiple datasources * Replace dashboard time range with pubdash time range settings * Fix comments from review, build failure * removes changes to DataSourceWithBackend.ts regarding getting the pubdash panel query url. Going to do this in a new class, PublicDashboardDataSource.ts * Include pubdash Uid in dashboard meta * Creates new PublicDashboardDataSource.ts and adds test * Passes pubdash uid down to PanelQueryRunner.ts to a PublicDashboardDatasource can be chosen when were looking at a public dashboard * removes comment * checks for error when unmarshalling json * Only replace dashboard time settings with pubdash time settings when pubdash time settings exist * formatting and added comment Co-authored-by: Jesse Weaver <jesse.weaver@grafana.com> Co-authored-by: Jeff Levin <jeff@levinology.com>
This commit is contained in:
co-authored by
Jesse Weaver
Jeff Levin
parent
0371884cdd
commit
1bb2d2599c
+18
-14
@@ -14,25 +14,28 @@ import (
|
||||
|
||||
// gets public dashboard
|
||||
func (hs *HTTPServer) GetPublicDashboard(c *models.ReqContext) response.Response {
|
||||
dash, err := hs.dashboardService.GetPublicDashboard(c.Req.Context(), web.Params(c.Req)[":uid"])
|
||||
publicDashboardUid := web.Params(c.Req)[":uid"]
|
||||
|
||||
dash, err := hs.dashboardService.GetPublicDashboard(c.Req.Context(), publicDashboardUid)
|
||||
if err != nil {
|
||||
return handleDashboardErr(http.StatusInternalServerError, "Failed to get public dashboard", err)
|
||||
}
|
||||
|
||||
meta := dtos.DashboardMeta{
|
||||
Slug: dash.Slug,
|
||||
Type: models.DashTypeDB,
|
||||
CanStar: false,
|
||||
CanSave: false,
|
||||
CanEdit: false,
|
||||
CanAdmin: false,
|
||||
CanDelete: false,
|
||||
Created: dash.Created,
|
||||
Updated: dash.Updated,
|
||||
Version: dash.Version,
|
||||
IsFolder: false,
|
||||
FolderId: dash.FolderId,
|
||||
IsPublic: dash.IsPublic,
|
||||
Slug: dash.Slug,
|
||||
Type: models.DashTypeDB,
|
||||
CanStar: false,
|
||||
CanSave: false,
|
||||
CanEdit: false,
|
||||
CanAdmin: false,
|
||||
CanDelete: false,
|
||||
Created: dash.Created,
|
||||
Updated: dash.Updated,
|
||||
Version: dash.Version,
|
||||
IsFolder: false,
|
||||
FolderId: dash.FolderId,
|
||||
IsPublic: dash.IsPublic,
|
||||
PublicDashboardUid: publicDashboardUid,
|
||||
}
|
||||
|
||||
dto := dtos.DashboardFullWithMeta{Meta: meta, Dashboard: dash.Data}
|
||||
@@ -88,6 +91,7 @@ func (hs *HTTPServer) QueryPublicDashboard(c *models.ReqContext) response.Respon
|
||||
}
|
||||
|
||||
resp, err := hs.queryDataService.QueryDataMultipleSources(c.Req.Context(), nil, c.SkipCache, reqDTO, true)
|
||||
|
||||
if err != nil {
|
||||
return hs.handleQueryMetricsError(err)
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ type DashboardMeta struct {
|
||||
ProvisionedExternalId string `json:"provisionedExternalId"`
|
||||
AnnotationsPermissions *AnnotationPermission `json:"annotationsPermissions"`
|
||||
IsPublic bool `json:"isPublic"`
|
||||
PublicDashboardUid string `json:"publicDashboardUid"`
|
||||
}
|
||||
type AnnotationPermission struct {
|
||||
Dashboard AnnotationActions `json:"dashboard"`
|
||||
|
||||
@@ -25,7 +25,16 @@ func (dr *DashboardServiceImpl) GetPublicDashboard(ctx context.Context, dashboar
|
||||
return nil, models.ErrPublicDashboardNotFound
|
||||
}
|
||||
|
||||
// FIXME maybe insert logic to substitute pdc.TimeSettings into d
|
||||
// Replace dashboard time range with pubdash time range
|
||||
if pdc.TimeSettings != "" {
|
||||
var pdcTimeSettings map[string]interface{}
|
||||
err = json.Unmarshal([]byte(pdc.TimeSettings), &pdcTimeSettings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
d.Data.Set("time", pdcTimeSettings)
|
||||
}
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
||||
@@ -36,6 +36,19 @@ func TestGetPublicDashboard(t *testing.T) {
|
||||
errResp: nil,
|
||||
dashResp: &models.Dashboard{IsPublic: true},
|
||||
},
|
||||
{
|
||||
name: "puts pubdash time settings into dashboard",
|
||||
uid: "abc123",
|
||||
storeResp: &storeResp{
|
||||
pd: &models.PublicDashboard{TimeSettings: `{"from": "now-8", "to": "now"}`},
|
||||
d: &models.Dashboard{
|
||||
IsPublic: true,
|
||||
Data: simplejson.NewFromAny(map[string]interface{}{"time": map[string]interface{}{"from": "abc", "to": "123"}}),
|
||||
},
|
||||
err: nil},
|
||||
errResp: nil,
|
||||
dashResp: &models.Dashboard{IsPublic: true, Data: simplejson.NewFromAny(map[string]interface{}{"time": map[string]interface{}{"from": "now-8", "to": "now"}})},
|
||||
},
|
||||
{
|
||||
name: "returns ErrPublicDashboardNotFound when isPublic is false",
|
||||
uid: "abc123",
|
||||
@@ -224,6 +237,7 @@ func TestBuildPublicDashboardMetricRequest(t *testing.T) {
|
||||
pdc.PublicDashboard.Uid,
|
||||
49,
|
||||
)
|
||||
|
||||
require.ErrorContains(t, err, "Panel not found")
|
||||
})
|
||||
|
||||
|
||||
@@ -354,6 +354,10 @@ func (dr *DashboardServiceImpl) DeleteDashboard(ctx context.Context, dashboardId
|
||||
return dr.deleteDashboard(ctx, dashboardId, orgId, true)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboardByPublicUid(ctx context.Context, dashboardPublicUid string) (*models.Dashboard, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) MakeUserAdmin(ctx context.Context, orgID int64, userID int64, dashboardID int64, setViewAndEditPermissions bool) error {
|
||||
rtEditor := models.ROLE_EDITOR
|
||||
rtViewer := models.ROLE_VIEWER
|
||||
|
||||
@@ -444,6 +444,10 @@ func (s *dashboardServiceMock) DeleteDashboard(_ context.Context, dashboardId in
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *dashboardServiceMock) GetDashboardByPublicUid(ctx context.Context, dashboardPublicUid string) (*models.Dashboard, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type scenarioInput struct {
|
||||
storedPluginSettings []*pluginsettings.DTO
|
||||
installedPlugins []plugins.PluginDTO
|
||||
|
||||
Reference in New Issue
Block a user