mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[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 <dmeza@users.noreply.github.com> Co-authored-by: mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user