public dashboards: move into into its own service (#51358)

This PR moves public dashboards into its own self contained service including API, Service, Database, and Models. Routes are mounted on the Grafana HTTPServer by the API service at injection time with wire.go. The main  route that loads the frontend for public dashboards is still handled by the API package.

Co-authored-by: Jesse Weaver <jesse.weaver@grafana.com>
Co-authored-by: Owen Smallwood <owen.smallwood@grafana.com>
This commit is contained in:
Jeff Levin
2022-07-06 15:51:44 -08:00
committed by GitHub
parent ba2d8cd838
commit eacee08135
23 changed files with 1632 additions and 1198 deletions

View File

@@ -0,0 +1,57 @@
package models
import (
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/stretchr/testify/assert"
)
func TestPublicDashboardTableName(t *testing.T) {
assert.Equal(t, "dashboard_public", PublicDashboard{}.TableName())
}
func TestBuildTimeSettings(t *testing.T) {
var dashboardData = simplejson.NewFromAny(map[string]interface{}{"time": map[string]interface{}{"from": "now-8", "to": "now"}})
testCases := []struct {
name string
dashboard *models.Dashboard
pubdash *PublicDashboard
timeResult *TimeSettings
}{
{
name: "should use dashboard time if pubdash time empty",
dashboard: &models.Dashboard{Data: dashboardData},
pubdash: &PublicDashboard{},
timeResult: &TimeSettings{
From: "now-8",
To: "now",
},
},
{
name: "should use dashboard time if pubdash to/from empty",
dashboard: &models.Dashboard{Data: dashboardData},
pubdash: &PublicDashboard{},
timeResult: &TimeSettings{
From: "now-8",
To: "now",
},
},
{
name: "should use pubdash time",
dashboard: &models.Dashboard{Data: dashboardData},
pubdash: &PublicDashboard{TimeSettings: simplejson.NewFromAny(map[string]interface{}{"from": "now-12", "to": "now"})},
timeResult: &TimeSettings{
From: "now-12",
To: "now",
},
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
assert.Equal(t, test.timeResult, test.pubdash.BuildTimeSettings(test.dashboard))
})
}
}