System Console: Email notification content setting (#7122)

* PLT-7195: Added new config option, new license feature, and config UI to system console. Still need to implement behaviour change in email batching code

* PLT-7195: Modified batch emails to respect email notification content type setting

* PLT-7195: Tweaking the colours a bit

* PLT-7195: Added support for email notification content type setting in immediate (non-batched) notification messages. Attempted to clean up the code somewhat. Unit tests coming in a future commit

* PLT-7195: Added unit tests for non-batched emails

* Checked license when applying email content settings

* Changed return type of getFormattedPostTime
Этот коммит содержится в:
Jonathan
2017-08-05 19:52:35 -04:00
коммит произвёл Saturnino Abril
родитель 9f3713aa98
Коммит 178ccd16cb
19 изменённых файлов: 802 добавлений и 139 удалений

Просмотреть файл

@@ -177,9 +177,30 @@ func sendBatchedEmailNotification(userId string, notifications []*batchedNotific
var contents string
for _, notification := range notifications {
template := utils.NewHTMLTemplate("post_batched_post", user.Locale)
var sender *model.User
schan := Srv.Store.User().Get(notification.post.UserId)
if result := <-schan; result.Err != nil {
l4g.Warn(utils.T("api.email_batching.render_batched_post.sender.app_error"))
continue
} else {
sender = result.Data.(*model.User)
}
contents += renderBatchedPost(template, notification.post, notification.teamName, displayNameFormat, translateFunc)
var channel *model.Channel
cchan := Srv.Store.Channel().Get(notification.post.ChannelId, true)
if result := <-cchan; result.Err != nil {
l4g.Warn(utils.T("api.email_batching.render_batched_post.channel.app_error"))
continue
} else {
channel = result.Data.(*model.Channel)
}
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
if utils.IsLicensed && *utils.License.Features.EmailNotificationContents {
emailNotificationContentsType = *utils.Cfg.EmailSettings.EmailNotificationContentsType
}
contents += renderBatchedPost(notification, channel, sender, *utils.Cfg.ServiceSettings.SiteURL, displayNameFormat, translateFunc, user.Locale, emailNotificationContentsType)
}
tm := time.Unix(notifications[0].post.CreateAt/1000, 0)
@@ -201,15 +222,21 @@ func sendBatchedEmailNotification(userId string, notifications []*batchedNotific
}
}
func renderBatchedPost(template *utils.HTMLTemplate, post *model.Post, teamName string, displayNameFormat string, translateFunc i18n.TranslateFunc) string {
schan := Srv.Store.User().Get(post.UserId)
cchan := Srv.Store.Channel().Get(post.ChannelId, true)
func renderBatchedPost(notification *batchedNotification, channel *model.Channel, sender *model.User, siteURL string, displayNameFormat string, translateFunc i18n.TranslateFunc, userLocale string, emailNotificationContentsType string) string {
// don't include message contents if email notification contents type is set to generic
var template *utils.HTMLTemplate
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
template = utils.NewHTMLTemplate("post_batched_post_full", userLocale)
} else {
template = utils.NewHTMLTemplate("post_batched_post_generic", userLocale)
}
template.Props["Button"] = translateFunc("api.email_batching.render_batched_post.go_to_post")
template.Props["PostMessage"] = GetMessageForNotification(post, translateFunc)
template.Props["PostLink"] = *utils.Cfg.ServiceSettings.SiteURL + "/" + teamName + "/pl/" + post.Id
template.Props["PostMessage"] = GetMessageForNotification(notification.post, translateFunc)
template.Props["PostLink"] = siteURL + "/" + notification.teamName + "/pl/" + notification.post.Id
template.Props["SenderName"] = sender.GetDisplayName(displayNameFormat)
tm := time.Unix(post.CreateAt/1000, 0)
tm := time.Unix(notification.post.CreateAt/1000, 0)
timezone, _ := tm.Zone()
template.Props["Date"] = translateFunc("api.email_batching.render_batched_post.date", map[string]interface{}{
@@ -221,22 +248,17 @@ func renderBatchedPost(template *utils.HTMLTemplate, post *model.Post, teamName
"Timezone": timezone,
})
if result := <-schan; result.Err != nil {
l4g.Warn(utils.T("api.email_batching.render_batched_post.sender.app_error"))
return ""
} else {
template.Props["SenderName"] = result.Data.(*model.User).GetDisplayName(displayNameFormat)
}
if result := <-cchan; result.Err != nil {
l4g.Warn(utils.T("api.email_batching.render_batched_post.channel.app_error"))
return ""
} else if channel := result.Data.(*model.Channel); channel.Type == model.CHANNEL_DIRECT {
if channel.Type == model.CHANNEL_DIRECT {
template.Props["ChannelName"] = translateFunc("api.email_batching.render_batched_post.direct_message")
} else if channel.Type == model.CHANNEL_GROUP {
template.Props["ChannelName"] = translateFunc("api.email_batching.render_batched_post.group_message")
} else {
template.Props["ChannelName"] = channel.DisplayName
// don't include channel name if email notification contents type is set to generic
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
template.Props["ChannelName"] = channel.DisplayName
} else {
template.Props["ChannelName"] = translateFunc("api.email_batching.render_batched_post.notification")
}
}
return template.Render()

Просмотреть файл

@@ -4,6 +4,7 @@
package app
import (
"strings"
"testing"
"time"
@@ -271,3 +272,53 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
t.Fatal("should have sent queued post")
}
}
/*
* Ensures that post contents are not included in notification email when email notification content type is set to generic
*/
func TestRenderBatchedPostGeneric(t *testing.T) {
Setup()
var post = &model.Post{}
post.Message = "This is the message"
var notification = &batchedNotification{}
notification.post = post
var channel = &model.Channel{}
channel.DisplayName = "Some Test Channel"
var sender = &model.User{}
sender.Email = "sender@test.com"
translateFunc := func(translationID string, args ...interface{}) string {
// mock translateFunc just returns the translation id - this is good enough for our purposes
return translationID
}
var rendered = renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_GENERIC)
if strings.Contains(rendered, post.Message) {
t.Fatal("Rendered email should not contain post contents when email notification contents type is set to Generic.")
}
}
/*
* Ensures that post contents included in notification email when email notification content type is set to full
*/
func TestRenderBatchedPostFull(t *testing.T) {
Setup()
var post = &model.Post{}
post.Message = "This is the message"
var notification = &batchedNotification{}
notification.post = post
var channel = &model.Channel{}
channel.DisplayName = "Some Test Channel"
var sender = &model.User{}
sender.Email = "sender@test.com"
translateFunc := func(translationID string, args ...interface{}) string {
// mock translateFunc just returns the translation id - this is good enough for our purposes
return translationID
}
var rendered = renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_FULL)
if !strings.Contains(rendered, post.Message) {
t.Fatal("Rendered email should contain post contents when email notification contents type is set to Full.")
}
}

