Temporary fix for slack attachment fields being clobbered by plugins (#9935)

This commit is contained in:
Joram Wilander
2018-12-04 05:08:10 -05:00
committed by Carlos Tadeu Panato Junior
parent 2611606e13
commit 2d8cb45ff3

View File

@@ -7,6 +7,7 @@ import (
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"encoding/json"
"fmt"
"net/http"
"strings"
@@ -139,6 +140,19 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
return nil, err
}
// Temporary fix so old plugins don't clobber new fields in SlackAttachment struct, see MM-13088
if attachments, ok := post.Props["attachments"].([]*model.SlackAttachment); ok {
jsonAttachments, err := json.Marshal(attachments)
if err == nil {
attachmentsInterface := []interface{}{}
err = json.Unmarshal(jsonAttachments, &attachmentsInterface)
post.Props["attachments"] = attachmentsInterface
}
if err != nil {
mlog.Error("Could not convert post attachments to map interface, err=%s" + err.Error())
}
}
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
var rejectionError *model.AppError
pluginContext := &plugin.Context{}