From 5da1faf4549c40d6e046e987d08f15222595bed4 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Thu, 4 Apr 2019 17:52:40 +0200 Subject: [PATCH] Alerting: Notification channel http api fixes (#16379) Fixes so it's possible to create new notification channel and providing uid. Fixes better error/result handling when updating a notifcation channel. Fixes #16372 Ref #16219 #16012 --- pkg/api/alerting.go | 8 ++++++++ pkg/models/alert_notifications.go | 2 +- pkg/services/sqlstore/alert_notification.go | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index 64f80598821..0cd00d3b015 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -261,6 +261,10 @@ func UpdateAlertNotification(c *m.ReqContext, cmd m.UpdateAlertNotificationComma return Error(500, "Failed to update alert notification", err) } + if cmd.Result == nil { + return Error(404, "Alert notification not found", nil) + } + return JSON(200, dtos.NewAlertNotification(cmd.Result)) } @@ -272,6 +276,10 @@ func UpdateAlertNotificationByUID(c *m.ReqContext, cmd m.UpdateAlertNotification return Error(500, "Failed to update alert notification", err) } + if cmd.Result == nil { + return Error(404, "Alert notification not found", nil) + } + return JSON(200, dtos.NewAlertNotification(cmd.Result)) } diff --git a/pkg/models/alert_notifications.go b/pkg/models/alert_notifications.go index 1d445b5eb72..ccfd6ee84db 100644 --- a/pkg/models/alert_notifications.go +++ b/pkg/models/alert_notifications.go @@ -39,7 +39,7 @@ type AlertNotification struct { } type CreateAlertNotificationCommand struct { - Uid string `json:"-"` + Uid string `json:"uid"` Name string `json:"name" binding:"Required"` Type string `json:"type" binding:"Required"` SendReminder bool `json:"sendReminder"` diff --git a/pkg/services/sqlstore/alert_notification.go b/pkg/services/sqlstore/alert_notification.go index 7c376419161..898ab9ebc66 100644 --- a/pkg/services/sqlstore/alert_notification.go +++ b/pkg/services/sqlstore/alert_notification.go @@ -382,6 +382,8 @@ func UpdateAlertNotificationWithUid(cmd *m.UpdateAlertNotificationWithUidCommand return err } + cmd.Result = updateNotification.Result + return nil }