Browse Source

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
Marcus Efraimsson 6 years ago
parent
commit
5da1faf454

+ 8 - 0
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)
 		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))
 	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)
 		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))
 	return JSON(200, dtos.NewAlertNotification(cmd.Result))
 }
 }
 
 

+ 1 - 1
pkg/models/alert_notifications.go

@@ -39,7 +39,7 @@ type AlertNotification struct {
 }
 }
 
 
 type CreateAlertNotificationCommand struct {
 type CreateAlertNotificationCommand struct {
-	Uid                   string           `json:"-"`
+	Uid                   string           `json:"uid"`
 	Name                  string           `json:"name"  binding:"Required"`
 	Name                  string           `json:"name"  binding:"Required"`
 	Type                  string           `json:"type"  binding:"Required"`
 	Type                  string           `json:"type"  binding:"Required"`
 	SendReminder          bool             `json:"sendReminder"`
 	SendReminder          bool             `json:"sendReminder"`

+ 2 - 0
pkg/services/sqlstore/alert_notification.go

@@ -382,6 +382,8 @@ func UpdateAlertNotificationWithUid(cmd *m.UpdateAlertNotificationWithUidCommand
 		return err
 		return err
 	}
 	}
 
 
+	cmd.Result = updateNotification.Result
+
 	return nil
 	return nil
 }
 }