mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Alerting: Fix GetAlertRulesForScheduling to use folder table and join by org_id (#80330)
This commit is contained in:
parent
e1aa8a95d9
commit
77db6a9ca4
@ -566,9 +566,8 @@ func (st DBstore) GetAlertRulesForScheduling(ctx context.Context, query *ngmodel
|
||||
query.ResultRules = rules
|
||||
|
||||
if query.PopulateFolders {
|
||||
foldersSql := sess.Table("dashboard").Alias("d").Select("d.uid, d.title").
|
||||
Where("is_folder = ?", st.SQLStore.GetDialect().BooleanStr(true)).
|
||||
And(`EXISTS (SELECT 1 FROM alert_rule a WHERE d.uid = a.namespace_uid)`)
|
||||
foldersSql := sess.Table("folder").Alias("d").Select("d.uid, d.title").
|
||||
Where(`EXISTS (SELECT 1 FROM alert_rule a WHERE d.uid = a.namespace_uid AND d.org_id = a.org_id)`)
|
||||
if len(disabledOrgs) > 0 {
|
||||
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, 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 {
|
||||
name string
|
||||
rules []string
|
||||
|
Loading…
Reference in New Issue
Block a user