2022-03-03 08:05:47 -06:00
|
|
|
package guardian
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
2022-05-17 13:52:22 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
2022-03-03 08:05:47 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Provider struct{}
|
|
|
|
|
2022-05-10 08:48:47 -05:00
|
|
|
func ProvideService(
|
|
|
|
store *sqlstore.SQLStore, ac accesscontrol.AccessControl,
|
|
|
|
folderPermissionsService accesscontrol.FolderPermissionsService, dashboardPermissionsService accesscontrol.DashboardPermissionsService,
|
2022-05-17 13:52:22 -05:00
|
|
|
dashboardService dashboards.DashboardService,
|
2022-05-10 08:48:47 -05:00
|
|
|
) *Provider {
|
2022-04-25 03:42:09 -05:00
|
|
|
if !ac.IsDisabled() {
|
2022-03-03 08:05:47 -06:00
|
|
|
// TODO: Fix this hack, see https://github.com/grafana/grafana-enterprise/issues/2935
|
2022-05-17 13:52:22 -05:00
|
|
|
InitAccessControlGuardian(store, ac, folderPermissionsService, dashboardPermissionsService, dashboardService)
|
2022-03-21 04:49:49 -05:00
|
|
|
} else {
|
2022-06-01 13:16:26 -05:00
|
|
|
InitLegacyGuardian(store, dashboardService)
|
2022-03-03 08:05:47 -06:00
|
|
|
}
|
|
|
|
return &Provider{}
|
|
|
|
}
|
2022-03-21 04:49:49 -05:00
|
|
|
|
2022-06-01 13:16:26 -05:00
|
|
|
func InitLegacyGuardian(store sqlstore.Store, dashSvc dashboards.DashboardService) {
|
2022-03-21 04:49:49 -05:00
|
|
|
New = func(ctx context.Context, dashId int64, orgId int64, user *models.SignedInUser) DashboardGuardian {
|
2022-06-01 13:16:26 -05:00
|
|
|
return newDashboardGuardian(ctx, dashId, orgId, user, store, dashSvc)
|
2022-03-21 04:49:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 08:48:47 -05:00
|
|
|
func InitAccessControlGuardian(
|
|
|
|
store sqlstore.Store, ac accesscontrol.AccessControl, folderPermissionsService accesscontrol.FolderPermissionsService,
|
2022-05-17 13:52:22 -05:00
|
|
|
dashboardPermissionsService accesscontrol.DashboardPermissionsService, dashboardService dashboards.DashboardService,
|
2022-05-10 08:48:47 -05:00
|
|
|
) {
|
2022-03-21 04:49:49 -05:00
|
|
|
New = func(ctx context.Context, dashId int64, orgId int64, user *models.SignedInUser) DashboardGuardian {
|
2022-05-17 13:52:22 -05:00
|
|
|
return NewAccessControlDashboardGuardian(ctx, dashId, user, store, ac, folderPermissionsService, dashboardPermissionsService, dashboardService)
|
2022-03-21 04:49:49 -05:00
|
|
|
}
|
|
|
|
}
|