[MM-51090] - Notify Admin post fails plugin hook (#22508)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9252fff4d6
Коммит
a14958096d
@@ -6,6 +6,7 @@ package model
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
@@ -777,6 +778,9 @@ func (o *Post) ToNilIfInvalid() *Post {
|
||||
func (o *Post) ForPlugin() *Post {
|
||||
p := o.Clone()
|
||||
p.Metadata = nil
|
||||
if p.Type == fmt.Sprintf("%sup_notification", PostCustomTypePrefix) {
|
||||
p.DelProp("requested_features")
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -906,3 +907,34 @@ func TestPostAttachments(t *testing.T) {
|
||||
assert.Equal(t, attachments[0].Fields[1].Value, ":emoji2:")
|
||||
})
|
||||
}
|
||||
|
||||
func TestPostForPlugin(t *testing.T) {
|
||||
t.Run("post type custom_up_notification for plugin should have no requested features prop", func(t *testing.T) {
|
||||
p := &Post{
|
||||
Type: fmt.Sprintf("%sup_notification", PostCustomTypePrefix),
|
||||
}
|
||||
props := make(StringInterface)
|
||||
props["requested_features"] = "test_requested_features_map"
|
||||
p.SetProps(props)
|
||||
|
||||
require.NotNil(t, p.GetProp("requested_features"))
|
||||
|
||||
pluginPost := p.ForPlugin()
|
||||
require.Nil(t, pluginPost.GetProp("requested_features"))
|
||||
})
|
||||
|
||||
t.Run("non post type custom_up_notification for plugin should have requested features prop", func(t *testing.T) {
|
||||
p := &Post{
|
||||
Type: PostTypeWelcomePost,
|
||||
}
|
||||
props := make(StringInterface)
|
||||
props["requested_features"] = "test_requested_features_map"
|
||||
p.SetProps(props)
|
||||
|
||||
require.NotNil(t, p.GetProp("requested_features"))
|
||||
|
||||
pluginPost := p.ForPlugin()
|
||||
require.NotNil(t, pluginPost.GetProp("requested_features"))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user