Avoid counting top channel posts for posts made by plugins and OAuth apps (#20943)

* add from_integration prop to oauth posts to:
- oauth app posts
- plugin posts
- slash command responses
- incoming webhook posts

* tests

* include check for bot posts

* use from_plugin and from_oauth_app props

* fix test

* avoid counting top channel posts for posts made by plugins and oauth apps
Этот коммит содержится в:
Michael Kochell
2022-09-30 04:12:15 -04:00
коммит произвёл GitHub
родитель 3e4c44c478
Коммит 15b5b1c191
6 изменённых файлов: 112 добавлений и 6 удалений

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

@@ -212,6 +212,53 @@ func TestCreatePost(t *testing.T) {
require.Equal(t, post.CreateAt, rpost.CreateAt, "create at should match")
}
func TestCreatePostWithOAuthClient(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
originalOAuthSetting := *th.App.Config().ServiceSettings.EnableOAuthServiceProvider
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.EnableOAuthServiceProvider = true
})
defer th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.EnableOAuthServiceProvider = originalOAuthSetting
})
oAuthApp, appErr := th.App.CreateOAuthApp(&model.OAuthApp{
CreatorId: th.SystemAdminUser.Id,
Name: "name",
CallbackUrls: []string{"http://test.com"},
Homepage: "http://test.com",
})
require.Nil(t, appErr, "should create an OAuthApp")
session, appErr := th.App.CreateSession(&model.Session{
UserId: th.BasicUser.Id,
Token: "token",
IsOAuth: true,
Props: model.StringMap{model.SessionPropOAuthAppID: oAuthApp.Id},
})
require.Nil(t, appErr, "should create a session")
post, _, err := th.Client.CreatePost(&model.Post{
ChannelId: th.BasicPost.ChannelId,
Message: "test message",
})
require.NoError(t, err)
assert.NotContains(t, post.GetProps(), "from_oauth_app", "contains from_oauth_app prop when not using OAuth client")
client := th.CreateClient()
client.SetOAuthToken(session.Token)
post, _, err = client.CreatePost(&model.Post{
ChannelId: th.BasicPost.ChannelId,
Message: "test message",
})
require.NoError(t, err)
assert.Contains(t, post.GetProps(), "from_oauth_app", "missing from_oauth_app prop when using OAuth client")
}
func TestCreatePostEphemeral(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()