mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix receiver inheritance when provisioning a notification policy (#82007)
Terraform Issue: grafana/terraform-provider-grafana#1007 Nested routes should be allowed to inherit the contact point from the root (or direct parent) route but this fails in the provisioning API (it works in the UI)
This commit is contained in:
@@ -70,6 +70,7 @@ func (nps *NotificationPolicyService) UpdatePolicyTree(ctx context.Context, orgI
|
||||
return err
|
||||
}
|
||||
|
||||
receivers[""] = struct{}{} // Allow empty receiver (inheriting from parent)
|
||||
err = tree.ValidateReceivers(receivers)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrValidation, err.Error())
|
||||
|
||||
@@ -92,6 +92,31 @@ func TestNotificationPolicyService(t *testing.T) {
|
||||
require.Equal(t, "slack receiver", updated.Receiver)
|
||||
})
|
||||
|
||||
t.Run("no root receiver will error", func(t *testing.T) {
|
||||
sut := createNotificationPolicyServiceSut()
|
||||
|
||||
newRoute := createTestRoutingTree()
|
||||
newRoute.Receiver = ""
|
||||
newRoute.Routes = append(newRoute.Routes, &definitions.Route{
|
||||
Receiver: "",
|
||||
})
|
||||
|
||||
err := sut.UpdatePolicyTree(context.Background(), 1, newRoute, models.ProvenanceNone)
|
||||
require.EqualError(t, err, "invalid object specification: root route must specify a default receiver")
|
||||
})
|
||||
|
||||
t.Run("allow receiver inheritance", func(t *testing.T) {
|
||||
sut := createNotificationPolicyServiceSut()
|
||||
|
||||
newRoute := createTestRoutingTree()
|
||||
newRoute.Routes = append(newRoute.Routes, &definitions.Route{
|
||||
Receiver: "",
|
||||
})
|
||||
|
||||
err := sut.UpdatePolicyTree(context.Background(), 1, newRoute, models.ProvenanceNone)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("not existing receiver reference will error", func(t *testing.T) {
|
||||
sut := createNotificationPolicyServiceSut()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user