mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Public Dashboards: Disable email-sharing when there is no license (#80887)
* PublicDashboards: Disable email-shared dashboards when feature is disabled * fix pubdash creation when it was email-shared * add feature name const in OSS * update doc * Update service.go * fix test & linter * fix test * Update query_test.go * update tests * fix imports * fix doc linter issues * Update docs/sources/administration/enterprise-licensing/_index.md * fix after merge
This commit is contained in:
parent
cfcf03bf7a
commit
8d68159b52
@ -196,6 +196,13 @@ The active users limit is turned off immediately.
|
|||||||
|
|
||||||
Settings updates at runtime are not affected by an expired license.
|
Settings updates at runtime are not affected by an expired license.
|
||||||
|
|
||||||
|
#### Email sharing
|
||||||
|
|
||||||
|
External users can't access dashboards shared via email anymore.
|
||||||
|
These dashboards are now private but you can make them public and accessible to everyone if you want to.
|
||||||
|
|
||||||
|
Grafana keeps your sharing configurations and restores them after you update your license.
|
||||||
|
|
||||||
## Grafana Enterprise license restrictions
|
## Grafana Enterprise license restrictions
|
||||||
|
|
||||||
When you become a Grafana Enterprise customer, you receive a license that governs your use of Grafana Enterprise.
|
When you become a Grafana Enterprise customer, you receive a license that governs your use of Grafana Enterprise.
|
||||||
|
@ -98,7 +98,7 @@ func (hs *HTTPServer) GetDashboard(c *contextmodel.ReqContext) response.Response
|
|||||||
return response.Error(http.StatusInternalServerError, "Error while retrieving public dashboards", err)
|
return response.Error(http.StatusInternalServerError, "Error while retrieving public dashboards", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if publicDashboard != nil {
|
if publicDashboard != nil && (hs.License.FeatureEnabled(publicdashboardModels.FeaturePublicDashboardsEmailSharing) || publicDashboard.Share != publicdashboardModels.EmailShareType) {
|
||||||
publicDashboardEnabled = publicDashboard.IsEnabled
|
publicDashboardEnabled = publicDashboard.IsEnabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/guardian"
|
"github.com/grafana/grafana/pkg/services/guardian"
|
||||||
"github.com/grafana/grafana/pkg/services/libraryelements/model"
|
"github.com/grafana/grafana/pkg/services/libraryelements/model"
|
||||||
"github.com/grafana/grafana/pkg/services/librarypanels"
|
"github.com/grafana/grafana/pkg/services/librarypanels"
|
||||||
|
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
||||||
"github.com/grafana/grafana/pkg/services/live"
|
"github.com/grafana/grafana/pkg/services/live"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
||||||
@ -52,6 +53,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/provisioning"
|
"github.com/grafana/grafana/pkg/services/provisioning"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/api"
|
"github.com/grafana/grafana/pkg/services/publicdashboards/api"
|
||||||
|
publicdashboardModels "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/star/startest"
|
"github.com/grafana/grafana/pkg/services/star/startest"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
@ -272,7 +274,9 @@ func TestHTTPServer_DeleteDashboardByUID_AccessControl(t *testing.T) {
|
|||||||
pubDashService := publicdashboards.NewFakePublicDashboardService(t)
|
pubDashService := publicdashboards.NewFakePublicDashboardService(t)
|
||||||
pubDashService.On("DeleteByDashboard", mock.Anything, mock.Anything).Return(nil).Maybe()
|
pubDashService.On("DeleteByDashboard", mock.Anything, mock.Anything).Return(nil).Maybe()
|
||||||
middleware := publicdashboards.NewFakePublicDashboardMiddleware(t)
|
middleware := publicdashboards.NewFakePublicDashboardMiddleware(t)
|
||||||
hs.PublicDashboardsApi = api.ProvideApi(pubDashService, nil, hs.AccessControl, featuremgmt.WithFeatures(), middleware, hs.Cfg)
|
license := licensingtest.NewFakeLicensing()
|
||||||
|
license.On("FeatureEnabled", publicdashboardModels.FeaturePublicDashboardsEmailSharing).Return(false)
|
||||||
|
hs.PublicDashboardsApi = api.ProvideApi(pubDashService, nil, hs.AccessControl, featuremgmt.WithFeatures(), middleware, hs.Cfg, license)
|
||||||
|
|
||||||
guardian.InitAccessControlGuardian(hs.Cfg, hs.AccessControl, hs.DashboardService)
|
guardian.InitAccessControlGuardian(hs.Cfg, hs.AccessControl, hs.DashboardService)
|
||||||
})
|
})
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
|
"github.com/grafana/grafana/pkg/services/licensing"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/validation"
|
"github.com/grafana/grafana/pkg/services/publicdashboards/validation"
|
||||||
@ -28,6 +29,7 @@ type Api struct {
|
|||||||
accessControl accesscontrol.AccessControl
|
accessControl accesscontrol.AccessControl
|
||||||
cfg *setting.Cfg
|
cfg *setting.Cfg
|
||||||
features featuremgmt.FeatureToggles
|
features featuremgmt.FeatureToggles
|
||||||
|
license licensing.Licensing
|
||||||
log log.Logger
|
log log.Logger
|
||||||
routeRegister routing.RouteRegister
|
routeRegister routing.RouteRegister
|
||||||
}
|
}
|
||||||
@ -39,6 +41,7 @@ func ProvideApi(
|
|||||||
features featuremgmt.FeatureToggles,
|
features featuremgmt.FeatureToggles,
|
||||||
md publicdashboards.Middleware,
|
md publicdashboards.Middleware,
|
||||||
cfg *setting.Cfg,
|
cfg *setting.Cfg,
|
||||||
|
license licensing.Licensing,
|
||||||
) *Api {
|
) *Api {
|
||||||
api := &Api{
|
api := &Api{
|
||||||
PublicDashboardService: pd,
|
PublicDashboardService: pd,
|
||||||
@ -46,6 +49,7 @@ func ProvideApi(
|
|||||||
accessControl: ac,
|
accessControl: ac,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
features: features,
|
features: features,
|
||||||
|
license: license,
|
||||||
log: log.New("publicdashboards.api"),
|
log: log.New("publicdashboards.api"),
|
||||||
routeRegister: rr,
|
routeRegister: rr,
|
||||||
}
|
}
|
||||||
@ -158,8 +162,8 @@ func (api *Api) GetPublicDashboard(c *contextmodel.ReqContext) response.Response
|
|||||||
return response.Err(err)
|
return response.Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pd == nil {
|
if pd == nil || (!api.license.FeatureEnabled(FeaturePublicDashboardsEmailSharing) && pd.Share == EmailShareType) {
|
||||||
response.Err(ErrPublicDashboardNotFound.Errorf("GetPublicDashboard: public dashboard not found"))
|
return response.Err(ErrPublicDashboardNotFound.Errorf("GetPublicDashboard: public dashboard not found"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.JSON(http.StatusOK, pd)
|
return response.JSON(http.StatusOK, pd)
|
||||||
|
@ -26,10 +26,12 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/datasources/guardian"
|
"github.com/grafana/grafana/pkg/services/datasources/guardian"
|
||||||
datasourceService "github.com/grafana/grafana/pkg/services/datasources/service"
|
datasourceService "github.com/grafana/grafana/pkg/services/datasources/service"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
|
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
||||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
|
||||||
pluginSettings "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings/service"
|
pluginSettings "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings/service"
|
||||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
|
publicdashboardModels "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
"github.com/grafana/grafana/pkg/services/query"
|
"github.com/grafana/grafana/pkg/services/query"
|
||||||
fakeSecrets "github.com/grafana/grafana/pkg/services/secrets/fakes"
|
fakeSecrets "github.com/grafana/grafana/pkg/services/secrets/fakes"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
@ -73,7 +75,9 @@ func setupTestServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build api, this will mount the routes at the same time if the feature is enabled
|
// build api, this will mount the routes at the same time if the feature is enabled
|
||||||
ProvideApi(service, rr, ac, features, &Middleware{}, cfg)
|
license := licensingtest.NewFakeLicensing()
|
||||||
|
license.On("FeatureEnabled", publicdashboardModels.FeaturePublicDashboardsEmailSharing).Return(false)
|
||||||
|
ProvideApi(service, rr, ac, features, &Middleware{}, cfg, license)
|
||||||
|
|
||||||
// connect routes to mux
|
// connect routes to mux
|
||||||
rr.Register(m.Router)
|
rr.Register(m.Router)
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
||||||
|
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
publicdashboardsStore "github.com/grafana/grafana/pkg/services/publicdashboards/database"
|
publicdashboardsStore "github.com/grafana/grafana/pkg/services/publicdashboards/database"
|
||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
@ -331,7 +332,9 @@ func TestIntegrationUnauthenticatedUserCanGetPubdashPanelQueryData(t *testing.T)
|
|||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
pds := publicdashboardsService.ProvideService(cfg, store, qds, annotationsService, ac, ws, dashService)
|
license := licensingtest.NewFakeLicensing()
|
||||||
|
license.On("FeatureEnabled", FeaturePublicDashboardsEmailSharing).Return(false)
|
||||||
|
pds := publicdashboardsService.ProvideService(cfg, store, qds, annotationsService, ac, ws, dashService, license)
|
||||||
pubdash, err := pds.Create(context.Background(), &user.SignedInUser{}, savePubDashboardCmd)
|
pubdash, err := pds.Create(context.Background(), &user.SignedInUser{}, savePubDashboardCmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -24,10 +24,11 @@ func (e PublicDashboardErr) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
QuerySuccess = "success"
|
QuerySuccess = "success"
|
||||||
QueryFailure = "failure"
|
QueryFailure = "failure"
|
||||||
EmailShareType ShareType = "email"
|
EmailShareType ShareType = "email"
|
||||||
PublicShareType ShareType = "public"
|
PublicShareType ShareType = "public"
|
||||||
|
FeaturePublicDashboardsEmailSharing = "publicDashboardsEmailSharing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
51
pkg/services/publicdashboards/service/common_test.go
Normal file
51
pkg/services/publicdashboards/service/common_test.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
|
"github.com/grafana/grafana/pkg/services/annotations"
|
||||||
|
"github.com/grafana/grafana/pkg/services/annotations/annotationsimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
|
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
||||||
|
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
|
"github.com/grafana/grafana/pkg/services/publicdashboards/database"
|
||||||
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
|
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newPublicDashboardServiceImpl(
|
||||||
|
t *testing.T,
|
||||||
|
publicDashboardStore publicdashboards.Store,
|
||||||
|
dashboardService dashboards.DashboardService,
|
||||||
|
annotationsRepo annotations.Repository,
|
||||||
|
) (*PublicDashboardServiceImpl, *sqlstore.SQLStore) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
|
tagService := tagimpl.ProvideService(sqlStore)
|
||||||
|
if annotationsRepo == nil {
|
||||||
|
annotationsRepo = annotationsimpl.ProvideService(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagService)
|
||||||
|
}
|
||||||
|
|
||||||
|
if publicDashboardStore == nil {
|
||||||
|
publicDashboardStore = database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
||||||
|
}
|
||||||
|
serviceWrapper := ProvideServiceWrapper(publicDashboardStore)
|
||||||
|
|
||||||
|
license := licensingtest.NewFakeLicensing()
|
||||||
|
license.On("FeatureEnabled", FeaturePublicDashboardsEmailSharing).Return(false)
|
||||||
|
|
||||||
|
return &PublicDashboardServiceImpl{
|
||||||
|
AnnotationsRepo: annotationsRepo,
|
||||||
|
log: log.New("test.logger"),
|
||||||
|
intervalCalculator: intervalv2.NewCalculator(),
|
||||||
|
dashboardService: dashboardService,
|
||||||
|
store: publicDashboardStore,
|
||||||
|
serviceWrapper: serviceWrapper,
|
||||||
|
license: license,
|
||||||
|
}, sqlStore
|
||||||
|
}
|
@ -12,23 +12,17 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/infra/db"
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
|
||||||
dashboard2 "github.com/grafana/grafana/pkg/kinds/dashboard"
|
dashboard2 "github.com/grafana/grafana/pkg/kinds/dashboard"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations"
|
"github.com/grafana/grafana/pkg/services/annotations"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations/annotationsimpl"
|
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
dashboardsDB "github.com/grafana/grafana/pkg/services/dashboards/database"
|
dashboardsDB "github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/database"
|
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/internal"
|
"github.com/grafana/grafana/pkg/services/publicdashboards/internal"
|
||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
|
||||||
"github.com/grafana/grafana/pkg/services/query"
|
"github.com/grafana/grafana/pkg/services/query"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
|
||||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
|
|
||||||
@ -682,23 +676,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGetQueryDataResponse(t *testing.T) {
|
func TestGetQueryDataResponse(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
fakeQueryService := &query.FakeQueryService{}
|
fakeQueryService := &query.FakeQueryService{}
|
||||||
fakeQueryService.On("QueryData", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&backend.QueryDataResponse{}, nil)
|
fakeQueryService.On("QueryData", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&backend.QueryDataResponse{}, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
service.QueryDataService = fakeQueryService
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||||
log: log.New("test.logger"),
|
require.NoError(t, err)
|
||||||
store: publicdashboardStore,
|
|
||||||
intervalCalculator: intervalv2.NewCalculator(),
|
|
||||||
QueryDataService: fakeQueryService,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
publicDashboardQueryDTO := PublicDashboardQueryDTO{
|
publicDashboardQueryDTO := PublicDashboardQueryDTO{
|
||||||
IntervalMs: int64(1),
|
IntervalMs: int64(1),
|
||||||
@ -748,21 +733,12 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
color := "red"
|
color := "red"
|
||||||
name := "annoName"
|
name := "annoName"
|
||||||
t.Run("will build anonymous user with correct permissions to get annotations", func(t *testing.T) {
|
t.Run("will build anonymous user with correct permissions to get annotations", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
config := setting.NewCfg()
|
|
||||||
tagService := tagimpl.ProvideService(sqlStore)
|
|
||||||
annotationsRepo := annotationsimpl.ProvideService(sqlStore, config, featuremgmt.WithFeatures(), tagService)
|
|
||||||
fakeStore := FakePublicDashboardStore{}
|
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).
|
||||||
Return(&PublicDashboard{Uid: "uid1", IsEnabled: true}, nil)
|
Return(&PublicDashboard{Uid: "uid1", IsEnabled: true}, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboards.NewDashboard("dash1"), nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboards.NewDashboard("dash1"), nil)
|
||||||
service := &PublicDashboardServiceImpl{
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
AnnotationsRepo: annotationsRepo,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
reqDTO := AnnotationsQueryDTO{
|
reqDTO := AnnotationsQueryDTO{
|
||||||
From: 1,
|
From: 1,
|
||||||
@ -807,20 +783,15 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
annos := []DashAnnotation{grafanaAnnotation, grafanaTagAnnotation}
|
annos := []DashAnnotation{grafanaAnnotation, grafanaTagAnnotation}
|
||||||
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
||||||
|
|
||||||
annotationsRepo := annotations.FakeAnnotationsRepo{}
|
|
||||||
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
||||||
|
|
||||||
fakeStore := FakePublicDashboardStore{}
|
annotationsRepo := &annotations.FakeAnnotationsRepo{}
|
||||||
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
AnnotationsRepo: &annotationsRepo,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||||
{
|
{
|
||||||
@ -870,19 +841,14 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
annos := []DashAnnotation{grafanaAnnotation}
|
annos := []DashAnnotation{grafanaAnnotation}
|
||||||
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
||||||
|
|
||||||
annotationsRepo := annotations.FakeAnnotationsRepo{}
|
annotationsRepo := &annotations.FakeAnnotationsRepo{}
|
||||||
fakeStore := FakePublicDashboardStore{}
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
AnnotationsRepo: &annotationsRepo,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||||
{
|
{
|
||||||
@ -944,19 +910,14 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
annos := []DashAnnotation{grafanaAnnotation, queryAnnotation, disabledGrafanaAnnotation}
|
annos := []DashAnnotation{grafanaAnnotation, queryAnnotation, disabledGrafanaAnnotation}
|
||||||
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
||||||
|
|
||||||
annotationsRepo := annotations.FakeAnnotationsRepo{}
|
annotationsRepo := &annotations.FakeAnnotationsRepo{}
|
||||||
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
||||||
fakeStore := FakePublicDashboardStore{}
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
AnnotationsRepo: &annotationsRepo,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||||
{
|
{
|
||||||
@ -990,19 +951,13 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("test will return nothing when dashboard has no annotations", func(t *testing.T) {
|
t.Run("test will return nothing when dashboard has no annotations", func(t *testing.T) {
|
||||||
annotationsRepo := annotations.FakeAnnotationsRepo{}
|
|
||||||
dashboard := dashboards.NewDashboard("dashWithNoAnnotations")
|
dashboard := dashboards.NewDashboard("dashWithNoAnnotations")
|
||||||
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
||||||
fakeStore := FakePublicDashboardStore{}
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
service := &PublicDashboardServiceImpl{
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
AnnotationsRepo: &annotationsRepo,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||||
|
|
||||||
@ -1028,17 +983,11 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
annos := []DashAnnotation{grafanaAnnotation}
|
annos := []DashAnnotation{grafanaAnnotation}
|
||||||
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
||||||
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: false}
|
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: false}
|
||||||
annotationsRepo := annotations.FakeAnnotationsRepo{}
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
fakeStore := FakePublicDashboardStore{}
|
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
service := &PublicDashboardServiceImpl{
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
AnnotationsRepo: &annotationsRepo,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||||
|
|
||||||
@ -1060,23 +1009,17 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
dash := dashboards.NewDashboard("test")
|
dash := dashboards.NewDashboard("test")
|
||||||
annotationsRepo := annotations.FakeAnnotationsRepo{}
|
annotationsRepo := &annotations.FakeAnnotationsRepo{}
|
||||||
|
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return(nil, errors.New("failed")).Maybe()
|
||||||
annos := []DashAnnotation{grafanaAnnotation}
|
annos := []DashAnnotation{grafanaAnnotation}
|
||||||
dash = AddAnnotationsToDashboard(t, dash, annos)
|
dash = AddAnnotationsToDashboard(t, dash, annos)
|
||||||
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dash.UID, AnnotationsEnabled: true}
|
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dash.UID, AnnotationsEnabled: true}
|
||||||
fakeStore := FakePublicDashboardStore{}
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dash, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dash, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
AnnotationsRepo: &annotationsRepo,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return(nil, errors.New("failed")).Maybe()
|
|
||||||
|
|
||||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||||
|
|
||||||
@ -1099,12 +1042,12 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
dashboard := AddAnnotationsToDashboard(t, dash, annos)
|
||||||
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
pubdash := &PublicDashboard{Uid: "uid1", IsEnabled: true, OrgId: 1, DashboardUid: dashboard.UID, AnnotationsEnabled: true}
|
||||||
|
|
||||||
fakeStore := FakePublicDashboardStore{}
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
annotationsRepo := annotations.FakeAnnotationsRepo{}
|
annotationsRepo := &annotations.FakeAnnotationsRepo{}
|
||||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||||
{
|
{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
@ -1117,12 +1060,7 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}, nil).Maybe()
|
}, nil).Maybe()
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
AnnotationsRepo: &annotationsRepo,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||||
|
|
||||||
@ -1145,22 +1083,17 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetMetricRequest(t *testing.T) {
|
func TestGetMetricRequest(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, nil, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||||
|
|
||||||
publicDashboard := &PublicDashboard{
|
publicDashboard := &PublicDashboard{
|
||||||
Uid: "1",
|
Uid: "1",
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
IsEnabled: true,
|
IsEnabled: true,
|
||||||
AccessToken: "abc123",
|
AccessToken: "abc123",
|
||||||
}
|
}
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
intervalCalculator: intervalv2.NewCalculator(),
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("will return an error when validation fails", func(t *testing.T) {
|
t.Run("will return an error when validation fails", func(t *testing.T) {
|
||||||
publicDashboardQueryDTO := PublicDashboardQueryDTO{
|
publicDashboardQueryDTO := PublicDashboardQueryDTO{
|
||||||
@ -1230,24 +1163,16 @@ func TestGetUniqueDashboardDatasourceUids(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildMetricRequest(t *testing.T) {
|
func TestBuildMetricRequest(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
publicDashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
publicDashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||||
nonPublicDashboard := insertTestDashboard(t, dashboardStore, "testNonPublicDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
nonPublicDashboard := insertTestDashboard(t, dashboardStore, "testNonPublicDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(publicDashboard, nil)
|
|
||||||
from, to := internal.GetTimeRangeFromDashboard(t, publicDashboard.Data)
|
from, to := internal.GetTimeRangeFromDashboard(t, publicDashboard.Data)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(publicDashboard, nil)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
intervalCalculator: intervalv2.NewCalculator(),
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
publicDashboardQueryDTO := PublicDashboardQueryDTO{
|
publicDashboardQueryDTO := PublicDashboardQueryDTO{
|
||||||
IntervalMs: int64(10000000),
|
IntervalMs: int64(10000000),
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations"
|
"github.com/grafana/grafana/pkg/services/annotations"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
|
"github.com/grafana/grafana/pkg/services/licensing"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
||||||
@ -38,6 +39,7 @@ type PublicDashboardServiceImpl struct {
|
|||||||
ac accesscontrol.AccessControl
|
ac accesscontrol.AccessControl
|
||||||
serviceWrapper publicdashboards.ServiceWrapper
|
serviceWrapper publicdashboards.ServiceWrapper
|
||||||
dashboardService dashboards.DashboardService
|
dashboardService dashboards.DashboardService
|
||||||
|
license licensing.Licensing
|
||||||
}
|
}
|
||||||
|
|
||||||
var LogPrefix = "publicdashboards.service"
|
var LogPrefix = "publicdashboards.service"
|
||||||
@ -56,6 +58,7 @@ func ProvideService(
|
|||||||
ac accesscontrol.AccessControl,
|
ac accesscontrol.AccessControl,
|
||||||
serviceWrapper publicdashboards.ServiceWrapper,
|
serviceWrapper publicdashboards.ServiceWrapper,
|
||||||
dashboardService dashboards.DashboardService,
|
dashboardService dashboards.DashboardService,
|
||||||
|
license licensing.Licensing,
|
||||||
) *PublicDashboardServiceImpl {
|
) *PublicDashboardServiceImpl {
|
||||||
return &PublicDashboardServiceImpl{
|
return &PublicDashboardServiceImpl{
|
||||||
log: log.New(LogPrefix),
|
log: log.New(LogPrefix),
|
||||||
@ -67,6 +70,7 @@ func ProvideService(
|
|||||||
ac: ac,
|
ac: ac,
|
||||||
serviceWrapper: serviceWrapper,
|
serviceWrapper: serviceWrapper,
|
||||||
dashboardService: dashboardService,
|
dashboardService: dashboardService,
|
||||||
|
license: license,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +158,10 @@ func (pd *PublicDashboardServiceImpl) FindEnabledPublicDashboardAndDashboardByAc
|
|||||||
return nil, nil, ErrPublicDashboardNotEnabled.Errorf("FindEnabledPublicDashboardAndDashboardByAccessToken: Public dashboard is not enabled accessToken: %s", accessToken)
|
return nil, nil, ErrPublicDashboardNotEnabled.Errorf("FindEnabledPublicDashboardAndDashboardByAccessToken: Public dashboard is not enabled accessToken: %s", accessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !pd.license.FeatureEnabled(FeaturePublicDashboardsEmailSharing) && pubdash.Share == EmailShareType {
|
||||||
|
return nil, nil, ErrPublicDashboardNotFound.Errorf("FindEnabledPublicDashboardAndDashboardByAccessToken: Dashboard not found accessToken: %s", accessToken)
|
||||||
|
}
|
||||||
|
|
||||||
return pubdash, dash, err
|
return pubdash, dash, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +205,12 @@ func (pd *PublicDashboardServiceImpl) Create(ctx context.Context, u *user.Signed
|
|||||||
}
|
}
|
||||||
|
|
||||||
if existingPubdash != nil {
|
if existingPubdash != nil {
|
||||||
|
// If there is no license and the public dashboard was email-shared, we should update it to public
|
||||||
|
if !pd.license.FeatureEnabled(FeaturePublicDashboardsEmailSharing) && existingPubdash.Share == EmailShareType {
|
||||||
|
dto.Uid = existingPubdash.Uid
|
||||||
|
dto.PublicDashboard.Share = PublicShareType
|
||||||
|
return pd.Update(ctx, u, dto)
|
||||||
|
}
|
||||||
return nil, ErrDashboardIsPublic.Errorf("Create: public dashboard for dashboard %s already exists", dto.DashboardUid)
|
return nil, ErrDashboardIsPublic.Errorf("Create: public dashboard for dashboard %s already exists", dto.DashboardUid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,14 +16,11 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/infra/db"
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
dashboardsDB "github.com/grafana/grafana/pkg/services/dashboards/database"
|
dashboardsDB "github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/database"
|
|
||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/validation"
|
"github.com/grafana/grafana/pkg/services/publicdashboards/validation"
|
||||||
@ -386,16 +383,11 @@ func TestGetPublicDashboardForView(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
t.Run(test.Name, func(t *testing.T) {
|
t.Run(test.Name, func(t *testing.T) {
|
||||||
fakeStore := FakePublicDashboardStore{}
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
||||||
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
||||||
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
dashboardFullWithMeta, err := service.GetPublicDashboardForView(context.Background(), test.AccessToken)
|
dashboardFullWithMeta, err := service.GetPublicDashboardForView(context.Background(), test.AccessToken)
|
||||||
if test.ErrResp != nil {
|
if test.ErrResp != nil {
|
||||||
@ -501,15 +493,10 @@ func TestGetPublicDashboard(t *testing.T) {
|
|||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
t.Run(test.Name, func(t *testing.T) {
|
t.Run(test.Name, func(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeStore := FakePublicDashboardStore{}
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
||||||
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
||||||
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
pdc, dash, err := service.FindPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
pdc, dash, err := service.FindPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
||||||
if test.ErrResp != nil {
|
if test.ErrResp != nil {
|
||||||
@ -568,16 +555,11 @@ func TestGetEnabledPublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
t.Run(test.Name, func(t *testing.T) {
|
t.Run(test.Name, func(t *testing.T) {
|
||||||
fakeStore := FakePublicDashboardStore{}
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: &fakeStore,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
||||||
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
||||||
|
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
pdc, dash, err := service.FindEnabledPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
pdc, dash, err := service.FindEnabledPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
||||||
if test.ErrResp != nil {
|
if test.ErrResp != nil {
|
||||||
@ -600,24 +582,15 @@ func TestGetEnabledPublicDashboard(t *testing.T) {
|
|||||||
// the correct order is convoluted.
|
// the correct order is convoluted.
|
||||||
func TestCreatePublicDashboard(t *testing.T) {
|
func TestCreatePublicDashboard(t *testing.T) {
|
||||||
t.Run("Create public dashboard", func(t *testing.T) {
|
t.Run("Create public dashboard", func(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
|
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled, annotationsEnabled, timeSelectionEnabled := true, false, true
|
isEnabled, annotationsEnabled, timeSelectionEnabled := true, false, true
|
||||||
|
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
@ -690,23 +663,14 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range testCases {
|
for _, tt := range testCases {
|
||||||
t.Run(fmt.Sprintf("Create public dashboard with %s null boolean fields stores them as false", tt.Name), func(t *testing.T) {
|
t.Run(fmt.Sprintf("Create public dashboard with %s null boolean fields stores them as false", tt.Name), func(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
UserId: 7,
|
UserId: 7,
|
||||||
@ -731,24 +695,14 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Validate pubdash has default time setting value", func(t *testing.T) {
|
t.Run("Validate pubdash has default time setting value", func(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
|
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
@ -768,24 +722,16 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Creates pubdash whose dashboard has template variables successfully", func(t *testing.T) {
|
t.Run("Creates pubdash whose dashboard has template variables successfully", func(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
templateVars := make([]map[string]any, 1)
|
templateVars := make([]map[string]any, 1)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, templateVars, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, templateVars, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
@ -823,14 +769,7 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
serviceWrapper := ProvideServiceWrapper(publicDashboardStore)
|
service, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicDashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
@ -849,23 +788,14 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Create public dashboard with given pubdash uid", func(t *testing.T) {
|
t.Run("Create public dashboard with given pubdash uid", func(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled := true
|
isEnabled := true
|
||||||
|
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
@ -905,14 +835,7 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
publicDashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(nil, ErrPublicDashboardNotFound.Errorf(""))
|
publicDashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(nil, ErrPublicDashboardNotFound.Errorf(""))
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicDashboardStore)
|
service, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicDashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
@ -931,23 +854,14 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Create public dashboard with given pubdash access token", func(t *testing.T) {
|
t.Run("Create public dashboard with given pubdash access token", func(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled := true
|
isEnabled := true
|
||||||
|
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
@ -981,14 +895,7 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
publicDashboardStore := &FakePublicDashboardStore{}
|
publicDashboardStore := &FakePublicDashboardStore{}
|
||||||
publicDashboardStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(pubdash, nil)
|
publicDashboardStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(pubdash, nil)
|
||||||
|
service, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, nil, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicDashboardStore)
|
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicDashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := service.NewPublicDashboardAccessToken(context.Background())
|
_, err := service.NewPublicDashboardAccessToken(context.Background())
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
@ -996,25 +903,16 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Returns error if public dashboard exists", func(t *testing.T) {
|
t.Run("Returns error if public dashboard exists", func(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
|
||||||
|
|
||||||
publicdashboardStore := &FakePublicDashboardStore{}
|
publicdashboardStore := &FakePublicDashboardStore{}
|
||||||
publicdashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(&PublicDashboard{Uid: "newPubdashUid"}, nil)
|
publicdashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(&PublicDashboard{Uid: "newPubdashUid"}, nil)
|
||||||
publicdashboardStore.On("Find", mock.Anything, mock.Anything).Return(nil, nil)
|
publicdashboardStore.On("Find", mock.Anything, mock.Anything).Return(nil, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
service, sqlStore := newPublicDashboardServiceImpl(t, publicdashboardStore, fakeDashboardService, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||||
log: log.New("test.logger"),
|
require.NoError(t, err)
|
||||||
store: publicdashboardStore,
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
serviceWrapper: serviceWrapper,
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled, annotationsEnabled := true, false
|
isEnabled, annotationsEnabled := true, false
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
@ -1033,23 +931,15 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Validate pubdash has default share value", func(t *testing.T) {
|
t.Run("Validate pubdash has default share value", func(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
@ -1079,22 +969,15 @@ func assertFalseIfNull(t *testing.T, expectedValue bool, nullableValue *bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatePublicDashboard(t *testing.T) {
|
func TestUpdatePublicDashboard(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
dashboard2 := insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard2 := insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("Updating public dashboard", func(t *testing.T) {
|
t.Run("Updating public dashboard", func(t *testing.T) {
|
||||||
isEnabled, annotationsEnabled, timeSelectionEnabled := true, false, false
|
isEnabled, annotationsEnabled, timeSelectionEnabled := true, false, false
|
||||||
@ -1269,23 +1152,15 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range testCases {
|
for _, tt := range testCases {
|
||||||
t.Run(fmt.Sprintf("Update public dashboard with %s null boolean fields let those fields with old persisted value", tt.Name), func(t *testing.T) {
|
t.Run(fmt.Sprintf("Update public dashboard with %s null boolean fields let those fields with old persisted value", tt.Name), func(t *testing.T) {
|
||||||
sqlStore := db.InitTestDB(t)
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
|
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
|
||||||
serviceWrapper := ProvideServiceWrapper(publicdashboardStore)
|
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: publicdashboardStore,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
dashboardService: fakeDashboardService,
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled, annotationsEnabled, timeSelectionEnabled := true, true, false
|
isEnabled, annotationsEnabled, timeSelectionEnabled := true, true, false
|
||||||
|
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
@ -1398,15 +1273,7 @@ func TestDeletePublicDashboard(t *testing.T) {
|
|||||||
if tt.ExpectedErrResp == nil || tt.mockDeleteStore.StoreRespErr != nil {
|
if tt.ExpectedErrResp == nil || tt.mockDeleteStore.StoreRespErr != nil {
|
||||||
store.On("Delete", mock.Anything, mock.Anything).Return(tt.mockDeleteStore.AffectedRowsResp, tt.mockDeleteStore.StoreRespErr)
|
store.On("Delete", mock.Anything, mock.Anything).Return(tt.mockDeleteStore.AffectedRowsResp, tt.mockDeleteStore.StoreRespErr)
|
||||||
}
|
}
|
||||||
serviceWrapper := &PublicDashboardServiceWrapperImpl{
|
service, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: store,
|
|
||||||
}
|
|
||||||
service := &PublicDashboardServiceImpl{
|
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: store,
|
|
||||||
serviceWrapper: serviceWrapper,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := service.Delete(context.Background(), "pubdashUID", "uid")
|
err := service.Delete(context.Background(), "pubdashUID", "uid")
|
||||||
if tt.ExpectedErrResp != nil {
|
if tt.ExpectedErrResp != nil {
|
||||||
@ -1623,12 +1490,8 @@ func TestPublicDashboardServiceImpl_ListPublicDashboards(t *testing.T) {
|
|||||||
store := NewFakePublicDashboardStore(t)
|
store := NewFakePublicDashboardStore(t)
|
||||||
store.On("FindAllWithPagination", mock.Anything, mock.Anything).
|
store.On("FindAllWithPagination", mock.Anything, mock.Anything).
|
||||||
Return(tt.mockResponse.PublicDashboardListResponseWithPagination, tt.mockResponse.Err)
|
Return(tt.mockResponse.PublicDashboardListResponseWithPagination, tt.mockResponse.Err)
|
||||||
|
pd, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
||||||
pd := &PublicDashboardServiceImpl{
|
pd.ac = ac
|
||||||
log: log.New("test.logger"),
|
|
||||||
store: store,
|
|
||||||
ac: ac,
|
|
||||||
}
|
|
||||||
|
|
||||||
got, err := pd.FindAllWithPagination(tt.args.ctx, tt.args.query)
|
got, err := pd.FindAllWithPagination(tt.args.ctx, tt.args.query)
|
||||||
if !tt.wantErr(t, err, fmt.Sprintf("FindAllWithPagination(%v, %v)", tt.args.ctx, tt.args.query)) {
|
if !tt.wantErr(t, err, fmt.Sprintf("FindAllWithPagination(%v, %v)", tt.args.ctx, tt.args.query)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user