Docs: Rename Message templates to Notification templates (#59477)

This commit renames "Message templates" to "Notification templates"
in the user interface as it suggests that these templates cannot
be used to template anything other than the message. However, message
templates are much more general and can be used to template other fields
too such as the subject of an email, or the title of a Slack message.
This commit is contained in:
George Robinson
2023-01-18 17:26:34 +00:00
committed by GitHub
parent c54aa18cd8
commit d4256b352d
30 changed files with 513 additions and 268 deletions
@@ -650,7 +650,7 @@ func setContactPointProvenance(t *testing.T, orgID int64, UID string, ps provisi
// setTemplateProvenance marks a template as provisioned.
func setTemplateProvenance(t *testing.T, orgID int64, name string, ps provisioning.ProvisioningStore) {
t.Helper()
err := ps.SetProvenance(context.Background(), &apimodels.MessageTemplate{Name: name}, orgID, ngmodels.ProvenanceAPI)
err := ps.SetProvenance(context.Background(), &apimodels.NotificationTemplate{Name: name}, orgID, ngmodels.ProvenanceAPI)
require.NoError(t, err)
}
+6 -6
View File
@@ -35,7 +35,7 @@ type ContactPointService interface {
type TemplateService interface {
GetTemplates(ctx context.Context, orgID int64) (map[string]string, error)
SetTemplate(ctx context.Context, orgID int64, tmpl definitions.MessageTemplate) (definitions.MessageTemplate, error)
SetTemplate(ctx context.Context, orgID int64, tmpl definitions.NotificationTemplate) (definitions.NotificationTemplate, error)
DeleteTemplate(ctx context.Context, orgID int64, name string) error
}
@@ -149,9 +149,9 @@ func (srv *ProvisioningSrv) RouteGetTemplates(c *models.ReqContext) response.Res
if err != nil {
return ErrResp(http.StatusInternalServerError, err, "")
}
result := make([]definitions.MessageTemplate, 0, len(templates))
result := make([]definitions.NotificationTemplate, 0, len(templates))
for k, v := range templates {
result = append(result, definitions.MessageTemplate{Name: k, Template: v})
result = append(result, definitions.NotificationTemplate{Name: k, Template: v})
}
return response.JSON(http.StatusOK, result)
}
@@ -162,13 +162,13 @@ func (srv *ProvisioningSrv) RouteGetTemplate(c *models.ReqContext, name string)
return ErrResp(http.StatusInternalServerError, err, "")
}
if tmpl, ok := templates[name]; ok {
return response.JSON(http.StatusOK, definitions.MessageTemplate{Name: name, Template: tmpl})
return response.JSON(http.StatusOK, definitions.NotificationTemplate{Name: name, Template: tmpl})
}
return response.Empty(http.StatusNotFound)
}
func (srv *ProvisioningSrv) RoutePutTemplate(c *models.ReqContext, body definitions.MessageTemplateContent, name string) response.Response {
tmpl := definitions.MessageTemplate{
func (srv *ProvisioningSrv) RoutePutTemplate(c *models.ReqContext, body definitions.NotificationTemplateContent, name string) response.Response {
tmpl := definitions.NotificationTemplate{
Name: name,
Template: body.Template,
Provenance: alerting_models.ProvenanceAPI,
@@ -178,7 +178,7 @@ func TestProvisioningApi(t *testing.T) {
t.Run("PUT returns 400", func(t *testing.T) {
sut := createProvisioningSrvSut(t)
rc := createTestRequestCtx()
tmpl := definitions.MessageTemplateContent{Template: ""}
tmpl := definitions.NotificationTemplateContent{Template: ""}
response := sut.RoutePutTemplate(&rc, tmpl, "test")
@@ -177,7 +177,7 @@ func (f *ProvisioningApiHandler) RoutePutTemplate(ctx *models.ReqContext) respon
// Parse Path Parameters
nameParam := web.Params(ctx.Req)[":name"]
// Parse Request Body
conf := apimodels.MessageTemplateContent{}
conf := apimodels.NotificationTemplateContent{}
if err := web.Bind(ctx.Req, &conf); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err)
}
+1 -1
View File
@@ -48,7 +48,7 @@ func (f *ProvisioningApiHandler) handleRouteGetTemplate(ctx *models.ReqContext,
return f.svc.RouteGetTemplate(ctx, name)
}
func (f *ProvisioningApiHandler) handleRoutePutTemplate(ctx *models.ReqContext, body apimodels.MessageTemplateContent, name string) response.Response {
func (f *ProvisioningApiHandler) handleRoutePutTemplate(ctx *models.ReqContext, body apimodels.NotificationTemplateContent, name string) response.Response {
return f.svc.RoutePutTemplate(ctx, body, name)
}
+59 -42
View File
@@ -7,6 +7,26 @@
"Ack": {
"type": "object"
},
"AddCommand": {
"properties": {
"name": {
"type": "string"
},
"role": {
"enum": [
"Viewer",
"Editor",
"Admin"
],
"type": "string"
},
"secondsToLive": {
"format": "int64",
"type": "integer"
}
},
"type": "object"
},
"Alert": {
"properties": {
"activeAt": {
@@ -1491,34 +1511,6 @@
},
"type": "array"
},
"MessageTemplate": {
"properties": {
"name": {
"type": "string"
},
"provenance": {
"$ref": "#/definitions/Provenance"
},
"template": {
"type": "string"
}
},
"type": "object"
},
"MessageTemplateContent": {
"properties": {
"template": {
"type": "string"
}
},
"type": "object"
},
"MessageTemplates": {
"items": {
"$ref": "#/definitions/MessageTemplate"
},
"type": "array"
},
"MultiStatus": {
"type": "object"
},
@@ -1580,6 +1572,34 @@
"title": "NoticeSeverity is a type for the Severity property of a Notice.",
"type": "integer"
},
"NotificationTemplate": {
"properties": {
"name": {
"type": "string"
},
"provenance": {
"$ref": "#/definitions/Provenance"
},
"template": {
"type": "string"
}
},
"type": "object"
},
"NotificationTemplateContent": {
"properties": {
"template": {
"type": "string"
}
},
"type": "object"
},
"NotificationTemplates": {
"items": {
"$ref": "#/definitions/NotificationTemplate"
},
"type": "array"
},
"NotifierConfig": {
"properties": {
"send_resolved": {
@@ -3352,7 +3372,6 @@
"type": "object"
},
"alertGroups": {
"description": "AlertGroups alert groups",
"items": {
"$ref": "#/definitions/alertGroup"
},
@@ -3513,14 +3532,12 @@
"type": "object"
},
"gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"items": {
"$ref": "#/definitions/gettableAlert"
},
"type": "array"
},
"gettableSilence": {
"description": "GettableSilence gettable silence",
"properties": {
"comment": {
"description": "comment",
@@ -3569,7 +3586,6 @@
"type": "object"
},
"gettableSilences": {
"description": "GettableSilences gettable silences",
"items": {
"$ref": "#/definitions/gettableSilence"
},
@@ -3756,6 +3772,7 @@
"type": "object"
},
"receiver": {
"description": "Receiver receiver",
"properties": {
"active": {
"description": "active",
@@ -4442,16 +4459,16 @@
"operationId": "RouteGetTemplates",
"responses": {
"200": {
"description": "MessageTemplates",
"description": "NotificationTemplates",
"schema": {
"$ref": "#/definitions/MessageTemplates"
"$ref": "#/definitions/NotificationTemplates"
}
},
"404": {
"description": " Not found."
}
},
"summary": "Get all message templates.",
"summary": "Get all notification templates.",
"tags": [
"provisioning"
]
@@ -4492,16 +4509,16 @@
],
"responses": {
"200": {
"description": "MessageTemplate",
"description": "NotificationTemplate",
"schema": {
"$ref": "#/definitions/MessageTemplate"
"$ref": "#/definitions/NotificationTemplate"
}
},
"404": {
"description": " Not found."
}
},
"summary": "Get a message template.",
"summary": "Get a notification template.",
"tags": [
"provisioning"
]
@@ -4523,15 +4540,15 @@
"in": "body",
"name": "Body",
"schema": {
"$ref": "#/definitions/MessageTemplateContent"
"$ref": "#/definitions/NotificationTemplateContent"
}
}
],
"responses": {
"202": {
"description": "MessageTemplate",
"description": "NotificationTemplate",
"schema": {
"$ref": "#/definitions/MessageTemplate"
"$ref": "#/definitions/NotificationTemplate"
}
},
"400": {
@@ -4541,7 +4558,7 @@
}
}
},
"summary": "Updates an existing template.",
"summary": "Updates an existing notification template.",
"tags": [
"provisioning"
]
@@ -57,7 +57,7 @@ func (r *Route) validateChild() error {
return nil
}
func (t *MessageTemplate) Validate() error {
func (t *NotificationTemplate) Validate() error {
if t.Name == "" {
return fmt.Errorf("template must have a name")
}
@@ -6,29 +6,29 @@ import (
// swagger:route GET /api/v1/provisioning/templates provisioning stable RouteGetTemplates
//
// Get all message templates.
// Get all notification templates.
//
// Responses:
// 200: MessageTemplates
// 200: NotificationTemplates
// 404: description: Not found.
// swagger:route GET /api/v1/provisioning/templates/{name} provisioning stable RouteGetTemplate
//
// Get a message template.
// Get a notification template.
//
// Responses:
// 200: MessageTemplate
// 200: NotificationTemplate
// 404: description: Not found.
// swagger:route PUT /api/v1/provisioning/templates/{name} provisioning stable RoutePutTemplate
//
// Updates an existing template.
// Updates an existing notification template.
//
// Consumes:
// - application/json
//
// Responses:
// 202: MessageTemplate
// 202: NotificationTemplate
// 400: ValidationError
// swagger:route DELETE /api/v1/provisioning/templates/{name} provisioning stable RouteDeleteTemplate
@@ -46,29 +46,29 @@ type RouteGetTemplateParam struct {
}
// swagger:model
type MessageTemplate struct {
type NotificationTemplate struct {
Name string `json:"name"`
Template string `json:"template"`
Provenance models.Provenance `json:"provenance,omitempty"`
}
// swagger:model
type MessageTemplates []MessageTemplate
type NotificationTemplates []NotificationTemplate
type MessageTemplateContent struct {
type NotificationTemplateContent struct {
Template string `json:"template"`
}
// swagger:parameters RoutePutTemplate
type MessageTemplatePayload struct {
type NotificationTemplatePayload struct {
// in:body
Body MessageTemplateContent
Body NotificationTemplateContent
}
func (t *MessageTemplate) ResourceType() string {
func (t *NotificationTemplate) ResourceType() string {
return "template"
}
func (t *MessageTemplate) ResourceID() string {
func (t *NotificationTemplate) ResourceID() string {
return t.Name
}
+39 -40
View File
@@ -1491,34 +1491,6 @@
},
"type": "array"
},
"MessageTemplate": {
"properties": {
"name": {
"type": "string"
},
"provenance": {
"$ref": "#/definitions/Provenance"
},
"template": {
"type": "string"
}
},
"type": "object"
},
"MessageTemplateContent": {
"properties": {
"template": {
"type": "string"
}
},
"type": "object"
},
"MessageTemplates": {
"items": {
"$ref": "#/definitions/MessageTemplate"
},
"type": "array"
},
"MultiStatus": {
"type": "object"
},
@@ -1580,6 +1552,34 @@
"title": "NoticeSeverity is a type for the Severity property of a Notice.",
"type": "integer"
},
"NotificationTemplate": {
"properties": {
"name": {
"type": "string"
},
"provenance": {
"$ref": "#/definitions/Provenance"
},
"template": {
"type": "string"
}
},
"type": "object"
},
"NotificationTemplateContent": {
"properties": {
"template": {
"type": "string"
}
},
"type": "object"
},
"NotificationTemplates": {
"items": {
"$ref": "#/definitions/NotificationTemplate"
},
"type": "array"
},
"NotifierConfig": {
"properties": {
"send_resolved": {
@@ -3455,6 +3455,7 @@
"type": "object"
},
"gettableAlert": {
"description": "GettableAlert gettable alert",
"properties": {
"annotations": {
"$ref": "#/definitions/labelSet"
@@ -3510,7 +3511,6 @@
"type": "object"
},
"gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"items": {
"$ref": "#/definitions/gettableAlert"
},
@@ -3752,7 +3752,6 @@
"type": "object"
},
"receiver": {
"description": "Receiver receiver",
"properties": {
"active": {
"description": "active",
@@ -6111,16 +6110,16 @@
"operationId": "RouteGetTemplates",
"responses": {
"200": {
"description": "MessageTemplates",
"description": "NotificationTemplates",
"schema": {
"$ref": "#/definitions/MessageTemplates"
"$ref": "#/definitions/NotificationTemplates"
}
},
"404": {
"description": " Not found."
}
},
"summary": "Get all message templates.",
"summary": "Get all notification templates.",
"tags": [
"provisioning"
]
@@ -6161,16 +6160,16 @@
],
"responses": {
"200": {
"description": "MessageTemplate",
"description": "NotificationTemplate",
"schema": {
"$ref": "#/definitions/MessageTemplate"
"$ref": "#/definitions/NotificationTemplate"
}
},
"404": {
"description": " Not found."
}
},
"summary": "Get a message template.",
"summary": "Get a notification template.",
"tags": [
"provisioning"
]
@@ -6192,15 +6191,15 @@
"in": "body",
"name": "Body",
"schema": {
"$ref": "#/definitions/MessageTemplateContent"
"$ref": "#/definitions/NotificationTemplateContent"
}
}
],
"responses": {
"202": {
"description": "MessageTemplate",
"description": "NotificationTemplate",
"schema": {
"$ref": "#/definitions/MessageTemplate"
"$ref": "#/definitions/NotificationTemplate"
}
},
"400": {
@@ -6210,7 +6209,7 @@
}
}
},
"summary": "Updates an existing template.",
"summary": "Updates an existing notification template.",
"tags": [
"provisioning"
]
+39 -40
View File
@@ -2276,13 +2276,13 @@
"provisioning",
"stable"
],
"summary": "Get all message templates.",
"summary": "Get all notification templates.",
"operationId": "RouteGetTemplates",
"responses": {
"200": {
"description": "MessageTemplates",
"description": "NotificationTemplates",
"schema": {
"$ref": "#/definitions/MessageTemplates"
"$ref": "#/definitions/NotificationTemplates"
}
},
"404": {
@@ -2297,7 +2297,7 @@
"provisioning",
"stable"
],
"summary": "Get a message template.",
"summary": "Get a notification template.",
"operationId": "RouteGetTemplate",
"parameters": [
{
@@ -2310,9 +2310,9 @@
],
"responses": {
"200": {
"description": "MessageTemplate",
"description": "NotificationTemplate",
"schema": {
"$ref": "#/definitions/MessageTemplate"
"$ref": "#/definitions/NotificationTemplate"
}
},
"404": {
@@ -2328,7 +2328,7 @@
"provisioning",
"stable"
],
"summary": "Updates an existing template.",
"summary": "Updates an existing notification template.",
"operationId": "RoutePutTemplate",
"parameters": [
{
@@ -2342,15 +2342,15 @@
"name": "Body",
"in": "body",
"schema": {
"$ref": "#/definitions/MessageTemplateContent"
"$ref": "#/definitions/NotificationTemplateContent"
}
}
],
"responses": {
"202": {
"description": "MessageTemplate",
"description": "NotificationTemplate",
"schema": {
"$ref": "#/definitions/MessageTemplate"
"$ref": "#/definitions/NotificationTemplate"
}
},
"400": {
@@ -3977,34 +3977,6 @@
},
"$ref": "#/definitions/Matchers"
},
"MessageTemplate": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"provenance": {
"$ref": "#/definitions/Provenance"
},
"template": {
"type": "string"
}
}
},
"MessageTemplateContent": {
"type": "object",
"properties": {
"template": {
"type": "string"
}
}
},
"MessageTemplates": {
"type": "array",
"items": {
"$ref": "#/definitions/MessageTemplate"
}
},
"MultiStatus": {
"type": "object"
},
@@ -4066,6 +4038,34 @@
"format": "int64",
"title": "NoticeSeverity is a type for the Severity property of a Notice."
},
"NotificationTemplate": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"provenance": {
"$ref": "#/definitions/Provenance"
},
"template": {
"type": "string"
}
}
},
"NotificationTemplateContent": {
"type": "object",
"properties": {
"template": {
"type": "string"
}
}
},
"NotificationTemplates": {
"type": "array",
"items": {
"$ref": "#/definitions/NotificationTemplate"
}
},
"NotifierConfig": {
"type": "object",
"title": "NotifierConfig contains base options common across all notifier configurations.",
@@ -5943,6 +5943,7 @@
}
},
"gettableAlert": {
"description": "GettableAlert gettable alert",
"type": "object",
"required": [
"labels",
@@ -5999,7 +6000,6 @@
"$ref": "#/definitions/gettableAlert"
},
"gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"type": "array",
"items": {
"$ref": "#/definitions/gettableAlert"
@@ -6246,7 +6246,6 @@
"$ref": "#/definitions/postableSilence"
},
"receiver": {
"description": "Receiver receiver",
"type": "object",
"required": [
"active",