[MM-21919] Add use_channel_mentions permission (#13781)

* MM-21919 Add channel_mention permission

* MM-21919 Fix emojis migration test

* Enforce Channel Mentions on the in the posts api

* MM-21919 Rename permission to use_channel_mentions

Allow posts with channel mentions to still be posted without the permission just don't send notifications to users

* MM-21919 Add tests for a post with @all and @here

* MM-21919 Add use channel mentions to all roles that have create post

* MM-21919 Update app_test to include use_channel_mentions permission in default permissions
Этот коммит содержится в:
Farhan Munshi
2020-02-12 10:45:34 -05:00
коммит произвёл GitHub
родитель a7854f1b97
Коммит 897715f883
7 изменённых файлов: 85 добавлений и 25 удалений

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

@@ -876,47 +876,37 @@ func TestGetExplicitMentionsAtHere(t *testing.T) {
}
func TestAllowChannelMentions(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
post := &model.Post{ChannelId: th.BasicChannel.Id, UserId: th.BasicUser.Id}
t.Run("should return true for a regular post with few channel members", func(t *testing.T) {
th := Setup(t)
defer th.TearDown()
post := &model.Post{}
allowChannelMentions := th.App.allowChannelMentions(post, 5)
assert.True(t, allowChannelMentions)
})
t.Run("should return false for a channel header post", func(t *testing.T) {
th := Setup(t)
defer th.TearDown()
post := &model.Post{Type: model.POST_HEADER_CHANGE}
allowChannelMentions := th.App.allowChannelMentions(post, 5)
headerChangePost := &model.Post{ChannelId: th.BasicChannel.Id, UserId: th.BasicUser.Id, Type: model.POST_HEADER_CHANGE}
allowChannelMentions := th.App.allowChannelMentions(headerChangePost, 5)
assert.False(t, allowChannelMentions)
})
t.Run("should return false for a channel purpose post", func(t *testing.T) {
th := Setup(t)
defer th.TearDown()
post := &model.Post{Type: model.POST_PURPOSE_CHANGE}
allowChannelMentions := th.App.allowChannelMentions(post, 5)
purposeChangePost := &model.Post{ChannelId: th.BasicChannel.Id, UserId: th.BasicUser.Id, Type: model.POST_PURPOSE_CHANGE}
allowChannelMentions := th.App.allowChannelMentions(purposeChangePost, 5)
assert.False(t, allowChannelMentions)
})
t.Run("should return false for a regular post with many channel members", func(t *testing.T) {
th := Setup(t)
defer th.TearDown()
post := &model.Post{}
allowChannelMentions := th.App.allowChannelMentions(post, int(*th.App.Config().TeamSettings.MaxNotificationsPerChannel)+1)
assert.False(t, allowChannelMentions)
})
t.Run("should return false for a post where the post user does not have USE_CHANNEL_MENTIONS permission", func(t *testing.T) {
defer th.AddPermissionToRole(model.PERMISSION_USE_CHANNEL_MENTIONS.Id, model.CHANNEL_USER_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_USE_CHANNEL_MENTIONS.Id, model.CHANNEL_USER_ROLE_ID)
allowChannelMentions := th.App.allowChannelMentions(post, 5)
assert.False(t, allowChannelMentions)
})
}