Revert "Chore: Refactor quota service (#57586)" (#58394)

This reverts commit 326ea86a57.
This commit is contained in:
Sofia Papagiannaki
2022-11-08 11:52:07 +02:00
committed by GitHub
parent 228ec4c0f3
commit 96cdf77995
99 changed files with 1398 additions and 2596 deletions
@@ -17,7 +17,6 @@ import (
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/guardian"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/quota/quotatest"
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
"github.com/grafana/grafana/pkg/services/team/teamtest"
"github.com/grafana/grafana/pkg/services/user"
@@ -43,7 +42,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
}),
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardNotFound, err)
})
@@ -63,7 +62,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: false,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardNotFound, err)
})
@@ -105,7 +104,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sqlStore)
err := callSaveWithError(cmd, sqlStore)
assert.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, int64(0), sc.dashboardGuardianMock.DashId)
@@ -125,7 +124,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
require.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, sc.otherSavedFolder.Id, sc.dashboardGuardianMock.DashId)
@@ -145,7 +144,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
require.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, sc.savedDashInFolder.Id, sc.dashboardGuardianMock.DashId)
@@ -166,7 +165,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
require.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, sc.savedDashInFolder.Id, sc.dashboardGuardianMock.DashId)
@@ -187,7 +186,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, sc.savedDashInGeneralFolder.Id, sc.dashboardGuardianMock.DashId)
@@ -208,7 +207,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
require.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, sc.savedDashInFolder.Id, sc.dashboardGuardianMock.DashId)
@@ -229,7 +228,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
require.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, sc.savedDashInGeneralFolder.Id, sc.dashboardGuardianMock.DashId)
@@ -250,7 +249,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, sc.savedDashInFolder.Id, sc.dashboardGuardianMock.DashId)
@@ -271,7 +270,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
require.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, sc.savedDashInGeneralFolder.Id, sc.dashboardGuardianMock.DashId)
@@ -292,7 +291,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: true,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
require.Equal(t, dashboards.ErrDashboardUpdateAccessDenied, err)
assert.Equal(t, sc.savedDashInFolder.Id, sc.dashboardGuardianMock.DashId)
@@ -433,7 +432,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardFolderNotFound, err)
})
@@ -449,7 +448,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardVersionMismatch, err)
})
@@ -489,7 +488,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardVersionMismatch, err)
})
@@ -528,7 +527,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardWithSameNameInFolderExists, err)
})
@@ -544,7 +543,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardWithSameNameInFolderExists, err)
})
@@ -560,7 +559,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardWithSameNameInFolderExists, err)
})
})
@@ -648,7 +647,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardWithSameUIDExists, err)
})
@@ -712,7 +711,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardTypeMismatch, err)
})
@@ -728,7 +727,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardTypeMismatch, err)
})
@@ -744,7 +743,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardTypeMismatch, err)
})
@@ -760,7 +759,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardTypeMismatch, err)
})
@@ -775,7 +774,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardWithSameNameAsFolder, err)
})
@@ -790,7 +789,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
Overwrite: shouldOverwrite,
}
err := callSaveWithError(t, cmd, sc.sqlStore)
err := callSaveWithError(cmd, sc.sqlStore)
assert.Equal(t, dashboards.ErrDashboardFolderWithSameNameAsDashboard, err)
})
})
@@ -822,9 +821,7 @@ func permissionScenario(t *testing.T, desc string, canSave bool, fn permissionSc
cfg.RBACEnabled = false
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
sqlStore := db.InitTestDB(t)
quotaService := quotatest.New(false, nil)
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg), quotaService)
require.NoError(t, err)
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
service := ProvideDashboardService(
cfg, dashboardStore, &dummyDashAlertExtractor{},
featuremgmt.WithFeatures(),
@@ -881,9 +878,7 @@ func callSaveWithResult(t *testing.T, cmd models.SaveDashboardCommand, sqlStore
cfg := setting.NewCfg()
cfg.RBACEnabled = false
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
quotaService := quotatest.New(false, nil)
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg), quotaService)
require.NoError(t, err)
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
service := ProvideDashboardService(
cfg, dashboardStore, &dummyDashAlertExtractor{},
featuremgmt.WithFeatures(),
@@ -897,14 +892,12 @@ func callSaveWithResult(t *testing.T, cmd models.SaveDashboardCommand, sqlStore
return res
}
func callSaveWithError(t *testing.T, cmd models.SaveDashboardCommand, sqlStore db.DB) error {
func callSaveWithError(cmd models.SaveDashboardCommand, sqlStore db.DB) error {
dto := toSaveDashboardDto(cmd)
cfg := setting.NewCfg()
cfg.RBACEnabled = false
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
quotaService := quotatest.New(false, nil)
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg), quotaService)
require.NoError(t, err)
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
service := ProvideDashboardService(
cfg, dashboardStore, &dummyDashAlertExtractor{},
featuremgmt.WithFeatures(),
@@ -912,7 +905,7 @@ func callSaveWithError(t *testing.T, cmd models.SaveDashboardCommand, sqlStore d
accesscontrolmock.NewMockedPermissionsService(),
accesscontrolmock.New(),
)
_, err = service.SaveDashboard(context.Background(), &dto, false)
_, err := service.SaveDashboard(context.Background(), &dto, false)
return err
}
@@ -941,9 +934,7 @@ func saveTestDashboard(t *testing.T, title string, orgID, folderID int64, sqlSto
cfg := setting.NewCfg()
cfg.RBACEnabled = false
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
quotaService := quotatest.New(false, nil)
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg), quotaService)
require.NoError(t, err)
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
service := ProvideDashboardService(
cfg, dashboardStore, &dummyDashAlertExtractor{},
featuremgmt.WithFeatures(),
@@ -981,9 +972,7 @@ func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore db.DB) *mo
cfg := setting.NewCfg()
cfg.RBACEnabled = false
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
quotaService := quotatest.New(false, nil)
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg), quotaService)
require.NoError(t, err)
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
service := ProvideDashboardService(
cfg, dashboardStore, &dummyDashAlertExtractor{},
featuremgmt.WithFeatures(),