Nested Folders: Do not refer to the configuration for checking for the flag (#59197)

* Nested Folders: Do not refer to the configuration for checking for the flag

Use always features.IsEnabled() instead

* Depend on the interface instead
This commit is contained in:
Sofia Papagiannaki 2022-11-23 13:16:00 +02:00 committed by GitHub
parent a0334a92f5
commit 0af96936be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 20 deletions

View File

@ -34,7 +34,7 @@ type Service struct {
dashboardService dashboards.DashboardService
dashboardStore dashboards.Store
searchService *search.SearchService
features *featuremgmt.FeatureManager
features featuremgmt.FeatureToggles
permissions accesscontrol.FolderPermissionsService
accessControl accesscontrol.AccessControl
@ -49,7 +49,7 @@ func ProvideService(
dashboardService dashboards.DashboardService,
dashboardStore dashboards.Store,
db db.DB, // DB for the (new) nested folder store
features *featuremgmt.FeatureManager,
features featuremgmt.FeatureToggles,
folderPermissionsService accesscontrol.FolderPermissionsService,
searchService *search.SearchService,
) folder.Service {
@ -97,7 +97,7 @@ func (s *Service) Get(ctx context.Context, cmd *folder.GetFolderQuery) (*folder.
return nil, folder.ErrBadRequest.Errorf("missing signed in user")
}
if s.cfg.IsFeatureToggleEnabled(featuremgmt.FlagNestedFolders) {
if s.features.IsEnabled(featuremgmt.FlagNestedFolders) {
if ok, err := s.accessControl.Evaluate(ctx, cmd.SignedInUser, accesscontrol.EvalPermission(
dashboards.ActionFoldersRead, dashboards.ScopeFoldersProvider.GetResourceScopeUID(*cmd.UID),
)); !ok {

View File

@ -57,7 +57,6 @@ func TestIntegrationFolderService(t *testing.T) {
cfg := setting.NewCfg()
cfg.RBACEnabled = false
features := featuremgmt.WithFeatures()
cfg.IsFeatureToggleEnabled = features.IsEnabled
folderPermissions := acmock.NewMockedPermissionsService()
dashboardPermissions := acmock.NewMockedPermissionsService()
dashboardService := dashboardsvc.ProvideDashboardService(cfg, dashStore, nil, features, folderPermissions, dashboardPermissions, acmock.New())
@ -333,21 +332,12 @@ func TestNestedFolderServiceFeatureToggle(t *testing.T) {
dashStore.On("GetFolderByID", mock.Anything, mock.AnythingOfType("int64"), mock.AnythingOfType("int64")).Return(&folder.Folder{}, nil)
cfg := setting.NewCfg()
cfg.RBACEnabled = false
nestedFoldersEnabled := true
features := featuremgmt.WithFeatures()
cfg.IsFeatureToggleEnabled = func(key string) bool {
if key == featuremgmt.FlagNestedFolders {
return nestedFoldersEnabled
}
return false
}
cfg.IsFeatureToggleEnabled = features.IsEnabled
folderService := &Service{
cfg: cfg,
store: folderStore,
dashboardStore: &dashStore,
dashboardService: &dashboardsvc,
features: features,
features: featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders),
}
t.Run("create folder", func(t *testing.T) {
folderStore.ExpectedFolder = &folder.Folder{}
@ -396,15 +386,13 @@ func TestNestedFolderService(t *testing.T) {
// nothing enabled yet
cfg := setting.NewCfg()
cfg.RBACEnabled = false
features := featuremgmt.WithFeatures()
cfg.IsFeatureToggleEnabled = features.IsEnabled
foldersvc := &Service{
cfg: cfg,
log: log.New("test-folder-service"),
dashboardService: &dashboardsvc,
dashboardStore: &dashStore,
store: store,
features: features,
features: featuremgmt.WithFeatures(),
}
t.Run("When create folder, no create in folder table done", func(t *testing.T) {
@ -456,15 +444,13 @@ func TestNestedFolderService(t *testing.T) {
// nothing enabled yet
cfg := setting.NewCfg()
cfg.RBACEnabled = false
features := featuremgmt.WithFeatures("nestedFolders")
cfg.IsFeatureToggleEnabled = features.IsEnabled
foldersvc := &Service{
cfg: cfg,
log: log.New("test-folder-service"),
dashboardService: dashboardsvc,
dashboardStore: dashStore,
store: store,
features: features,
features: featuremgmt.WithFeatures("nestedFolders"),
accessControl: actest.FakeAccessControl{
ExpectedEvaluate: true,
},