Alerting: Fix GetAlertRulesForScheduling to use folder table and join by org_id (#80330)
This commit is contained in:
@@ -566,9 +566,8 @@ func (st DBstore) GetAlertRulesForScheduling(ctx context.Context, query *ngmodel
|
|||||||
query.ResultRules = rules
|
query.ResultRules = rules
|
||||||
|
|
||||||
if query.PopulateFolders {
|
if query.PopulateFolders {
|
||||||
foldersSql := sess.Table("dashboard").Alias("d").Select("d.uid, d.title").
|
foldersSql := sess.Table("folder").Alias("d").Select("d.uid, d.title").
|
||||||
Where("is_folder = ?", st.SQLStore.GetDialect().BooleanStr(true)).
|
Where(`EXISTS (SELECT 1 FROM alert_rule a WHERE d.uid = a.namespace_uid AND d.org_id = a.org_id)`)
|
||||||
And(`EXISTS (SELECT 1 FROM alert_rule a WHERE d.uid = a.namespace_uid)`)
|
|
||||||
if len(disabledOrgs) > 0 {
|
if len(disabledOrgs) > 0 {
|
||||||
foldersSql.NotIn("org_id", disabledOrgs)
|
foldersSql.NotIn("org_id", disabledOrgs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,6 +342,8 @@ func TestIntegration_GetAlertRulesForScheduling(t *testing.T) {
|
|||||||
createFolder(t, store, rule1.NamespaceUID, rule1.Title, rule1.OrgID)
|
createFolder(t, store, rule1.NamespaceUID, rule1.Title, rule1.OrgID)
|
||||||
createFolder(t, store, rule2.NamespaceUID, rule2.Title, rule2.OrgID)
|
createFolder(t, store, rule2.NamespaceUID, rule2.Title, rule2.OrgID)
|
||||||
|
|
||||||
|
createFolder(t, store, rule2.NamespaceUID, "same UID folder", generator().OrgID) // create a folder with the same UID but in the different org
|
||||||
|
|
||||||
tc := []struct {
|
tc := []struct {
|
||||||
name string
|
name string
|
||||||
rules []string
|
rules []string
|
||||||
|
|||||||
Reference in New Issue
Block a user