[MM-24177] Adds props to post for front end to know if highlight or not (#14348)

* Add props to post

* Address PR comments

* address PR comments

* Fix styling problems

* Address PR comments

* address PR comments

* Add PR suggestion

* fix usage

* fix error

* remove err

* fix golang lint
Этот коммит содержится в:
Hossein Ahmadian-Yazdi
2020-05-05 06:00:59 -04:00
коммит произвёл GitHub
родитель 3dbb0201a4
Коммит 40b20c3eaf
3 изменённых файлов: 97 добавлений и 0 удалений

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

@@ -396,6 +396,11 @@ func (a *App) FillInPostProps(post *model.Post, channel *model.Channel) *model.A
post.DelProp("channel_mentions")
}
matched := model.AT_MENTION_PATTEN.MatchString(post.Message)
if a.License() != nil && *a.License().Features.LDAPGroups && matched && !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PERMISSION_USE_GROUP_MENTIONS) {
post.AddProp(model.POST_PROPS_GROUP_HIGHLIGHT_DISABLED, true)
}
return nil
}

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

@@ -1755,3 +1755,92 @@ func TestCountMentionsFromPost(t *testing.T) {
assert.Equal(t, numPosts, count)
})
}
func TestFillInPostProps(t *testing.T) {
t.Run("should not add disable group highlight to post props for user with group mention permissions", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.SetLicense(model.NewTestLicense("ldap"))
user1 := th.BasicUser
channel := th.CreateChannel(th.BasicTeam)
post1, err := th.App.CreatePost(&model.Post{
UserId: user1.Id,
ChannelId: channel.Id,
Message: "test123123 @group1 @group2 blah blah blah",
}, channel, false)
require.Nil(t, err)
err = th.App.FillInPostProps(post1, channel)
assert.Nil(t, err)
assert.Equal(t, post1.Props, model.StringInterface{})
})
t.Run("should not add disable group highlight to post props for app without license", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
id := model.NewId()
guest := &model.User{
Email: "success+" + id + "@simulator.amazonses.com",
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
EmailVerified: true,
}
guest, err := th.App.CreateGuest(guest)
require.Nil(t, err)
th.LinkUserToTeam(guest, th.BasicTeam)
channel := th.CreateChannel(th.BasicTeam)
th.AddUserToChannel(guest, channel)
post1, err := th.App.CreatePost(&model.Post{
UserId: guest.Id,
ChannelId: channel.Id,
Message: "test123123 @group1 @group2 blah blah blah",
}, channel, false)
require.Nil(t, err)
err = th.App.FillInPostProps(post1, channel)
assert.Nil(t, err)
assert.Equal(t, post1.Props, model.StringInterface{})
})
t.Run("should add disable group highlight to post props for guest user", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.SetLicense(model.NewTestLicense("ldap"))
id := model.NewId()
guest := &model.User{
Email: "success+" + id + "@simulator.amazonses.com",
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
EmailVerified: true,
}
guest, err := th.App.CreateGuest(guest)
require.Nil(t, err)
th.LinkUserToTeam(guest, th.BasicTeam)
channel := th.CreateChannel(th.BasicTeam)
th.AddUserToChannel(guest, channel)
post1, err := th.App.CreatePost(&model.Post{
UserId: guest.Id,
ChannelId: channel.Id,
Message: "test123123 @group1 @group2 blah blah blah",
}, channel, false)
require.Nil(t, err)
err = th.App.FillInPostProps(post1, channel)
assert.Nil(t, err)
assert.Equal(t, post1.Props, model.StringInterface{"disable_group_highlight": true})
})
}

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

@@ -63,8 +63,11 @@ const (
POST_PROPS_OVERRIDE_ICON_EMOJI = "override_icon_emoji"
POST_PROPS_MENTION_HIGHLIGHT_DISABLED = "mentionHighlightDisabled"
POST_PROPS_GROUP_HIGHLIGHT_DISABLED = "disable_group_highlight"
)
var AT_MENTION_PATTEN = regexp.MustCompile(`\B@`)
type Post struct {
Id string `json:"id"`
CreateAt int64 `json:"create_at"`