[release-12.0.0] Access control: Make sure that user permission cache is cleared after new dashboard and folder creation (#104494)
Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
This commit is contained in:
co-authored by
Ieva
parent
238ea51922
commit
255df4e4a3
@@ -536,12 +536,6 @@ func (hs *HTTPServer) postDashboard(c *contextmodel.ReqContext, cmd dashboards.S
|
|||||||
return apierrors.ToDashboardErrorResponse(ctx, hs.pluginStore, saveErr)
|
return apierrors.ToDashboardErrorResponse(ctx, hs.pluginStore, saveErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear permission cache for the user who's created the dashboard, so that new permissions are fetched for their next call
|
|
||||||
// Required for cases when caller wants to immediately interact with the newly created object
|
|
||||||
if newDashboard {
|
|
||||||
hs.accesscontrolService.ClearUserPermissionCache(c.SignedInUser)
|
|
||||||
}
|
|
||||||
|
|
||||||
// connect library panels for this dashboard after the dashboard is stored and has an ID
|
// connect library panels for this dashboard after the dashboard is stored and has an ID
|
||||||
err = hs.LibraryPanelService.ConnectLibraryPanelsForDashboard(ctx, c.SignedInUser, dashboard)
|
err = hs.LibraryPanelService.ConnectLibraryPanelsForDashboard(ctx, c.SignedInUser, dashboard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -946,7 +946,7 @@ func getDashboardShouldReturn200WithConfig(t *testing.T, sc *scenarioContext, pr
|
|||||||
if dashboardService == nil {
|
if dashboardService == nil {
|
||||||
dashboardService, err = service.ProvideDashboardServiceImpl(
|
dashboardService, err = service.ProvideDashboardServiceImpl(
|
||||||
cfg, dashboardStore, folderStore, features, folderPermissions,
|
cfg, dashboardStore, folderStore, features, folderPermissions,
|
||||||
ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil,
|
ac, actest.FakeService{}, folderSvc, nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil,
|
||||||
dualwrite.ProvideTestService(), sort.ProvideService(),
|
dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(db, tracing.InitializeTracerForTest()), kvstore.NewFakeKVStore(),
|
serverlock.ProvideService(db, tracing.InitializeTracerForTest()), kvstore.NewFakeKVStore(),
|
||||||
)
|
)
|
||||||
@@ -956,7 +956,7 @@ func getDashboardShouldReturn200WithConfig(t *testing.T, sc *scenarioContext, pr
|
|||||||
|
|
||||||
dashboardProvisioningService, err := service.ProvideDashboardServiceImpl(
|
dashboardProvisioningService, err := service.ProvideDashboardServiceImpl(
|
||||||
cfg, dashboardStore, folderStore, features, folderPermissions,
|
cfg, dashboardStore, folderStore, features, folderPermissions,
|
||||||
ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil,
|
ac, actest.FakeService{}, folderSvc, nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil,
|
||||||
dualwrite.ProvideTestService(), sort.ProvideService(),
|
dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(db, tracing.InitializeTracerForTest()), kvstore.NewFakeKVStore(),
|
serverlock.ProvideService(db, tracing.InitializeTracerForTest()), kvstore.NewFakeKVStore(),
|
||||||
)
|
)
|
||||||
|
|||||||
+12
-6
@@ -206,10 +206,6 @@ func (hs *HTTPServer) CreateFolder(c *contextmodel.ReqContext) response.Response
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear permission cache for the user who's created the folder, so that new permissions are fetched for their next call
|
|
||||||
// Required for cases when caller wants to immediately interact with the newly created object
|
|
||||||
hs.accesscontrolService.ClearUserPermissionCache(c.SignedInUser)
|
|
||||||
|
|
||||||
folderDTO, err := hs.newToFolderDto(c, folder)
|
folderDTO, err := hs.newToFolderDto(c, folder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.Err(err)
|
return response.Err(err)
|
||||||
@@ -226,7 +222,7 @@ func (hs *HTTPServer) setDefaultFolderPermissions(ctx context.Context, orgID int
|
|||||||
|
|
||||||
var permissions []accesscontrol.SetResourcePermissionCommand
|
var permissions []accesscontrol.SetResourcePermissionCommand
|
||||||
|
|
||||||
if user.IsIdentityType(claims.TypeUser) {
|
if user.IsIdentityType(claims.TypeUser, claims.TypeServiceAccount) {
|
||||||
userID, err := user.GetInternalID()
|
userID, err := user.GetInternalID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -246,7 +242,17 @@ func (hs *HTTPServer) setDefaultFolderPermissions(ctx context.Context, orgID int
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err := hs.folderPermissionsService.SetPermissions(ctx, orgID, folder.UID, permissions...)
|
_, err := hs.folderPermissionsService.SetPermissions(ctx, orgID, folder.UID, permissions...)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.IsIdentityType(claims.TypeUser, claims.TypeServiceAccount) {
|
||||||
|
// Clear permission cache for the user who's created the folder, so that new permissions are fetched for their next call
|
||||||
|
// Required for cases when caller wants to immediately interact with the newly created object
|
||||||
|
hs.accesscontrolService.ClearUserPermissionCache(user)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:route POST /folders/{folder_uid}/move folders moveFolder
|
// swagger:route POST /folders/{folder_uid}/move folders moveFolder
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/services/accesscontrol/actest"
|
||||||
acdb "github.com/grafana/grafana/pkg/services/accesscontrol/database"
|
acdb "github.com/grafana/grafana/pkg/services/accesscontrol/database"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/permreg"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/permreg"
|
||||||
@@ -477,8 +478,8 @@ func setupServer(b testing.TB, sc benchScenario, features featuremgmt.FeatureTog
|
|||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
dashboardSvc, err := dashboardservice.ProvideDashboardServiceImpl(
|
dashboardSvc, err := dashboardservice.ProvideDashboardServiceImpl(
|
||||||
sc.cfg, dashStore, folderStore,
|
sc.cfg, dashStore, folderStore,
|
||||||
features, folderPermissions, ac,
|
features, folderPermissions, ac, actest.FakeService{},
|
||||||
folderServiceWithFlagOn, fStore, nil, client.MockTestRestConfig{}, nil, quotaSrv, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
folderServiceWithFlagOn, nil, client.MockTestRestConfig{}, nil, quotaSrv, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sc.db, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sc.db, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore(),
|
kvstore.NewFakeKVStore(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ type folderStorage struct {
|
|||||||
cfg *setting.Cfg
|
cfg *setting.Cfg
|
||||||
features featuremgmt.FeatureToggles
|
features featuremgmt.FeatureToggles
|
||||||
folderPermissionsSvc accesscontrol.FolderPermissionsService
|
folderPermissionsSvc accesscontrol.FolderPermissionsService
|
||||||
|
acService accesscontrol.Service
|
||||||
store grafanarest.Storage
|
store grafanarest.Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +140,7 @@ func (s *folderStorage) setDefaultFolderPermissions(ctx context.Context, orgID i
|
|||||||
|
|
||||||
var permissions []accesscontrol.SetResourcePermissionCommand
|
var permissions []accesscontrol.SetResourcePermissionCommand
|
||||||
|
|
||||||
if user.IsIdentityType(claims.TypeUser) {
|
if user.IsIdentityType(claims.TypeUser, claims.TypeServiceAccount) {
|
||||||
userID, err := user.GetInternalID()
|
userID, err := user.GetInternalID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -157,5 +158,13 @@ func (s *folderStorage) setDefaultFolderPermissions(ctx context.Context, orgID i
|
|||||||
}...)
|
}...)
|
||||||
}
|
}
|
||||||
_, err := s.folderPermissionsSvc.SetPermissions(ctx, orgID, uid, permissions...)
|
_, err := s.folderPermissionsSvc.SetPermissions(ctx, orgID, uid, permissions...)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.IsIdentityType(claims.TypeUser, claims.TypeServiceAccount) {
|
||||||
|
s.acService.ClearUserPermissionCache(user)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
folders "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
|
folders "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
|
||||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
|
"github.com/grafana/grafana/pkg/services/accesscontrol/actest"
|
||||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
@@ -48,6 +49,7 @@ func TestSetDefaultPermissionsWhenCreatingFolder(t *testing.T) {
|
|||||||
|
|
||||||
fs := folderStorage{
|
fs := folderStorage{
|
||||||
folderPermissionsSvc: folderPermService,
|
folderPermissionsSvc: folderPermService,
|
||||||
|
acService: actest.FakeService{},
|
||||||
store: &fakeStorage{},
|
store: &fakeStorage{},
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ type FolderAPIBuilder struct {
|
|||||||
namespacer request.NamespaceMapper
|
namespacer request.NamespaceMapper
|
||||||
folderSvc folder.Service
|
folderSvc folder.Service
|
||||||
folderPermissionsSvc accesscontrol.FolderPermissionsService
|
folderPermissionsSvc accesscontrol.FolderPermissionsService
|
||||||
|
acService accesscontrol.Service
|
||||||
storage grafanarest.Storage
|
storage grafanarest.Storage
|
||||||
|
|
||||||
authorizer authorizer.Authorizer
|
authorizer authorizer.Authorizer
|
||||||
@@ -64,6 +65,7 @@ func RegisterAPIService(cfg *setting.Cfg,
|
|||||||
folderSvc folder.Service,
|
folderSvc folder.Service,
|
||||||
folderPermissionsSvc accesscontrol.FolderPermissionsService,
|
folderPermissionsSvc accesscontrol.FolderPermissionsService,
|
||||||
accessControl accesscontrol.AccessControl,
|
accessControl accesscontrol.AccessControl,
|
||||||
|
acService accesscontrol.Service,
|
||||||
registerer prometheus.Registerer,
|
registerer prometheus.Registerer,
|
||||||
unified resource.ResourceClient,
|
unified resource.ResourceClient,
|
||||||
) *FolderAPIBuilder {
|
) *FolderAPIBuilder {
|
||||||
@@ -73,6 +75,7 @@ func RegisterAPIService(cfg *setting.Cfg,
|
|||||||
namespacer: request.GetNamespaceMapper(cfg),
|
namespacer: request.GetNamespaceMapper(cfg),
|
||||||
folderSvc: folderSvc,
|
folderSvc: folderSvc,
|
||||||
folderPermissionsSvc: folderPermissionsSvc,
|
folderPermissionsSvc: folderPermissionsSvc,
|
||||||
|
acService: acService,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
authorizer: newLegacyAuthorizer(accessControl),
|
authorizer: newLegacyAuthorizer(accessControl),
|
||||||
searcher: unified,
|
searcher: unified,
|
||||||
@@ -155,6 +158,7 @@ func (b *FolderAPIBuilder) UpdateAPIGroupInfo(apiGroupInfo *genericapiserver.API
|
|||||||
folderStore := &folderStorage{
|
folderStore := &folderStorage{
|
||||||
tableConverter: resourceInfo.TableConverter(),
|
tableConverter: resourceInfo.TableConverter(),
|
||||||
folderPermissionsSvc: b.folderPermissionsSvc,
|
folderPermissionsSvc: b.folderPermissionsSvc,
|
||||||
|
acService: b.acService,
|
||||||
features: b.features,
|
features: b.features,
|
||||||
cfg: b.cfg,
|
cfg: b.cfg,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func TestIntegrationAuthorize(t *testing.T) {
|
|||||||
fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
||||||
nil, sql, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
nil, sql, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
||||||
dashSvc, err := dashboardsservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), accesscontrolmock.NewMockedPermissionsService(),
|
dashSvc, err := dashboardsservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), accesscontrolmock.NewMockedPermissionsService(),
|
||||||
ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
ac, actest.FakeService{}, folderSvc, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sql, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sql, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore())
|
kvstore.NewFakeKVStore())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
|||||||
fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
||||||
nil, sql, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
nil, sql, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
||||||
dashSvc, err := dashboardsservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), accesscontrolmock.NewMockedPermissionsService(),
|
dashSvc, err := dashboardsservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), accesscontrolmock.NewMockedPermissionsService(),
|
||||||
ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
ac, actest.FakeService{}, folderSvc, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sql, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sql, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore())
|
kvstore.NewFakeKVStore())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -251,7 +251,7 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) {
|
|||||||
fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
||||||
nil, sql, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
nil, sql, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
||||||
dashSvc, err := dashboardsservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, features, accesscontrolmock.NewMockedPermissionsService(),
|
dashSvc, err := dashboardsservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, features, accesscontrolmock.NewMockedPermissionsService(),
|
||||||
ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
ac, actest.FakeService{}, folderSvc, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sql, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sql, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore(),
|
kvstore.NewFakeKVStore(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ type DashboardServiceImpl struct {
|
|||||||
folderPermissions accesscontrol.FolderPermissionsService
|
folderPermissions accesscontrol.FolderPermissionsService
|
||||||
dashboardPermissions accesscontrol.DashboardPermissionsService
|
dashboardPermissions accesscontrol.DashboardPermissionsService
|
||||||
ac accesscontrol.AccessControl
|
ac accesscontrol.AccessControl
|
||||||
|
acService accesscontrol.Service
|
||||||
k8sclient client.K8sHandler
|
k8sclient client.K8sHandler
|
||||||
metrics *dashboardsMetrics
|
metrics *dashboardsMetrics
|
||||||
publicDashboardService publicdashboards.ServiceWrapper
|
publicDashboardService publicdashboards.ServiceWrapper
|
||||||
@@ -368,7 +369,7 @@ var _ registry.BackgroundService = (*DashboardServiceImpl)(nil)
|
|||||||
func ProvideDashboardServiceImpl(
|
func ProvideDashboardServiceImpl(
|
||||||
cfg *setting.Cfg, dashboardStore dashboards.Store, folderStore folder.FolderStore,
|
cfg *setting.Cfg, dashboardStore dashboards.Store, folderStore folder.FolderStore,
|
||||||
features featuremgmt.FeatureToggles, folderPermissionsService accesscontrol.FolderPermissionsService,
|
features featuremgmt.FeatureToggles, folderPermissionsService accesscontrol.FolderPermissionsService,
|
||||||
ac accesscontrol.AccessControl, folderSvc folder.Service, fStore folder.Store, r prometheus.Registerer,
|
ac accesscontrol.AccessControl, acService accesscontrol.Service, folderSvc folder.Service, r prometheus.Registerer,
|
||||||
restConfigProvider apiserver.RestConfigProvider, userService user.Service,
|
restConfigProvider apiserver.RestConfigProvider, userService user.Service,
|
||||||
quotaService quota.Service, orgService org.Service, publicDashboardService publicdashboards.ServiceWrapper,
|
quotaService quota.Service, orgService org.Service, publicDashboardService publicdashboards.ServiceWrapper,
|
||||||
resourceClient resource.ResourceClient, dual dualwrite.Service, sorter sort.Service,
|
resourceClient resource.ResourceClient, dual dualwrite.Service, sorter sort.Service,
|
||||||
@@ -383,6 +384,7 @@ func ProvideDashboardServiceImpl(
|
|||||||
features: features,
|
features: features,
|
||||||
folderPermissions: folderPermissionsService,
|
folderPermissions: folderPermissionsService,
|
||||||
ac: ac,
|
ac: ac,
|
||||||
|
acService: acService,
|
||||||
folderStore: folderStore,
|
folderStore: folderStore,
|
||||||
folderService: folderSvc,
|
folderService: folderSvc,
|
||||||
orgService: orgService,
|
orgService: orgService,
|
||||||
@@ -1001,7 +1003,7 @@ func (dr *DashboardServiceImpl) SaveFolderForProvisionedDashboards(ctx context.C
|
|||||||
|
|
||||||
// Only set default permissions if the Folder API Server is disabled.
|
// Only set default permissions if the Folder API Server is disabled.
|
||||||
if !dr.features.IsEnabledGlobally(featuremgmt.FlagKubernetesClientDashboardsFolders) {
|
if !dr.features.IsEnabledGlobally(featuremgmt.FlagKubernetesClientDashboardsFolders) {
|
||||||
dr.setDefaultFolderPermissions(ctx, dto, f, true)
|
dr.setDefaultFolderPermissions(ctx, dto, f)
|
||||||
}
|
}
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
@@ -1206,16 +1208,15 @@ func (dr *DashboardServiceImpl) SetDefaultPermissionsAfterCreate(ctx context.Con
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var permissions []accesscontrol.SetResourcePermissionCommand
|
permissions := []accesscontrol.SetResourcePermissionCommand{}
|
||||||
|
if user.IsIdentityType(claims.TypeUser, claims.TypeServiceAccount) {
|
||||||
|
permissions = append(permissions, accesscontrol.SetResourcePermissionCommand{
|
||||||
|
UserID: uid, Permission: dashboardaccess.PERMISSION_ADMIN.String(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
isNested := obj.GetFolder() != ""
|
||||||
if !dr.features.IsEnabledGlobally(featuremgmt.FlagKubernetesDashboards) {
|
if !dr.features.IsEnabledGlobally(featuremgmt.FlagKubernetesDashboards) {
|
||||||
// legacy behavior
|
// legacy behavior
|
||||||
permissions = []accesscontrol.SetResourcePermissionCommand{}
|
|
||||||
if user.IsIdentityType(claims.TypeUser) {
|
|
||||||
permissions = append(permissions, accesscontrol.SetResourcePermissionCommand{
|
|
||||||
UserID: uid, Permission: dashboardaccess.PERMISSION_ADMIN.String(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
isNested := obj.GetFolder() != ""
|
|
||||||
if !isNested || !dr.features.IsEnabled(ctx, featuremgmt.FlagNestedFolders) {
|
if !isNested || !dr.features.IsEnabled(ctx, featuremgmt.FlagNestedFolders) {
|
||||||
permissions = append(permissions, []accesscontrol.SetResourcePermissionCommand{
|
permissions = append(permissions, []accesscontrol.SetResourcePermissionCommand{
|
||||||
{BuiltinRole: string(org.RoleEditor), Permission: dashboardaccess.PERMISSION_EDIT.String()},
|
{BuiltinRole: string(org.RoleEditor), Permission: dashboardaccess.PERMISSION_EDIT.String()},
|
||||||
@@ -1223,14 +1224,14 @@ func (dr *DashboardServiceImpl) SetDefaultPermissionsAfterCreate(ctx context.Con
|
|||||||
}...)
|
}...)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if obj.GetFolder() != "" {
|
// Don't set any permissions for nested dashboards
|
||||||
|
if isNested {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
permissions = []accesscontrol.SetResourcePermissionCommand{
|
permissions = append(permissions, []accesscontrol.SetResourcePermissionCommand{
|
||||||
{UserID: uid, Permission: dashboardaccess.PERMISSION_ADMIN.String()},
|
|
||||||
{BuiltinRole: string(org.RoleEditor), Permission: dashboardaccess.PERMISSION_ADMIN.String()},
|
{BuiltinRole: string(org.RoleEditor), Permission: dashboardaccess.PERMISSION_ADMIN.String()},
|
||||||
{BuiltinRole: string(org.RoleViewer), Permission: dashboardaccess.PERMISSION_VIEW.String()},
|
{BuiltinRole: string(org.RoleViewer), Permission: dashboardaccess.PERMISSION_VIEW.String()},
|
||||||
}
|
}...)
|
||||||
}
|
}
|
||||||
svc := dr.getPermissionsService(key.Resource == "folders")
|
svc := dr.getPermissionsService(key.Resource == "folders")
|
||||||
if _, err := svc.SetPermissions(ctx, ns.OrgID, obj.GetName(), permissions...); err != nil {
|
if _, err := svc.SetPermissions(ctx, ns.OrgID, obj.GetName(), permissions...); err != nil {
|
||||||
@@ -1238,6 +1239,12 @@ func (dr *DashboardServiceImpl) SetDefaultPermissionsAfterCreate(ctx context.Con
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear permission cache for the user who created the dashboard, so that new permissions are fetched for their next call
|
||||||
|
// Required for cases when caller wants to immediately interact with the newly created object
|
||||||
|
if user.IsIdentityType(claims.TypeUser, claims.TypeServiceAccount) {
|
||||||
|
dr.acService.ClearUserPermissionCache(user)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1279,37 +1286,25 @@ func (dr *DashboardServiceImpl) SetDefaultPermissions(ctx context.Context, dto *
|
|||||||
if _, err := svc.SetPermissions(ctx, dto.OrgID, dash.UID, permissions...); err != nil {
|
if _, err := svc.SetPermissions(ctx, dto.OrgID, dash.UID, permissions...); err != nil {
|
||||||
dr.log.Error("Could not set default permissions", "dashboard", dash.Title, "error", err)
|
dr.log.Error("Could not set default permissions", "dashboard", dash.Title, "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear permission cache for the user who created the dashboard, so that new permissions are fetched for their next call
|
||||||
|
// Required for cases when caller wants to immediately interact with the newly created object
|
||||||
|
if !provisioned && dto.User.IsIdentityType(claims.TypeUser, claims.TypeServiceAccount) {
|
||||||
|
dr.acService.ClearUserPermissionCache(dto.User)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dr *DashboardServiceImpl) setDefaultFolderPermissions(ctx context.Context, cmd *folder.CreateFolderCommand, f *folder.Folder, provisioned bool) {
|
func (dr *DashboardServiceImpl) setDefaultFolderPermissions(ctx context.Context, cmd *folder.CreateFolderCommand, f *folder.Folder) {
|
||||||
if dr.features.IsEnabledGlobally(featuremgmt.FlagKubernetesClientDashboardsFolders) {
|
if dr.features.IsEnabledGlobally(featuremgmt.FlagKubernetesClientDashboardsFolders) || !dr.cfg.RBAC.PermissionsOnCreation("folder") || f.ParentUID != "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, span := tracer.Start(ctx, "dashboards.service.setDefaultFolderPermissions")
|
ctx, span := tracer.Start(ctx, "dashboards.service.setDefaultFolderPermissions")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
if !dr.cfg.RBAC.PermissionsOnCreation("folder") {
|
permissions := []accesscontrol.SetResourcePermissionCommand{
|
||||||
return
|
{BuiltinRole: string(org.RoleEditor), Permission: dashboardaccess.PERMISSION_EDIT.String()},
|
||||||
}
|
{BuiltinRole: string(org.RoleViewer), Permission: dashboardaccess.PERMISSION_VIEW.String()},
|
||||||
|
|
||||||
var permissions []accesscontrol.SetResourcePermissionCommand
|
|
||||||
if !provisioned && cmd.SignedInUser.IsIdentityType(claims.TypeUser) {
|
|
||||||
userID, err := cmd.SignedInUser.GetInternalID()
|
|
||||||
if err != nil {
|
|
||||||
dr.log.Error("Could not make user admin", "folder", cmd.Title, "id", cmd.SignedInUser.GetID())
|
|
||||||
} else {
|
|
||||||
permissions = append(permissions, accesscontrol.SetResourcePermissionCommand{
|
|
||||||
UserID: userID, Permission: dashboardaccess.PERMISSION_ADMIN.String(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.ParentUID == "" {
|
|
||||||
permissions = append(permissions, []accesscontrol.SetResourcePermissionCommand{
|
|
||||||
{BuiltinRole: string(org.RoleEditor), Permission: dashboardaccess.PERMISSION_EDIT.String()},
|
|
||||||
{BuiltinRole: string(org.RoleViewer), Permission: dashboardaccess.PERMISSION_VIEW.String()},
|
|
||||||
}...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := dr.folderPermissions.SetPermissions(ctx, cmd.OrgID, f.UID, permissions...); err != nil {
|
if _, err := dr.folderPermissions.SetPermissions(ctx, cmd.OrgID, f.UID, permissions...); err != nil {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards/database"
|
"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/folder"
|
|
||||||
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
@@ -806,8 +805,8 @@ func permissionScenario(t *testing.T, desc string, fn permissionScenarioFunc) {
|
|||||||
featuremgmt.WithFeatures(),
|
featuremgmt.WithFeatures(),
|
||||||
folderPermissions,
|
folderPermissions,
|
||||||
ac,
|
ac,
|
||||||
|
actest.FakeService{},
|
||||||
folderService,
|
folderService,
|
||||||
folder.NewFakeStore(),
|
|
||||||
nil,
|
nil,
|
||||||
client.MockTestRestConfig{},
|
client.MockTestRestConfig{},
|
||||||
nil,
|
nil,
|
||||||
@@ -902,8 +901,8 @@ func callSaveWithResult(t *testing.T, cmd dashboards.SaveDashboardCommand, sqlSt
|
|||||||
featuremgmt.WithFeatures(),
|
featuremgmt.WithFeatures(),
|
||||||
folderPermissions,
|
folderPermissions,
|
||||||
ac,
|
ac,
|
||||||
|
actest.FakeService{},
|
||||||
folderService,
|
folderService,
|
||||||
folder.NewFakeStore(),
|
|
||||||
nil,
|
nil,
|
||||||
client.MockTestRestConfig{},
|
client.MockTestRestConfig{},
|
||||||
nil,
|
nil,
|
||||||
@@ -976,8 +975,8 @@ func saveTestDashboard(t *testing.T, title string, orgID int64, folderUID string
|
|||||||
features,
|
features,
|
||||||
accesscontrolmock.NewMockedPermissionsService(),
|
accesscontrolmock.NewMockedPermissionsService(),
|
||||||
actest.FakeAccessControl{ExpectedEvaluate: true},
|
actest.FakeAccessControl{ExpectedEvaluate: true},
|
||||||
|
actest.FakeService{},
|
||||||
folderService,
|
folderService,
|
||||||
folder.NewFakeStore(),
|
|
||||||
nil,
|
nil,
|
||||||
client.MockTestRestConfig{},
|
client.MockTestRestConfig{},
|
||||||
nil,
|
nil,
|
||||||
@@ -1058,8 +1057,8 @@ func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore db.DB) *da
|
|||||||
featuremgmt.WithFeatures(),
|
featuremgmt.WithFeatures(),
|
||||||
folderPermissions,
|
folderPermissions,
|
||||||
actest.FakeAccessControl{ExpectedEvaluate: true},
|
actest.FakeAccessControl{ExpectedEvaluate: true},
|
||||||
|
actest.FakeService{},
|
||||||
folderService,
|
folderService,
|
||||||
folder.NewFakeStore(),
|
|
||||||
nil,
|
nil,
|
||||||
client.MockTestRestConfig{},
|
client.MockTestRestConfig{},
|
||||||
nil,
|
nil,
|
||||||
|
|||||||
@@ -1287,8 +1287,9 @@ func TestSetDefaultPermissionsWhenSavingFolderForProvisionedDashboards(t *testin
|
|||||||
UID: "general",
|
UID: "general",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ac: actest.FakeAccessControl{ExpectedEvaluate: true},
|
ac: actest.FakeAccessControl{ExpectedEvaluate: true},
|
||||||
log: log.NewNopLogger(),
|
acService: &actest.FakeService{},
|
||||||
|
log: log.NewNopLogger(),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := &folder.CreateFolderCommand{
|
cmd := &folder.CreateFolderCommand{
|
||||||
@@ -2496,6 +2497,7 @@ func TestSetDefaultPermissionsAfterCreate(t *testing.T) {
|
|||||||
dashboardPermissions: permService,
|
dashboardPermissions: permService,
|
||||||
folderPermissions: permService,
|
folderPermissions: permService,
|
||||||
dashboardPermissionsReady: make(chan struct{}),
|
dashboardPermissionsReady: make(chan struct{}),
|
||||||
|
acService: &actest.FakeService{},
|
||||||
}
|
}
|
||||||
service.RegisterDashboardPermissions(permService)
|
service.RegisterDashboardPermissions(permService)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/kvstore"
|
"github.com/grafana/grafana/pkg/infra/kvstore"
|
||||||
"github.com/grafana/grafana/pkg/infra/serverlock"
|
"github.com/grafana/grafana/pkg/infra/serverlock"
|
||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/actest"
|
||||||
"github.com/grafana/grafana/pkg/services/apiserver/client"
|
"github.com/grafana/grafana/pkg/services/apiserver/client"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
dashdb "github.com/grafana/grafana/pkg/services/dashboards/database"
|
dashdb "github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||||
@@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
||||||
dashsnapdb "github.com/grafana/grafana/pkg/services/dashboardsnapshots/database"
|
dashsnapdb "github.com/grafana/grafana/pkg/services/dashboardsnapshots/database"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/folder"
|
|
||||||
"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/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
@@ -112,9 +111,9 @@ func TestValidateDashboardExists(t *testing.T) {
|
|||||||
folderimpl.ProvideDashboardFolderStore(sqlStore),
|
folderimpl.ProvideDashboardFolderStore(sqlStore),
|
||||||
feats,
|
feats,
|
||||||
nil,
|
nil,
|
||||||
acmock.New(),
|
actest.FakeAccessControl{},
|
||||||
|
actest.FakeService{},
|
||||||
foldertest.NewFakeService(),
|
foldertest.NewFakeService(),
|
||||||
folder.NewFakeStore(),
|
|
||||||
nil,
|
nil,
|
||||||
client.MockTestRestConfig{},
|
client.MockTestRestConfig{},
|
||||||
nil,
|
nil,
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ func TestIntegrationNestedFolderService(t *testing.T) {
|
|||||||
})
|
})
|
||||||
publicDashboardFakeService.On("DeleteByDashboardUIDs", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
publicDashboardFakeService.On("DeleteByDashboardUIDs", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||||
|
|
||||||
dashSrv, err := dashboardservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuresFlagOn, folderPermissions, ac, serviceWithFlagOn, nestedFolderStore, nil,
|
dashSrv, err := dashboardservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuresFlagOn, folderPermissions, ac, actest.FakeService{}, serviceWithFlagOn, nil,
|
||||||
client.MockTestRestConfig{}, nil, quotaService, nil, publicDashboardFakeService, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
client.MockTestRestConfig{}, nil, quotaService, nil, publicDashboardFakeService, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(db, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(db, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore(),
|
kvstore.NewFakeKVStore(),
|
||||||
@@ -533,7 +533,7 @@ func TestIntegrationNestedFolderService(t *testing.T) {
|
|||||||
publicDashboardFakeService.On("DeleteByDashboardUIDs", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
publicDashboardFakeService.On("DeleteByDashboardUIDs", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||||
|
|
||||||
dashSrv, err := dashboardservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuresFlagOff,
|
dashSrv, err := dashboardservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuresFlagOff,
|
||||||
folderPermissions, ac, serviceWithFlagOff, nestedFolderStore, nil, client.MockTestRestConfig{}, nil, quotaService, nil, publicDashboardFakeService, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
folderPermissions, ac, actest.FakeService{}, serviceWithFlagOff, nil, client.MockTestRestConfig{}, nil, quotaService, nil, publicDashboardFakeService, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(db, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(db, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore(),
|
kvstore.NewFakeKVStore(),
|
||||||
)
|
)
|
||||||
@@ -679,8 +679,8 @@ func TestIntegrationNestedFolderService(t *testing.T) {
|
|||||||
tc.service.store = nestedFolderStore
|
tc.service.store = nestedFolderStore
|
||||||
publicDashboardFakeService.On("DeleteByDashboardUIDs", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
publicDashboardFakeService.On("DeleteByDashboardUIDs", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||||
|
|
||||||
dashSrv, err := dashboardservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, tc.featuresFlag, folderPermissions, ac, tc.service,
|
dashSrv, err := dashboardservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, tc.featuresFlag, folderPermissions, ac, actest.FakeService{}, tc.service,
|
||||||
tc.service.store, nil, client.MockTestRestConfig{}, nil, quotaService, nil, publicDashboardFakeService, nil,
|
nil, client.MockTestRestConfig{}, nil, quotaService, nil, publicDashboardFakeService, nil,
|
||||||
dualwrite.ProvideTestService(), sort.ProvideService(),
|
dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(db, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(db, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore(),
|
kvstore.NewFakeKVStore(),
|
||||||
@@ -1465,8 +1465,8 @@ func TestIntegrationNestedFolderSharedWithMe(t *testing.T) {
|
|||||||
featuresFlagOn,
|
featuresFlagOn,
|
||||||
acmock.NewMockedPermissionsService(),
|
acmock.NewMockedPermissionsService(),
|
||||||
actest.FakeAccessControl{},
|
actest.FakeAccessControl{},
|
||||||
|
actest.FakeService{},
|
||||||
serviceWithFlagOn,
|
serviceWithFlagOn,
|
||||||
nestedFolderStore,
|
|
||||||
nil,
|
nil,
|
||||||
client.MockTestRestConfig{},
|
client.MockTestRestConfig{},
|
||||||
nil,
|
nil,
|
||||||
|
|||||||
@@ -358,8 +358,8 @@ func createDashboard(t *testing.T, sqlStore db.DB, user user.SignedInUser, dash
|
|||||||
service, err := dashboardservice.ProvideDashboardServiceImpl(
|
service, err := dashboardservice.ProvideDashboardServiceImpl(
|
||||||
cfg, dashboardStore, folderStore,
|
cfg, dashboardStore, folderStore,
|
||||||
features, folderPermissions, ac,
|
features, folderPermissions, ac,
|
||||||
|
actest.FakeService{},
|
||||||
folderSvc,
|
folderSvc,
|
||||||
folder.NewFakeStore(),
|
|
||||||
nil,
|
nil,
|
||||||
client.MockTestRestConfig{},
|
client.MockTestRestConfig{},
|
||||||
nil,
|
nil,
|
||||||
@@ -461,8 +461,7 @@ func scenarioWithPanel(t *testing.T, desc string, fn func(t *testing.T, sc scena
|
|||||||
nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
||||||
dashboardService, svcErr := dashboardservice.ProvideDashboardServiceImpl(
|
dashboardService, svcErr := dashboardservice.ProvideDashboardServiceImpl(
|
||||||
cfg, dashboardStore, folderStore,
|
cfg, dashboardStore, folderStore,
|
||||||
features, folderPermissions, ac,
|
features, folderPermissions, ac, actest.FakeService{}, folderSvc,
|
||||||
folderSvc, fStore,
|
|
||||||
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore(),
|
kvstore.NewFakeKVStore(),
|
||||||
@@ -536,8 +535,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashService, dashSvcErr := dashboardservice.ProvideDashboardServiceImpl(
|
dashService, dashSvcErr := dashboardservice.ProvideDashboardServiceImpl(
|
||||||
cfg, dashboardStore, folderStore,
|
cfg, dashboardStore, folderStore,
|
||||||
features, folderPermissions, ac,
|
features, folderPermissions, ac, actest.FakeService{}, folderSvc,
|
||||||
folderSvc, fStore,
|
|
||||||
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore(),
|
kvstore.NewFakeKVStore(),
|
||||||
|
|||||||
@@ -739,8 +739,7 @@ func createDashboard(t *testing.T, sqlStore db.DB, user *user.SignedInUser, dash
|
|||||||
dashPermissionService.On("SetPermissions", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]accesscontrol.ResourcePermission{}, nil)
|
dashPermissionService.On("SetPermissions", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]accesscontrol.ResourcePermission{}, nil)
|
||||||
service, err := dashboardservice.ProvideDashboardServiceImpl(
|
service, err := dashboardservice.ProvideDashboardServiceImpl(
|
||||||
cfg, dashboardStore, folderStore,
|
cfg, dashboardStore, folderStore,
|
||||||
features, acmock.NewMockedPermissionsService(), ac,
|
features, acmock.NewMockedPermissionsService(), ac, actest.FakeService{}, foldertest.NewFakeService(),
|
||||||
foldertest.NewFakeService(), folder.NewFakeStore(),
|
|
||||||
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore())
|
kvstore.NewFakeKVStore())
|
||||||
@@ -838,8 +837,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
|||||||
folderSvc.ExpectedFolder = &folder.Folder{ID: 1}
|
folderSvc.ExpectedFolder = &folder.Folder{ID: 1}
|
||||||
dashService, err := dashboardservice.ProvideDashboardServiceImpl(
|
dashService, err := dashboardservice.ProvideDashboardServiceImpl(
|
||||||
cfg, dashStore, folderStore,
|
cfg, dashStore, folderStore,
|
||||||
features, acmock.NewMockedPermissionsService(), ac,
|
features, acmock.NewMockedPermissionsService(), ac, actest.FakeService{}, folderSvc,
|
||||||
folderSvc, folder.NewFakeStore(),
|
|
||||||
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore())
|
kvstore.NewFakeKVStore())
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/serverlock"
|
"github.com/grafana/grafana/pkg/infra/serverlock"
|
||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
|
"github.com/grafana/grafana/pkg/services/accesscontrol/actest"
|
||||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||||
"github.com/grafana/grafana/pkg/services/apiserver"
|
"github.com/grafana/grafana/pkg/services/apiserver"
|
||||||
"github.com/grafana/grafana/pkg/services/apiserver/client"
|
"github.com/grafana/grafana/pkg/services/apiserver/client"
|
||||||
@@ -67,7 +68,7 @@ func SetupDashboardService(tb testing.TB, sqlStore db.DB, fs *folderimpl.Dashboa
|
|||||||
dashboardService, err := dashboardservice.ProvideDashboardServiceImpl(
|
dashboardService, err := dashboardservice.ProvideDashboardServiceImpl(
|
||||||
cfg, dashboardStore, fs,
|
cfg, dashboardStore, fs,
|
||||||
features, folderPermissions, ac,
|
features, folderPermissions, ac,
|
||||||
foldertest.NewFakeService(), folder.NewFakeStore(),
|
&actest.FakeService{}, foldertest.NewFakeService(),
|
||||||
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil,
|
nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil,
|
||||||
dualwrite.ProvideTestService(), sort.ProvideService(),
|
dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/infra/serverlock"
|
"github.com/grafana/grafana/pkg/infra/serverlock"
|
||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
|
"github.com/grafana/grafana/pkg/services/accesscontrol/actest"
|
||||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations/annotationstest"
|
"github.com/grafana/grafana/pkg/services/annotations/annotationstest"
|
||||||
"github.com/grafana/grafana/pkg/services/apiserver/client"
|
"github.com/grafana/grafana/pkg/services/apiserver/client"
|
||||||
@@ -36,7 +37,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/datasources/guardian"
|
"github.com/grafana/grafana/pkg/services/datasources/guardian"
|
||||||
datasourcesService "github.com/grafana/grafana/pkg/services/datasources/service"
|
datasourcesService "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/folder"
|
|
||||||
"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/licensing/licensingtest"
|
||||||
@@ -324,14 +324,14 @@ func TestIntegrationUnauthenticatedUserCanGetPubdashPanelQueryData(t *testing.T)
|
|||||||
// create public dashboard
|
// create public dashboard
|
||||||
store := publicdashboardsStore.ProvideStore(db, cfg, featuremgmt.WithFeatures())
|
store := publicdashboardsStore.ProvideStore(db, cfg, featuremgmt.WithFeatures())
|
||||||
cfg.PublicDashboardsEnabled = true
|
cfg.PublicDashboardsEnabled = true
|
||||||
ac := acmock.New()
|
ac := actest.FakeAccessControl{}
|
||||||
ws := publicdashboardsService.ProvideServiceWrapper(store)
|
ws := publicdashboardsService.ProvideServiceWrapper(store)
|
||||||
folderStore := folderimpl.ProvideDashboardFolderStore(db)
|
folderStore := folderimpl.ProvideDashboardFolderStore(db)
|
||||||
dashPermissionService := acmock.NewMockedPermissionsService()
|
dashPermissionService := acmock.NewMockedPermissionsService()
|
||||||
dashService, err := service.ProvideDashboardServiceImpl(
|
dashService, err := service.ProvideDashboardServiceImpl(
|
||||||
cfg, dashboardStoreService, folderStore,
|
cfg, dashboardStoreService, folderStore,
|
||||||
featuremgmt.WithFeatures(), acmock.NewMockedPermissionsService(), ac,
|
featuremgmt.WithFeatures(), acmock.NewMockedPermissionsService(), ac, actest.FakeService{},
|
||||||
foldertest.NewFakeService(), folder.NewFakeStore(), nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil,
|
foldertest.NewFakeService(), nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil,
|
||||||
nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(db, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(db, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore(),
|
kvstore.NewFakeKVStore(),
|
||||||
|
|||||||
@@ -1403,7 +1403,7 @@ func TestPublicDashboardServiceImpl_ListPublicDashboards(t *testing.T) {
|
|||||||
fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
||||||
nil, testDB, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
nil, testDB, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
||||||
|
|
||||||
dashboardService, err := dashsvc.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), folderPermissions, ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
dashboardService, err := dashsvc.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), folderPermissions, ac, actest.FakeService{}, folderSvc, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(testDB, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(testDB, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore())
|
kvstore.NewFakeKVStore())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
pluginfakes "github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
pluginfakes "github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/services/accesscontrol/actest"
|
||||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations/annotationstest"
|
"github.com/grafana/grafana/pkg/services/annotations/annotationstest"
|
||||||
"github.com/grafana/grafana/pkg/services/apikey"
|
"github.com/grafana/grafana/pkg/services/apikey"
|
||||||
@@ -504,7 +505,7 @@ func setupEnv(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, b bus.Bus, quotaSe
|
|||||||
fStore, acmock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
fStore, acmock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore,
|
||||||
nil, sqlStore, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
nil, sqlStore, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig)
|
||||||
dashService, err := dashService.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), acmock.NewMockedPermissionsService(),
|
dashService, err := dashService.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), acmock.NewMockedPermissionsService(),
|
||||||
ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
ac, actest.FakeService{}, folderSvc, nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(),
|
||||||
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()),
|
||||||
kvstore.NewFakeKVStore())
|
kvstore.NewFakeKVStore())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user