3
0
mirror of https://github.com/grafana/grafana.git synced 2025-02-25 18:55:37 -06:00
grafana/pkg/services/ngalert/middleware.go
Sofia Papagiannaki 5560be73bf
Alerting NG: update API to expect UIDs instead of IDs ()
* Change API to expect UIDs instead of ID

* Remove unnecessary transactions

When only one query is executed

* Modify API responses

* Cleanup tests

* Use globally orgID and UID for identifying alert definitions
2021-01-07 17:45:42 +02:00

21 lines
521 B
Go

package ngalert
import (
"github.com/grafana/grafana/pkg/models"
)
func (ng *AlertNG) validateOrgAlertDefinition(c *models.ReqContext) {
uid := c.ParamsEscape(":alertDefinitionUID")
query := getAlertDefinitionByUIDQuery{UID: uid, OrgID: c.SignedInUser.OrgId}
if err := ng.getAlertDefinitionByUID(&query); err != nil {
c.JsonApiErr(404, "Alert definition not found", nil)
return
}
if c.OrgId != query.Result.OrgID {
c.JsonApiErr(403, "You are not allowed to edit/view alert definition", nil)
return
}
}