[v10.1.x] Alerting: Fix deleting rules in a folder with matching UID in another organization (#79007)

* Alerting: Fix deleting rules in a folder with matching UID in another organization (#78258)

* Remove usage of obsolete function for deleting alert rules under folder

* Apply suggestion from code review

* Update tests

(cherry picked from commit 6d4625ad52)

* fixup
This commit is contained in:
Sofia Papagiannaki
2023-12-05 13:30:17 +02:00
committed by GitHub
parent 7a0ee7044b
commit 5bed94f873
11 changed files with 80 additions and 94 deletions
+19 -4
View File
@@ -73,6 +73,16 @@ func TestIntegrationFolderService(t *testing.T) {
cfg := setting.NewCfg()
features := featuremgmt.WithFeatures()
ac := acmock.New().WithPermissions([]accesscontrol.Permission{
{Action: accesscontrol.ActionAlertingRuleDelete, Scope: dashboards.ScopeFoldersAll},
})
alertingStore := ngstore.DBstore{
SQLStore: db,
Cfg: cfg.UnifiedAlerting,
Logger: log.New("test-alerting-store"),
AccessControl: ac,
}
service := &Service{
cfg: cfg,
log: log.New("test-folder-service"),
@@ -83,8 +93,11 @@ func TestIntegrationFolderService(t *testing.T) {
bus: bus.ProvideBus(tracing.InitializeTracerForTest()),
db: db,
accessControl: acimpl.ProvideAccessControl(cfg),
registry: make(map[string]folder.RegistryService),
}
require.NoError(t, service.RegisterService(alertingStore))
t.Run("Given user has no permissions", func(t *testing.T) {
origNewGuardian := guardian.New
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{})
@@ -362,8 +375,10 @@ func TestIntegrationNestedFolderService(t *testing.T) {
signedInUser := user.SignedInUser{UserID: 1, OrgID: orgID, Permissions: map[int64]map[string][]string{
orgID: {
dashboards.ActionFoldersCreate: {},
dashboards.ActionFoldersWrite: {dashboards.ScopeFoldersAll}},
dashboards.ActionFoldersCreate: {},
dashboards.ActionFoldersWrite: {dashboards.ScopeFoldersAll},
accesscontrol.ActionAlertingRuleDelete: {dashboards.ScopeFoldersAll},
},
}}
createCmd := folder.CreateFolderCommand{
OrgID: orgID,
@@ -567,7 +582,7 @@ func TestIntegrationNestedFolderService(t *testing.T) {
prefix: "flagon-noforce",
depth: 3,
forceDelete: false,
deletionErr: dashboards.ErrFolderContainsAlertRules,
deletionErr: folder.ErrFolderNotEmpty,
desc: "With nested folder feature flag on and no force deletion of rules",
},
{
@@ -586,7 +601,7 @@ func TestIntegrationNestedFolderService(t *testing.T) {
prefix: "flagoff-noforce",
depth: 1,
forceDelete: false,
deletionErr: dashboards.ErrFolderContainsAlertRules,
deletionErr: folder.ErrFolderNotEmpty,
desc: "With nested folder feature flag off and no force deletion of rules",
},
}