2022-03-03 15:05:47 +01:00
|
|
|
package guardian
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
2023-08-30 16:51:18 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/auth/identity"
|
2022-05-17 14:52:22 -04:00
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
2023-07-25 15:31:12 +03:00
|
|
|
"github.com/grafana/grafana/pkg/services/folder"
|
2022-09-20 18:58:04 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/team"
|
2023-03-16 09:54:01 +00:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2022-03-03 15:05:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Provider struct{}
|
|
|
|
|
|
2022-05-10 15:48:47 +02:00
|
|
|
func ProvideService(
|
2023-08-30 10:14:17 +02:00
|
|
|
cfg *setting.Cfg, ac accesscontrol.AccessControl,
|
2022-09-20 18:58:04 +02:00
|
|
|
dashboardService dashboards.DashboardService, teamService team.Service,
|
2022-05-10 15:48:47 +02:00
|
|
|
) *Provider {
|
2023-08-30 10:14:17 +02:00
|
|
|
// TODO: Fix this hack, see https://github.com/grafana/grafana-enterprise/issues/2935
|
|
|
|
|
InitAccessControlGuardian(cfg, ac, dashboardService)
|
2022-03-03 15:05:47 +01:00
|
|
|
return &Provider{}
|
|
|
|
|
}
|
2022-03-21 10:49:49 +01:00
|
|
|
|
2022-05-10 15:48:47 +02:00
|
|
|
func InitAccessControlGuardian(
|
2023-08-28 09:49:10 +02:00
|
|
|
cfg *setting.Cfg, ac accesscontrol.AccessControl, dashboardService dashboards.DashboardService,
|
2022-05-10 15:48:47 +02:00
|
|
|
) {
|
2023-08-30 16:51:18 +02:00
|
|
|
New = func(ctx context.Context, dashId int64, orgId int64, user identity.Requester) (DashboardGuardian, error) {
|
2023-08-28 09:49:10 +02:00
|
|
|
return NewAccessControlDashboardGuardian(ctx, cfg, dashId, user, ac, dashboardService)
|
2022-03-21 10:49:49 +01:00
|
|
|
}
|
2022-12-15 16:34:17 +02:00
|
|
|
|
2023-08-30 16:51:18 +02:00
|
|
|
NewByUID = func(ctx context.Context, dashUID string, orgId int64, user identity.Requester) (DashboardGuardian, error) {
|
2023-08-28 09:49:10 +02:00
|
|
|
return NewAccessControlDashboardGuardianByUID(ctx, cfg, dashUID, user, ac, dashboardService)
|
2022-12-15 16:34:17 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-30 16:51:18 +02:00
|
|
|
NewByDashboard = func(ctx context.Context, dash *dashboards.Dashboard, orgId int64, user identity.Requester) (DashboardGuardian, error) {
|
2023-08-28 09:49:10 +02:00
|
|
|
return NewAccessControlDashboardGuardianByDashboard(ctx, cfg, dash, user, ac, dashboardService)
|
2022-12-15 16:34:17 +02:00
|
|
|
}
|
2023-07-25 15:31:12 +03:00
|
|
|
|
2023-08-30 16:51:18 +02:00
|
|
|
NewByFolder = func(ctx context.Context, f *folder.Folder, orgId int64, user identity.Requester) (DashboardGuardian, error) {
|
2023-08-28 09:49:10 +02:00
|
|
|
return NewAccessControlFolderGuardian(ctx, cfg, f, user, ac, dashboardService)
|
2023-07-25 15:31:12 +03:00
|
|
|
}
|
2022-03-21 10:49:49 +01:00
|
|
|
}
|