backend/services: Move GetDashboard from sqlstore to dashboard service (#48971)
* rename folder to match package name * backend/sqlstore: move GetDashboard into DashboardService This is a stepping-stone commit which copies the GetDashboard function - which lets us remove the sqlstore from the interfaces in dashboards - without changing any other callers. * checkpoint: moving GetDashboard calls into dashboard service * finish refactoring api tests for dashboardService.GetDashboard
This commit is contained in:
@@ -7,24 +7,28 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/annotations"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
)
|
||||
|
||||
type PermissionChecker struct {
|
||||
sqlStore *sqlstore.SQLStore
|
||||
features featuremgmt.FeatureToggles
|
||||
accessControl accesscontrol.AccessControl
|
||||
sqlStore *sqlstore.SQLStore
|
||||
features featuremgmt.FeatureToggles
|
||||
accessControl accesscontrol.AccessControl
|
||||
dashboardService dashboards.DashboardService
|
||||
}
|
||||
|
||||
func NewPermissionChecker(sqlStore *sqlstore.SQLStore, features featuremgmt.FeatureToggles, accessControl accesscontrol.AccessControl) *PermissionChecker {
|
||||
func NewPermissionChecker(sqlStore *sqlstore.SQLStore, features featuremgmt.FeatureToggles,
|
||||
accessControl accesscontrol.AccessControl, dashboardService dashboards.DashboardService,
|
||||
) *PermissionChecker {
|
||||
return &PermissionChecker{sqlStore: sqlStore, features: features, accessControl: accessControl}
|
||||
}
|
||||
|
||||
func (c *PermissionChecker) getDashboardByUid(ctx context.Context, orgID int64, uid string) (*models.Dashboard, error) {
|
||||
query := models.GetDashboardQuery{Uid: uid, OrgId: orgID}
|
||||
if err := c.sqlStore.GetDashboard(ctx, &query); err != nil {
|
||||
if err := c.dashboardService.GetDashboard(ctx, &query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return query.Result, nil
|
||||
@@ -32,7 +36,7 @@ func (c *PermissionChecker) getDashboardByUid(ctx context.Context, orgID int64,
|
||||
|
||||
func (c *PermissionChecker) getDashboardById(ctx context.Context, orgID int64, id int64) (*models.Dashboard, error) {
|
||||
query := models.GetDashboardQuery{Id: id, OrgId: orgID}
|
||||
if err := c.sqlStore.GetDashboard(ctx, &query); err != nil {
|
||||
if err := c.dashboardService.GetDashboard(ctx, &query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return query.Result, nil
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/comments/commentmodel"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/live"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
@@ -19,7 +20,9 @@ type Service struct {
|
||||
permissions *commentmodel.PermissionChecker
|
||||
}
|
||||
|
||||
func ProvideService(cfg *setting.Cfg, store *sqlstore.SQLStore, live *live.GrafanaLive, features featuremgmt.FeatureToggles, accessControl accesscontrol.AccessControl) *Service {
|
||||
func ProvideService(cfg *setting.Cfg, store *sqlstore.SQLStore, live *live.GrafanaLive,
|
||||
features featuremgmt.FeatureToggles, accessControl accesscontrol.AccessControl,
|
||||
dashboardService dashboards.DashboardService) *Service {
|
||||
s := &Service{
|
||||
cfg: cfg,
|
||||
live: live,
|
||||
@@ -27,7 +30,7 @@ func ProvideService(cfg *setting.Cfg, store *sqlstore.SQLStore, live *live.Grafa
|
||||
storage: &sqlStorage{
|
||||
sql: store,
|
||||
},
|
||||
permissions: commentmodel.NewPermissionChecker(store, features, accessControl),
|
||||
permissions: commentmodel.NewPermissionChecker(store, features, accessControl, dashboardService),
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user