mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 19:30:36 -06:00
2edfbb7767
* backend/sqlstore split: remove unused GetDashboardPermissionsForUser from sqlstore * remove debugging line * backend/sqlstore: move dashboard permission related functions to dashboard service
42 lines
1.6 KiB
Go
42 lines
1.6 KiB
Go
package guardian
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
)
|
|
|
|
type Provider struct{}
|
|
|
|
func ProvideService(
|
|
store *sqlstore.SQLStore, ac accesscontrol.AccessControl,
|
|
folderPermissionsService accesscontrol.FolderPermissionsService, dashboardPermissionsService accesscontrol.DashboardPermissionsService,
|
|
dashboardService dashboards.DashboardService,
|
|
) *Provider {
|
|
if !ac.IsDisabled() {
|
|
// TODO: Fix this hack, see https://github.com/grafana/grafana-enterprise/issues/2935
|
|
InitAccessControlGuardian(store, ac, folderPermissionsService, dashboardPermissionsService, dashboardService)
|
|
} else {
|
|
InitLegacyGuardian(store, dashboardService)
|
|
}
|
|
return &Provider{}
|
|
}
|
|
|
|
func InitLegacyGuardian(store sqlstore.Store, dashSvc dashboards.DashboardService) {
|
|
New = func(ctx context.Context, dashId int64, orgId int64, user *models.SignedInUser) DashboardGuardian {
|
|
return newDashboardGuardian(ctx, dashId, orgId, user, store, dashSvc)
|
|
}
|
|
}
|
|
|
|
func InitAccessControlGuardian(
|
|
store sqlstore.Store, ac accesscontrol.AccessControl, folderPermissionsService accesscontrol.FolderPermissionsService,
|
|
dashboardPermissionsService accesscontrol.DashboardPermissionsService, dashboardService dashboards.DashboardService,
|
|
) {
|
|
New = func(ctx context.Context, dashId int64, orgId int64, user *models.SignedInUser) DashboardGuardian {
|
|
return NewAccessControlDashboardGuardian(ctx, dashId, user, store, ac, folderPermissionsService, dashboardPermissionsService, dashboardService)
|
|
}
|
|
}
|