Alerting: Fix updating notification channels in legacy (#45302) (#45331)

The problem here is that without the orgID we ignore the lookup of the existing notification channel just before updating and end up failing the update because there is no channel available.

(cherry picked from commit 8bf2e642aa)

Co-authored-by: gotjosh <josue.abreu@gmail.com>
This commit is contained in:
Grot (@grafanabot) 2022-02-16 08:35:39 -05:00 committed by GitHub
parent 5b73b4e070
commit 3179d548bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package alerting
import (
"context"
"fmt"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
@ -74,6 +75,7 @@ func (s *AlertNotificationService) UpdateAlertNotification(ctx context.Context,
model := models.AlertNotification{
Id: cmd.Id,
OrgId: cmd.OrgId,
Name: cmd.Name,
Type: cmd.Type,
Settings: cmd.Settings,
@ -134,7 +136,11 @@ func (s *AlertNotificationService) createNotifier(ctx context.Context, model *mo
return nil, err
}
if query.Result != nil && query.Result.SecureSettings != nil {
if query.Result == nil {
return nil, fmt.Errorf("unable to find the alert notification")
}
if query.Result.SecureSettings != nil {
var err error
secureSettingsMap, err = s.EncryptionService.DecryptJsonData(ctx, query.Result.SecureSettings, setting.SecretKey)
if err != nil {