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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3e4c44c478
Коммит
15b5b1c191
@@ -2434,6 +2434,40 @@ func TestGetTopChannelsForTeamSince(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// add an oauth app post to ensure it's not counted
|
||||
_, err = th.Server.Store.Post().Save(&model.Post{
|
||||
Message: "hello from an ouath app",
|
||||
ChannelId: channel3.Id,
|
||||
UserId: th.BasicUser.Id,
|
||||
Props: model.StringInterface{
|
||||
"from_oauth_app": true,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// add a plugin post to ensure it's not counted
|
||||
_, err = th.Server.Store.Post().Save(&model.Post{
|
||||
Message: "hello from a plugin",
|
||||
ChannelId: channel3.Id,
|
||||
UserId: th.BasicUser.Id,
|
||||
Props: model.StringInterface{
|
||||
"from_plugin": true,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// add a system post to ensure it's not counted
|
||||
_, err = th.Server.Store.Post().Save(&model.Post{
|
||||
Message: "system message",
|
||||
Type: "system_join_channel",
|
||||
ChannelId: channel3.Id,
|
||||
UserId: th.BasicUser.Id,
|
||||
Props: model.StringInterface{
|
||||
"from_oauth_app": true,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
channel4 := th.CreatePrivateChannel(th.Context, th.BasicTeam)
|
||||
channel5 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
channel6 := th.CreatePrivateChannel(th.Context, th.BasicTeam)
|
||||
|
||||
@@ -630,6 +630,8 @@ func (api *PluginAPI) GetGroupsForUser(userID string) ([]*model.Group, *model.Ap
|
||||
}
|
||||
|
||||
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||
post.AddProp("from_plugin", "true")
|
||||
|
||||
post, appErr := api.app.CreatePostMissingChannel(api.ctx, post, true)
|
||||
if post != nil {
|
||||
post = post.ForPlugin()
|
||||
|
||||
@@ -1383,6 +1383,25 @@ func TestPluginCreatePostWithUploadedFile(t *testing.T) {
|
||||
assert.Equal(t, model.StringArray{fileInfo.Id}, actualPost.FileIds)
|
||||
}
|
||||
|
||||
func TestPluginCreatePostAddsFromPluginProp(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
channelID := th.BasicChannel.Id
|
||||
userID := th.BasicUser.Id
|
||||
post, err := api.CreatePost(&model.Post{
|
||||
Message: "test",
|
||||
ChannelId: channelID,
|
||||
UserId: userID,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
actualPost, err := api.GetPost(post.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "true", actualPost.GetProp("from_plugin"))
|
||||
}
|
||||
|
||||
func TestPluginAPIGetConfig(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -203,6 +203,10 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
|
||||
post.AddProp("from_bot", "true")
|
||||
}
|
||||
|
||||
if c.Session().IsOAuth {
|
||||
post.AddProp("from_oauth_app", "true")
|
||||
}
|
||||
|
||||
var ephemeralPost *model.Post
|
||||
if post.Type == "" && !a.HasPermissionToChannel(c, user.Id, channel.Id, model.PermissionUseChannelMentions) {
|
||||
mention := post.DisableMentionHighlights()
|
||||
|
||||
Ссылка в новой задаче
Block a user