Просмотреть файл

@@ -349,67 +349,25 @@ func sendNotificationEmail(post *model.Post, user *model.User, channel *model.Ch
// fall back to sending a single email if we can't batch it for some reason
}
var channelName string
var bodyText string
translateFunc := utils.GetUserTranslations(user.Locale)
var subjectText string
var mailTemplate string
var mailParameters map[string]interface{}
if channel.Type == model.CHANNEL_DIRECT {
subjectText = getDirectMessageNotificationEmailSubject(post, translateFunc, utils.Cfg.TeamSettings.SiteName, senderName)
} else {
subjectText = getNotificationEmailSubject(post, translateFunc, utils.Cfg.TeamSettings.SiteName, team.DisplayName)
}
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
if utils.IsLicensed && *utils.License.Features.EmailNotificationContents {
emailNotificationContentsType = *utils.Cfg.EmailSettings.EmailNotificationContentsType
}
teamURL := utils.GetSiteURL() + "/" + team.Name
tm := time.Unix(post.CreateAt/1000, 0)
userLocale := utils.GetUserTranslations(user.Locale)
month := userLocale(tm.Month().String())
day := fmt.Sprintf("%d", tm.Day())
year := fmt.Sprintf("%d", tm.Year())
zone, _ := tm.Zone()
if channel.Type == model.CHANNEL_DIRECT {
bodyText = userLocale("api.post.send_notifications_and_forget.message_body")
subjectText = userLocale("api.post.send_notifications_and_forget.message_subject")
senderDisplayName := senderName
mailTemplate = "api.templates.post_subject_in_direct_message"
mailParameters = map[string]interface{}{"SubjectText": subjectText,
"SenderDisplayName": senderDisplayName, "Month": month, "Day": day, "Year": year}
} else if channel.Type == model.CHANNEL_GROUP {
bodyText = userLocale("api.post.send_notifications_and_forget.mention_body")
senderDisplayName := senderName
mailTemplate = "api.templates.post_subject_in_group_message"
mailParameters = map[string]interface{}{"SenderDisplayName": senderDisplayName, "Month": month, "Day": day, "Year": year}
channelName = userLocale("api.templates.channel_name.group")
} else {
bodyText = userLocale("api.post.send_notifications_and_forget.mention_body")
subjectText = userLocale("api.post.send_notifications_and_forget.mention_subject")
channelName = channel.DisplayName
mailTemplate = "api.templates.post_subject_in_channel"
mailParameters = map[string]interface{}{"SubjectText": subjectText, "TeamDisplayName": team.DisplayName,
"ChannelName": channelName, "Month": month, "Day": day, "Year": year}
}
subject := fmt.Sprintf("[%v] %v", utils.Cfg.TeamSettings.SiteName, userLocale(mailTemplate, mailParameters))
bodyPage := utils.NewHTMLTemplate("post_body", user.Locale)
bodyPage.Props["SiteURL"] = utils.GetSiteURL()
bodyPage.Props["PostMessage"] = GetMessageForNotification(post, userLocale)
if team.Name != "select_team" {
bodyPage.Props["TeamLink"] = teamURL + "/pl/" + post.Id
} else {
bodyPage.Props["TeamLink"] = teamURL
}
bodyPage.Props["BodyText"] = bodyText
bodyPage.Props["Button"] = userLocale("api.templates.post_body.button")
bodyPage.Html["Info"] = template.HTML(userLocale("api.templates.post_body.info",
map[string]interface{}{"ChannelName": channelName, "SenderName": senderName,
"Hour": fmt.Sprintf("%02d", tm.Hour()), "Minute": fmt.Sprintf("%02d", tm.Minute()),
"TimeZone": zone, "Month": month, "Day": day}))
var bodyText = getNotificationEmailBody(user, post, channel, senderName, team.Name, teamURL, emailNotificationContentsType, translateFunc)
go func() {
if err := utils.SendMail(user.Email, html.UnescapeString(subject), bodyPage.Render()); err != nil {
if err := utils.SendMail(user.Email, html.UnescapeString(subjectText), bodyText); err != nil {
l4g.Error(utils.T("api.post.send_notifications_and_forget.send.error"), user.Email, err)
}
}()
@@ -421,6 +379,149 @@ func sendNotificationEmail(post *model.Post, user *model.User, channel *model.Ch
return nil
}
/**
* Computes the subject line for direct notification email messages
*/
func getDirectMessageNotificationEmailSubject(post *model.Post, translateFunc i18n.TranslateFunc, siteName string, senderName string) string {
t := getFormattedPostTime(post, translateFunc)
var subjectParameters = map[string]interface{}{
"SiteName": siteName,
"SenderDisplayName": senderName,
"Month": t.Month,
"Day": t.Day,
"Year": t.Year,
}
return translateFunc("app.notification.subject.direct.full", subjectParameters)
}
/**
* Computes the subject line for group, public, and private email messages
*/
func getNotificationEmailSubject(post *model.Post, translateFunc i18n.TranslateFunc, siteName string, teamName string) string {
t := getFormattedPostTime(post, translateFunc)
var subjectParameters = map[string]interface{}{
"SiteName": siteName,
"TeamName": teamName,
"Month": t.Month,
"Day": t.Day,
"Year": t.Year,
}
return translateFunc("app.notification.subject.notification.full", subjectParameters)
}
/**
* Computes the email body for notification messages
*/
func getNotificationEmailBody(recipient *model.User, post *model.Post, channel *model.Channel, senderName string, teamName string, teamURL string, emailNotificationContentsType string, translateFunc i18n.TranslateFunc) string {
// only include message contents in notification email if email notification contents type is set to full
var bodyPage *utils.HTMLTemplate
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
bodyPage = utils.NewHTMLTemplate("post_body_full", recipient.Locale)
bodyPage.Props["PostMessage"] = GetMessageForNotification(post, translateFunc)
} else {
bodyPage = utils.NewHTMLTemplate("post_body_generic", recipient.Locale)
}
bodyPage.Props["SiteURL"] = utils.GetSiteURL()
if teamName != "select_team" {
bodyPage.Props["TeamLink"] = teamURL + "/pl/" + post.Id
} else {
bodyPage.Props["TeamLink"] = teamURL
}
var channelName = channel.DisplayName
if channel.Type == model.CHANNEL_GROUP {
channelName = translateFunc("api.templates.channel_name.group")
}
t := getFormattedPostTime(post, translateFunc)
var bodyText string
var info string
if channel.Type == model.CHANNEL_DIRECT {
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
bodyText = translateFunc("app.notification.body.intro.direct.full")
info = translateFunc("app.notification.body.text.direct.full",
map[string]interface{}{
"SenderName": senderName,
"Hour": t.Hour,
"Minute": t.Minute,
"TimeZone": t.TimeZone,
"Month": t.Month,
"Day": t.Day,
})
} else {
bodyText = translateFunc("app.notification.body.intro.direct.generic", map[string]interface{}{
"SenderName": senderName,
})
info = translateFunc("app.notification.body.text.direct.generic",
map[string]interface{}{
"Hour": t.Hour,
"Minute": t.Minute,
"TimeZone": t.TimeZone,
"Month": t.Month,
"Day": t.Day,
})
}
} else {
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
bodyText = translateFunc("app.notification.body.intro.notification.full")
info = translateFunc("app.notification.body.text.notification.full",
map[string]interface{}{
"ChannelName": channelName,
"SenderName": senderName,
"Hour": t.Hour,
"Minute": t.Minute,
"TimeZone": t.TimeZone,
"Month": t.Month,
"Day": t.Day,
})
} else {
bodyText = translateFunc("app.notification.body.intro.notification.generic", map[string]interface{}{
"SenderName": senderName,
})
info = translateFunc("app.notification.body.text.notification.generic",
map[string]interface{}{
"Hour": t.Hour,
"Minute": t.Minute,
"TimeZone": t.TimeZone,
"Month": t.Month,
"Day": t.Day,
})
}
}
bodyPage.Props["BodyText"] = bodyText
bodyPage.Html["Info"] = template.HTML(info)
bodyPage.Props["Button"] = translateFunc("api.templates.post_body.button")
return bodyPage.Render()
}
type formattedPostTime struct {
Time time.Time
Year string
Month string
Day string
Hour string
Minute string
TimeZone string
}
func getFormattedPostTime(post *model.Post, translateFunc i18n.TranslateFunc) formattedPostTime {
tm := time.Unix(post.CreateAt/1000, 0)
zone, _ := tm.Zone()
return formattedPostTime{
Time: tm,
Year: fmt.Sprintf("%d", tm.Year()),
Month: translateFunc(tm.Month().String()),
Day: fmt.Sprintf("%d", tm.Day()),
Hour: fmt.Sprintf("%02d", tm.Hour()),
Minute: fmt.Sprintf("%02d", tm.Minute()),
TimeZone: zone,
}
}
func GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFunc) string {
if len(strings.TrimSpace(post.Message)) != 0 || len(post.FileIds) == 0 {
return post.Message

Просмотреть файл

@@ -4,9 +4,11 @@
package app
import (
"strings"
"testing"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
func TestSendNotifications(t *testing.T) {
@@ -817,3 +819,287 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
t.Fatal("Should have been false")
}
}
func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
Setup()
expectedPrefix := "[http://localhost:8065] New Direct Message from sender on"
post := &model.Post{
CreateAt: 1501804801000,
}
translateFunc := utils.GetUserTranslations("en")
subject := getDirectMessageNotificationEmailSubject(post, translateFunc, "http://localhost:8065", "sender")
if !strings.HasPrefix(subject, expectedPrefix) {
t.Fatal("Expected subject line prefix '" + expectedPrefix + "', got " + subject)
}
}
func TestGetNotificationEmailSubject(t *testing.T) {
Setup()
expectedPrefix := "[http://localhost:8065] Notification in team on"
post := &model.Post{
CreateAt: 1501804801000,
}
translateFunc := utils.GetUserTranslations("en")
subject := getNotificationEmailSubject(post, translateFunc, "http://localhost:8065", "team")
if !strings.HasPrefix(subject, expectedPrefix) {
t.Fatal("Expected subject line prefix '" + expectedPrefix + "', got " + subject)
}
}
func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
Setup()
recipient := &model.User{}
post := &model.Post{
Message: "This is the message",
}
channel := &model.Channel{
DisplayName: "ChannelName",
Type: model.CHANNEL_OPEN,
}
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
if !strings.Contains(body, "You have a new notification.") {
t.Fatal("Expected email text 'You have a new notification. Got " + body)
}
if !strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
t.Fatal("Expected email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
}
if !strings.Contains(body, senderName+" - ") {
t.Fatal("Expected email text '" + senderName + " - '. Got " + body)
}
if !strings.Contains(body, post.Message) {
t.Fatal("Expected email text '" + post.Message + "'. Got " + body)
}
if !strings.Contains(body, teamURL) {
t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
}
}
func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
Setup()
recipient := &model.User{}
post := &model.Post{
Message: "This is the message",
}
channel := &model.Channel{
DisplayName: "ChannelName",
Type: model.CHANNEL_GROUP,
}
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
if !strings.Contains(body, "You have a new notification.") {
t.Fatal("Expected email text 'You have a new notification. Got " + body)
}
if !strings.Contains(body, "CHANNEL: Group Message") {
t.Fatal("Expected email text 'CHANNEL: Group Message'. Got " + body)
}
if !strings.Contains(body, senderName+" - ") {
t.Fatal("Expected email text '" + senderName + " - '. Got " + body)
}
if !strings.Contains(body, post.Message) {
t.Fatal("Expected email text '" + post.Message + "'. Got " + body)
}
if !strings.Contains(body, teamURL) {
t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
}
}
func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
Setup()
recipient := &model.User{}
post := &model.Post{
Message: "This is the message",
}
channel := &model.Channel{
DisplayName: "ChannelName",
Type: model.CHANNEL_PRIVATE,
}
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
if !strings.Contains(body, "You have a new notification.") {
t.Fatal("Expected email text 'You have a new notification. Got " + body)
}
if !strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
t.Fatal("Expected email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
}
if !strings.Contains(body, senderName+" - ") {
t.Fatal("Expected email text '" + senderName + " - '. Got " + body)
}
if !strings.Contains(body, post.Message) {
t.Fatal("Expected email text '" + post.Message + "'. Got " + body)
}
if !strings.Contains(body, teamURL) {
t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
}
}
func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
Setup()
recipient := &model.User{}
post := &model.Post{
Message: "This is the message",
}
channel := &model.Channel{
DisplayName: "ChannelName",
Type: model.CHANNEL_DIRECT,
}
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
if !strings.Contains(body, "You have a new direct message.") {
t.Fatal("Expected email text 'You have a new direct message. Got " + body)
}
if !strings.Contains(body, senderName+" - ") {
t.Fatal("Expected email text '" + senderName + " - '. Got " + body)
}
if !strings.Contains(body, post.Message) {
t.Fatal("Expected email text '" + post.Message + "'. Got " + body)
}
if !strings.Contains(body, teamURL) {
t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
}
}
// from here
func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T) {
Setup()
recipient := &model.User{}
post := &model.Post{
Message: "This is the message",
}
channel := &model.Channel{
DisplayName: "ChannelName",
Type: model.CHANNEL_OPEN,
}
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en")
body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
if !strings.Contains(body, "You have a new notification from "+senderName) {
t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
}
if strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
t.Fatal("Did not expect email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
}
if strings.Contains(body, post.Message) {
t.Fatal("Did not expect email text '" + post.Message + "'. Got " + body)
}
if !strings.Contains(body, teamURL) {
t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
}
}
func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
Setup()
recipient := &model.User{}
post := &model.Post{
Message: "This is the message",
}
channel := &model.Channel{
DisplayName: "ChannelName",
Type: model.CHANNEL_GROUP,
}
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en")
body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
if !strings.Contains(body, "You have a new notification from "+senderName) {
t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
}
if strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
t.Fatal("Did not expect email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
}
if strings.Contains(body, post.Message) {
t.Fatal("Did not expect email text '" + post.Message + "'. Got " + body)
}
if !strings.Contains(body, teamURL) {
t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
}
}
func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T) {
Setup()
recipient := &model.User{}
post := &model.Post{
Message: "This is the message",
}
channel := &model.Channel{
DisplayName: "ChannelName",
Type: model.CHANNEL_PRIVATE,
}
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en")
body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
if !strings.Contains(body, "You have a new notification from "+senderName) {
t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
}
if strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
t.Fatal("Did not expect email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
}
if strings.Contains(body, post.Message) {
t.Fatal("Did not expect email text '" + post.Message + "'. Got " + body)
}
if !strings.Contains(body, teamURL) {
t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
}
}
func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) {
Setup()
recipient := &model.User{}
post := &model.Post{
Message: "This is the message",
}
channel := &model.Channel{
DisplayName: "ChannelName",
Type: model.CHANNEL_DIRECT,
}
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en")
body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
if !strings.Contains(body, "You have a new direct message from "+senderName) {
t.Fatal("Expected email text 'You have a new direct message from " + senderName + "'. Got " + body)
}
if strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
t.Fatal("Did not expect email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
}
if strings.Contains(body, post.Message) {
t.Fatal("Did not expect email text '" + post.Message + "'. Got " + body)
}
if !strings.Contains(body, teamURL) {
t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
}
}