From 0dbaa2d032ae42cbf39945df12efb20fc572b559 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Fri, 11 May 2018 17:20:47 +0200 Subject: [MM-10458] Change system response to "Could not find the channel" - bug fix (#8738) * [MM-10458] Change system response to "Could not find the channel" when trying to invite user to private channel you can't see * add another check to check if user have permission to add another in pvt channel --- app/apptestlib.go | 23 +++++++++++++++++++++++ app/command_invite.go | 10 +++++++++- app/command_invite_test.go | 7 +++++++ 3 files changed, 39 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/apptestlib.go b/app/apptestlib.go index 626e932e8..b245ddabf 100644 --- a/app/apptestlib.go +++ b/app/apptestlib.go @@ -227,6 +227,29 @@ func (me *TestHelper) createChannel(team *model.Team, channelType string) *model return channel } +func (me *TestHelper) createChannelWithAnotherUser(team *model.Team, channelType, userId string) *model.Channel { + id := model.NewId() + + channel := &model.Channel{ + DisplayName: "dn_" + id, + Name: "name_" + id, + Type: channelType, + TeamId: team.Id, + CreatorId: userId, + } + + utils.DisableDebugLogForTest() + var err *model.AppError + if channel, err = me.App.CreateChannel(channel, true); err != nil { + mlog.Error(err.Error()) + + time.Sleep(time.Second) + panic(err) + } + utils.EnableDebugLogForTest() + return channel +} + func (me *TestHelper) CreateDmChannel(user *model.User) *model.Channel { utils.DisableDebugLogForTest() var err *model.AppError diff --git a/app/command_invite.go b/app/command_invite.go index 4b76c0c45..54cf2da02 100644 --- a/app/command_invite.go +++ b/app/command_invite.go @@ -79,10 +79,18 @@ func (me *InviteProvider) DoCommand(a *App, args *model.CommandArgs, message str return &model.CommandResponse{Text: args.T("api.command_invite.permission.app_error", map[string]interface{}{"User": userProfile.Username, "Channel": channelToJoin.Name}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } - if channelToJoin.Type == model.CHANNEL_PRIVATE && !a.SessionHasPermissionToChannel(args.Session, channelToJoin.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) { + // Check if the user who wants to add another is trying to add in a pvt channel, but does not have permission + // but is in the channel + _, err = a.GetChannelMember(channelToJoin.Id, args.UserId) + if channelToJoin.Type == model.CHANNEL_PRIVATE && !a.SessionHasPermissionToChannel(args.Session, channelToJoin.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) && err == nil { return &model.CommandResponse{Text: args.T("api.command_invite.permission.app_error", map[string]interface{}{"User": userProfile.Username, "Channel": channelToJoin.Name}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } + // In this case just check if is a pvt channel and user has permission + if channelToJoin.Type == model.CHANNEL_PRIVATE && !a.SessionHasPermissionToChannel(args.Session, channelToJoin.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) { + return &model.CommandResponse{Text: args.T("api.command_invite.private_channel.app_error", map[string]interface{}{"Channel": channelToJoin.Name}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} + } + // Check if user is already in the channel _, err = a.GetChannelMember(channelToJoin.Id, userProfile.Id) if err == nil { diff --git a/app/command_invite_test.go b/app/command_invite_test.go index c46bc4628..0d1db4a07 100644 --- a/app/command_invite_test.go +++ b/app/command_invite_test.go @@ -18,6 +18,7 @@ func TestInviteProvider(t *testing.T) { channel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN) privateChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE) dmChannel := th.CreateDmChannel(th.BasicUser2) + privateChannel2 := th.createChannelWithAnotherUser(th.BasicTeam, model.CHANNEL_PRIVATE, th.BasicUser2.Id) basicUser3 := th.CreateUser() th.LinkUserToTeam(basicUser3, th.BasicTeam) @@ -36,6 +37,7 @@ func TestInviteProvider(t *testing.T) { userAndDisplayChannel := "@" + th.BasicUser2.Username + " ~" + channel.DisplayName + " " userAndPrivateChannel := "@" + th.BasicUser2.Username + " ~" + privateChannel.Name userAndDMChannel := "@" + basicUser3.Username + " ~" + dmChannel.Name + userAndInvalidPrivate := "@" + basicUser3.Username + " ~" + privateChannel2.Name tests := []struct { desc string @@ -97,6 +99,11 @@ func TestInviteProvider(t *testing.T) { expected: "api.command_invite.directchannel.app_error", msg: userAndDMChannel, }, + { + desc: "try to add a user to a privante channel with no permission", + expected: "api.command_invite.private_channel.app_error", + msg: userAndInvalidPrivate, + }, } for _, test := range tests { -- cgit v1.2.3-1-g7c22 From 91c998156336e34ab4b8979db77cc65c97a65782 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 11 May 2018 11:56:02 -0400 Subject: More potential panic fixes (#8776) --- app/web_hub.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/web_hub.go b/app/web_hub.go index f69645f50..2ce78b5ef 100644 --- a/app/web_hub.go +++ b/app/web_hub.go @@ -177,8 +177,9 @@ func (a *App) Publish(message *model.WebSocketEvent) { func (a *App) PublishSkipClusterSend(message *model.WebSocketEvent) { if message.Broadcast.UserId != "" { - if len(a.Hubs) != 0 { - a.GetHubForUserId(message.Broadcast.UserId).Broadcast(message) + hub := a.GetHubForUserId(message.Broadcast.UserId) + if hub != nil { + hub.Broadcast(message) } } else { for _, hub := range a.Hubs { @@ -299,8 +300,9 @@ func (a *App) InvalidateCacheForUserSkipClusterSend(userId string) { a.Srv.Store.User().InvalidateProfilesInChannelCacheByUser(userId) a.Srv.Store.User().InvalidatProfileCacheForUser(userId) - if len(a.Hubs) != 0 { - a.GetHubForUserId(userId).InvalidateUser(userId) + hub := a.GetHubForUserId(userId) + if hub != nil { + hub.InvalidateUser(userId) } } @@ -322,8 +324,9 @@ func (a *App) InvalidateCacheForWebhookSkipClusterSend(webhookId string) { } func (a *App) InvalidateWebConnSessionCacheForUser(userId string) { - if len(a.Hubs) != 0 { - a.GetHubForUserId(userId).InvalidateUser(userId) + hub := a.GetHubForUserId(userId) + if hub != nil { + hub.InvalidateUser(userId) } } -- cgit v1.2.3-1-g7c22 From 4ce37601a15a7af11d33465d1ae92de26f7fa498 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Sat, 12 May 2018 00:57:20 +0800 Subject: add notification when @user, @here, @all and @channel has colon ":" at the end (#8760) --- app/notification.go | 13 ++++++------ app/notification_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/notification.go b/app/notification.go index 7198de764..4bdc6c94f 100644 --- a/app/notification.go +++ b/app/notification.go @@ -919,12 +919,13 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit // remove trailing '.', as that is the end of a sentence foundWithSuffix := false - - for strings.HasSuffix(word, ".") { - word = strings.TrimSuffix(word, ".") - if checkForMention(word) { - foundWithSuffix = true - break + for _, suffixPunctuation := range []string{".", ":"} { + for strings.HasSuffix(word, suffixPunctuation) { + word = strings.TrimSuffix(word, suffixPunctuation) + if checkForMention(word) { + foundWithSuffix = true + break + } } } diff --git a/app/notification_test.go b/app/notification_test.go index 3b8b4adf5..818ad1d9d 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -148,6 +148,16 @@ func TestGetExplicitMentions(t *testing.T) { OtherPotentialMentions: []string{"user"}, }, }, + "OnePersonWithColonAtEnd": { + Message: "this is a message for @user:", + Keywords: map[string][]string{"this": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + OtherPotentialMentions: []string{"user"}, + }, + }, "MultiplePeopleWithOneWord": { Message: "this is a message for @user", Keywords: map[string][]string{"@user": {id1, id2}}, @@ -188,6 +198,18 @@ func TestGetExplicitMentions(t *testing.T) { ChannelMentioned: true, }, }, + + "ChannelWithColonAtEnd": { + Message: "this is a message for @channel:", + Keywords: map[string][]string{"@channel": {id1, id2}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + id2: true, + }, + ChannelMentioned: true, + }, + }, "CapitalizedChannel": { Message: "this is an message for @cHaNNeL", Keywords: map[string][]string{"@channel": {id1, id2}}, @@ -210,6 +232,17 @@ func TestGetExplicitMentions(t *testing.T) { AllMentioned: true, }, }, + "AllWithColonAtEnd": { + Message: "this is a message for @all:", + Keywords: map[string][]string{"@all": {id1, id2}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + id2: true, + }, + AllMentioned: true, + }, + }, "CapitalizedAll": { Message: "this is an message for @ALL", Keywords: map[string][]string{"@all": {id1, id2}}, @@ -230,6 +263,15 @@ func TestGetExplicitMentions(t *testing.T) { }, }, }, + "AtUserWithColonAtEnd": { + Message: "this is a message for @user:", + Keywords: map[string][]string{"@user": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + }, + }, "AtUserWithPeriodAtEndOfSentence": { Message: "this is a message for @user.period.", Keywords: map[string][]string{"@user.period": {id1}}, @@ -248,6 +290,15 @@ func TestGetExplicitMentions(t *testing.T) { }, }, }, + "UserWithColonAtEnd": { + Message: "this is a message for user:", + Keywords: map[string][]string{"user": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + }, + }, "PotentialOutOfChannelUser": { Message: "this is an message for @potential and @user", Keywords: map[string][]string{"@user": {id1}}, @@ -452,6 +503,7 @@ func TestGetExplicitMentionsAtHere(t *testing.T) { "\\@here\\": true, "|@here|": true, ";@here;": true, + "@here:": true, ":@here:": false, // This case shouldn't trigger a mention since it follows the format of reactions e.g. :word: "'@here'": true, "\"@here\"": true, -- cgit v1.2.3-1-g7c22 From df6a7f8b19e2381ee57f946d5b184185653b2ee1 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 15 May 2018 13:33:47 -0700 Subject: MM-10249 Adding plugin ability to intercept posts before they reach the DB. (#8791) * Adding plugin ability to intercept posts before they reach the DB. * s/envoked/invoked/ --- app/plugin.go | 4 ++++ app/post.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'app') diff --git a/app/plugin.go b/app/plugin.go index 0aaa8d1d4..0d3415f4c 100644 --- a/app/plugin.go +++ b/app/plugin.go @@ -661,3 +661,7 @@ func (a *App) ExecutePluginCommand(args *model.CommandArgs) (*model.Command, *mo } return nil, nil, nil } + +func (a *App) PluginsReady() bool { + return a.PluginEnv != nil && *a.Config().PluginSettings.Enable +} diff --git a/app/post.go b/app/post.go index bc31aee44..2efa4c90e 100644 --- a/app/post.go +++ b/app/post.go @@ -160,6 +160,14 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo return nil, err } + if a.PluginsReady() { + if newPost, rejectionReason := a.PluginEnv.Hooks().MessageWillBePosted(post); newPost == nil { + return nil, model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) + } else { + post = newPost + } + } + var rpost *model.Post if result := <-a.Srv.Store.Post().Save(post); result.Err != nil { return nil, result.Err @@ -167,6 +175,12 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo rpost = result.Data.(*model.Post) } + if a.PluginsReady() { + a.Go(func() { + a.PluginEnv.Hooks().MessageHasBeenPosted(rpost) + }) + } + esInterface := a.Elasticsearch if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing { a.Go(func() { @@ -371,11 +385,25 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model return nil, err } + if a.PluginsReady() { + if pluginModifiedPost, rejectionReason := a.PluginEnv.Hooks().MessageWillBeUpdated(newPost, oldPost); pluginModifiedPost == nil { + return nil, model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) + } else { + newPost = pluginModifiedPost + } + } + if result := <-a.Srv.Store.Post().Update(newPost, oldPost); result.Err != nil { return nil, result.Err } else { rpost := result.Data.(*model.Post) + if a.PluginsReady() { + a.Go(func() { + a.PluginEnv.Hooks().MessageHasBeenUpdated(newPost, oldPost) + }) + } + esInterface := a.Elasticsearch if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing { a.Go(func() { -- cgit v1.2.3-1-g7c22 From 02f8c18f40cd0e973e4c75b751e8fcbbbd019728 Mon Sep 17 00:00:00 2001 From: Ugurcan Turkdogan Date: Tue, 15 May 2018 13:43:59 -0700 Subject: Update email notification subject line and contents for Group Messages (#8689) Reordered notification strings MM-10335 Changed uppercase CHANNEL to Lowercase Channel, added @ sign before username on notifications Added @ sign in front of username in all email notifications. Capitalized Direct Message and Group Message in email notifications. Fixed the issue with long group message names. Removed executable bit --- app/notification.go | 77 ++++++++++++++++++++++++++------ app/notification_test.go | 114 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 141 insertions(+), 50 deletions(-) (limited to 'app') diff --git a/app/notification.go b/app/notification.go index 4bdc6c94f..0fbc33060 100644 --- a/app/notification.go +++ b/app/notification.go @@ -217,7 +217,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod } if userAllowsEmails && status.Status != model.STATUS_ONLINE && profileMap[id].DeleteAt == 0 { - a.sendNotificationEmail(post, profileMap[id], channel, team, senderName, sender) + a.sendNotificationEmail(post, profileMap[id], channel, team, channelName, senderName, sender) } } } @@ -351,7 +351,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod return mentionedUsersList, nil } -func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel *model.Channel, team *model.Team, senderName string, sender *model.User) *model.AppError { +func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel *model.Channel, team *model.Team, channelName string, senderName string, sender *model.User) *model.AppError { if channel.IsGroupOrDirect() { if result := <-a.Srv.Store.Team().GetTeamsByUserId(user.Id); result.Err != nil { return result.Err @@ -396,22 +396,24 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel translateFunc := utils.GetUserTranslations(user.Locale) + emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL + if license := a.License(); license != nil && *license.Features.EmailNotificationContents { + emailNotificationContentsType = *a.Config().EmailSettings.EmailNotificationContentsType + } + var subjectText string if channel.Type == model.CHANNEL_DIRECT { subjectText = getDirectMessageNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, senderName) + } else if channel.Type == model.CHANNEL_GROUP { + subjectText = getGroupMessageNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, channelName, emailNotificationContentsType) } else if *a.Config().EmailSettings.UseChannelInEmailNotifications { subjectText = getNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName+" ("+channel.DisplayName+")") } else { subjectText = getNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName) } - emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL - if license := a.License(); license != nil && *license.Features.EmailNotificationContents { - emailNotificationContentsType = *a.Config().EmailSettings.EmailNotificationContentsType - } - teamURL := a.GetSiteURL() + "/" + team.Name - var bodyText = a.getNotificationEmailBody(user, post, channel, senderName, team.Name, teamURL, emailNotificationContentsType, translateFunc) + var bodyText = a.getNotificationEmailBody(user, post, channel, channelName, senderName, team.Name, teamURL, emailNotificationContentsType, translateFunc) a.Go(func() { if err := a.SendMail(user.Email, html.UnescapeString(subjectText), bodyText); err != nil { @@ -456,10 +458,37 @@ func getNotificationEmailSubject(post *model.Post, translateFunc i18n.TranslateF return translateFunc("app.notification.subject.notification.full", subjectParameters) } +/** + * Computes the subject line for group email messages + */ +func getGroupMessageNotificationEmailSubject(post *model.Post, translateFunc i18n.TranslateFunc, siteName string, channelName string, emailNotificationContentsType string) string { + t := getFormattedPostTime(post, translateFunc) + var subjectText string + if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL { + var subjectParameters = map[string]interface{}{ + "SiteName": siteName, + "ChannelName": channelName, + "Month": t.Month, + "Day": t.Day, + "Year": t.Year, + } + subjectText = translateFunc("app.notification.subject.group_message.full", subjectParameters) + } else { + var subjectParameters = map[string]interface{}{ + "SiteName": siteName, + "Month": t.Month, + "Day": t.Day, + "Year": t.Year, + } + subjectText = translateFunc("app.notification.subject.group_message.generic", subjectParameters) + } + return subjectText +} + /** * Computes the email body for notification messages */ -func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, channel *model.Channel, senderName string, teamName string, teamURL string, emailNotificationContentsType string, translateFunc i18n.TranslateFunc) string { +func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, channel *model.Channel, channelName string, 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 { @@ -476,10 +505,6 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, 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 @@ -509,6 +534,32 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, "Day": t.Day, }) } + } else if channel.Type == model.CHANNEL_GROUP { + if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL { + bodyText = translateFunc("app.notification.body.intro.group_message.full") + info = utils.TranslateAsHtml(translateFunc, "app.notification.body.text.group_message.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.group_message.generic", map[string]interface{}{ + "SenderName": senderName, + }) + info = utils.TranslateAsHtml(translateFunc, "app.notification.body.text.group_message.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") diff --git a/app/notification_test.go b/app/notification_test.go index 818ad1d9d..8fbcf3a78 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -1043,7 +1043,7 @@ func TestGetDirectMessageNotificationEmailSubject(t *testing.T) { th := Setup() defer th.TearDown() - expectedPrefix := "[http://localhost:8065] New Direct Message from sender on" + expectedPrefix := "[http://localhost:8065] New Direct Message from @sender on" post := &model.Post{ CreateAt: 1501804801000, } @@ -1054,6 +1054,38 @@ func TestGetDirectMessageNotificationEmailSubject(t *testing.T) { } } +func TestGetGroupMessageNotificationEmailSubjectFull(t *testing.T) { + th := Setup() + defer th.TearDown() + + expectedPrefix := "[http://localhost:8065] New Group Message in sender on" + post := &model.Post{ + CreateAt: 1501804801000, + } + translateFunc := utils.GetUserTranslations("en") + emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL + subject := getGroupMessageNotificationEmailSubject(post, translateFunc, "http://localhost:8065", "sender", emailNotificationContentsType) + if !strings.HasPrefix(subject, expectedPrefix) { + t.Fatal("Expected subject line prefix '" + expectedPrefix + "', got " + subject) + } +} + +func TestGetGroupMessageNotificationEmailSubjectGeneric(t *testing.T) { + th := Setup() + defer th.TearDown() + + expectedPrefix := "[http://localhost:8065] New Group Message on" + post := &model.Post{ + CreateAt: 1501804801000, + } + translateFunc := utils.GetUserTranslations("en") + emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC + subject := getGroupMessageNotificationEmailSubject(post, translateFunc, "http://localhost:8065", "sender", emailNotificationContentsType) + if !strings.HasPrefix(subject, expectedPrefix) { + t.Fatal("Expected subject line prefix '" + expectedPrefix + "', got " + subject) + } +} + func TestGetNotificationEmailSubject(t *testing.T) { th := Setup() defer th.TearDown() @@ -1081,21 +1113,22 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) { DisplayName: "ChannelName", Type: model.CHANNEL_OPEN, } + channelName := "ChannelName" senderName := "sender" teamName := "team" teamURL := "http://localhost:8065/" + teamName emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL translateFunc := utils.GetUserTranslations("en") - body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc) + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, 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, "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, "@"+senderName+" - ") { + t.Fatal("Expected email text '@" + senderName + " - '. Got " + body) } if !strings.Contains(body, post.Message) { t.Fatal("Expected email text '" + post.Message + "'. Got " + body) @@ -1117,21 +1150,22 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) { DisplayName: "ChannelName", Type: model.CHANNEL_GROUP, } + channelName := "ChannelName" senderName := "sender" teamName := "team" teamURL := "http://localhost:8065/" + teamName emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL translateFunc := utils.GetUserTranslations("en") - body := th.App.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) + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc) + if !strings.Contains(body, "You have a new Group Message.") { + t.Fatal("Expected email text 'You have a new Group Message. Got " + body) } - if !strings.Contains(body, "CHANNEL: Group Message") { - t.Fatal("Expected email text 'CHANNEL: Group Message'. Got " + body) + if !strings.Contains(body, "Channel: ChannelName") { + t.Fatal("Expected email text 'Channel: ChannelName'. Got " + body) } - if !strings.Contains(body, senderName+" - ") { - t.Fatal("Expected email text '" + senderName + " - '. 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) @@ -1153,21 +1187,22 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) { DisplayName: "ChannelName", Type: model.CHANNEL_PRIVATE, } + channelName := "ChannelName" senderName := "sender" teamName := "team" teamURL := "http://localhost:8065/" + teamName emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL translateFunc := utils.GetUserTranslations("en") - body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc) + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, 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, "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, "@"+senderName+" - ") { + t.Fatal("Expected email text '@" + senderName + " - '. Got " + body) } if !strings.Contains(body, post.Message) { t.Fatal("Expected email text '" + post.Message + "'. Got " + body) @@ -1189,18 +1224,19 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) { DisplayName: "ChannelName", Type: model.CHANNEL_DIRECT, } + channelName := "ChannelName" senderName := "sender" teamName := "team" teamURL := "http://localhost:8065/" + teamName emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL translateFunc := utils.GetUserTranslations("en") - body := th.App.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) + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, 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, "@"+senderName+" - ") { + t.Fatal("Expected email text '@" + senderName + " - '. Got " + body) } if !strings.Contains(body, post.Message) { t.Fatal("Expected email text '" + post.Message + "'. Got " + body) @@ -1223,18 +1259,19 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T) DisplayName: "ChannelName", Type: model.CHANNEL_OPEN, } + channelName := "ChannelName" senderName := "sender" teamName := "team" teamURL := "http://localhost:8065/" + teamName emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC translateFunc := utils.GetUserTranslations("en") - body := th.App.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) + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, 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, "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) @@ -1256,15 +1293,16 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) { DisplayName: "ChannelName", Type: model.CHANNEL_GROUP, } + channelName := "ChannelName" senderName := "sender" teamName := "team" teamURL := "http://localhost:8065/" + teamName emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC translateFunc := utils.GetUserTranslations("en") - body := th.App.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) + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc) + if !strings.Contains(body, "You have a new Group Message from @"+senderName) { + t.Fatal("Expected email text 'You have a new Group Message from @" + senderName + "'. Got " + body) } if strings.Contains(body, "CHANNEL: "+channel.DisplayName) { t.Fatal("Did not expect email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body) @@ -1289,15 +1327,16 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T) DisplayName: "ChannelName", Type: model.CHANNEL_PRIVATE, } + channelName := "ChannelName" senderName := "sender" teamName := "team" teamURL := "http://localhost:8065/" + teamName emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC translateFunc := utils.GetUserTranslations("en") - body := th.App.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) + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, 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) @@ -1322,15 +1361,16 @@ func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) DisplayName: "ChannelName", Type: model.CHANNEL_DIRECT, } + channelName := "ChannelName" senderName := "sender" teamName := "team" teamURL := "http://localhost:8065/" + teamName emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC translateFunc := utils.GetUserTranslations("en") - body := th.App.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) + body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, 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) -- cgit v1.2.3-1-g7c22