From 8e2c59ca006e042c51ee42f81df1df186b09ce87 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Mon, 13 Jan 2020 16:24:28 -0500 Subject: [PATCH] [MM-17155] Changes to email notifications to support Deep Linking page (#13362) * Change link to redirect email notifications to landing page * Fix to undefined variable * Change `vault` to `landing` * Added a couple tests Co-authored-by: David Meza Co-authored-by: mattermod --- app/notification_email.go | 12 ++++----- app/notification_email_test.go | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/app/notification_email.go b/app/notification_email.go index 5da7fc5ddf..fa40a6dd02 100644 --- a/app/notification_email.go +++ b/app/notification_email.go @@ -95,8 +95,8 @@ func (a *App) sendNotificationEmail(notification *PostNotification, user *model. subjectText = getNotificationEmailSubject(user, post, translateFunc, *a.Config().TeamSettings.SiteName, team.DisplayName, useMilitaryTime) } - teamURL := a.GetSiteURL() + "/" + team.Name - var bodyText = a.getNotificationEmailBody(user, post, channel, channelName, senderName, team.Name, teamURL, emailNotificationContentsType, useMilitaryTime, translateFunc) + landingURL := a.GetSiteURL() + "/landing#/" + team.Name + var bodyText = a.getNotificationEmailBody(user, post, channel, channelName, senderName, team.Name, landingURL, emailNotificationContentsType, useMilitaryTime, translateFunc) a.Srv.Go(func() { if err := a.SendNotificationMail(user.Email, html.UnescapeString(subjectText), bodyText); err != nil { @@ -162,14 +162,14 @@ func getGroupMessageNotificationEmailSubject(user *model.User, post *model.Post, /** * Computes the email body for notification messages */ -func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, channel *model.Channel, channelName string, senderName string, teamName string, teamURL string, emailNotificationContentsType string, useMilitaryTime bool, translateFunc i18n.TranslateFunc) string { +func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, channel *model.Channel, channelName string, senderName string, teamName string, landingURL string, emailNotificationContentsType string, useMilitaryTime bool, 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 = a.NewEmailTemplate("post_body_full", recipient.Locale) postMessage := a.GetMessageForNotification(post, translateFunc) postMessage = html.EscapeString(postMessage) - normalizedPostMessage := a.generateHyperlinkForChannels(postMessage, teamName, teamURL) + normalizedPostMessage := a.generateHyperlinkForChannels(postMessage, teamName, landingURL) bodyPage.Props["PostMessage"] = template.HTML(normalizedPostMessage) } else { bodyPage = a.NewEmailTemplate("post_body_generic", recipient.Locale) @@ -177,9 +177,9 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, bodyPage.Props["SiteURL"] = a.GetSiteURL() if teamName != "select_team" { - bodyPage.Props["TeamLink"] = teamURL + "/pl/" + post.Id + bodyPage.Props["TeamLink"] = landingURL + "/pl/" + post.Id } else { - bodyPage.Props["TeamLink"] = teamURL + bodyPage.Props["TeamLink"] = landingURL } t := getFormattedPostTime(recipient, post, useMilitaryTime, translateFunc) diff --git a/app/notification_email_test.go b/app/notification_email_test.go index c15dd9f1eb..aa578658b9 100644 --- a/app/notification_email_test.go +++ b/app/notification_email_test.go @@ -586,3 +586,50 @@ func TestGenerateHyperlinkForChannelsPrivate(t *testing.T) { outMessage := th.App.generateHyperlinkForChannels(message, teamName, teamURL) assert.Equal(t, message, outMessage) } + +func TestLandingLink(t *testing.T) { + th := Setup(t) + defer th.TearDown() + + recipient := &model.User{} + post := &model.Post{ + Message: "This is the message", + } + channel := &model.Channel{ + DisplayName: "ChannelName", + Type: model.CHANNEL_OPEN, + } + channelName := "ChannelName" + senderName := "sender" + teamName := "select_team" + teamURL := "http://localhost:8065/landing#/" + teamName + emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL + translateFunc := utils.GetUserTranslations("en") + + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc) + require.Contains(t, body, teamURL, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body)) +} + +func TestLandingLinkPermalink(t *testing.T) { + th := Setup(t) + defer th.TearDown() + + recipient := &model.User{} + post := &model.Post{ + Id: "Test_id", + Message: "This is the message", + } + channel := &model.Channel{ + DisplayName: "ChannelName", + Type: model.CHANNEL_OPEN, + } + channelName := "ChannelName" + senderName := "sender" + teamName := "team" + teamURL := "http://localhost:8065/landing#/" + teamName + emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL + translateFunc := utils.GetUserTranslations("en") + + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc) + require.Contains(t, body, teamURL+"/pl/"+post.Id, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body)) +}