[MM-22622] Add Ephemeral response when using mentions without permissions (#13902)

* MM-22282 Add Ephemeral response when using mentions without permission and add new prop to disable mention highlights on client

* MM-22622 Make test name test actually what it does and fix comment style

* MM-22622 Check ephemeral post created when post create with mentions on API

* MM-22622 More tests for App>CreatePost

* MM-22622 Make DisableMentionHighlights more concise and rename ephemeral post

* MM-22622 Dont send ephemeral message for system message created by user

* Trigger build
Этот коммит содержится в:
Farhan Munshi
2020-03-03 05:22:49 -05:00
коммит произвёл GitHub
родитель 4c7fee7ac8
Коммит aec606500f
7 изменённых файлов: 366 добавлений и 1 удалений

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

@@ -189,6 +189,22 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
return nil, model.NewAppError("createPost", "api.post.create_post.town_square_read_only", nil, "", http.StatusForbidden)
}
var ephemeralPost *model.Post
if post.Type == "" && !a.HasPermissionToChannel(user.Id, channel.Id, model.PERMISSION_USE_CHANNEL_MENTIONS) {
mention := post.DisableMentionHighlights()
if mention != "" {
T := utils.GetUserTranslations(user.Locale)
ephemeralPost = &model.Post{
UserId: user.Id,
RootId: post.RootId,
ParentId: post.ParentId,
ChannelId: channel.Id,
Message: T("model.post.channel_notifications_disabled_in_channel.message", model.StringInterface{"ChannelName": channel.Name, "Mention": mention}),
Props: model.StringInterface{model.POST_PROPS_MENTION_HIGHLIGHT_DISABLED: true},
}
}
}
// Verify the parent/child relationships are correct
var parentPostList *model.PostList
if pchan != nil {
@@ -311,6 +327,11 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
mlog.Error("Failed to handle post events", mlog.Err(err))
}
// Send any ephemeral posts after the post is created to ensure it shows up after the latest post created
if ephemeralPost != nil {
a.SendEphemeralPost(post.UserId, ephemeralPost)
}
return rpost, nil
}
@@ -604,6 +625,10 @@ func (a *App) PatchPost(postId string, patch *model.PostPatch) (*model.Post, *mo
return nil, err
}
if !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PERMISSION_USE_CHANNEL_MENTIONS) {
patch.DisableMentionHighlights()
}
post.Patch(patch)
updatedPost, err := a.UpdatePost(post, false)