Revert "Removed the opengraph type dependency for plugins by stripping post Metadata (#20612)" (#20684)

This reverts commit da7a8a4552.
Этот коммит содержится в:
Agniva De Sarker
2022-07-20 20:09:03 +05:30
коммит произвёл GitHub
родитель 6376f7ff55
Коммит 32dee6d449
6 изменённых файлов: 40 добавлений и 76 удалений

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

@@ -259,7 +259,7 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
var rejectionError *model.AppError
pluginContext := pluginContext(c)
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
replacementPost, rejectionReason := hooks.MessageWillBePosted(pluginContext, post.ForPlugin())
replacementPost, rejectionReason := hooks.MessageWillBePosted(pluginContext, post)
if rejectionReason != "" {
id := "Post rejected by plugin. " + rejectionReason
if rejectionReason == plugin.DismissPostError {
@@ -269,7 +269,6 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
return false
}
if replacementPost != nil {
// the original post's metadata (if there ever was any) is lost, and will be rebuilt.
post = replacementPost
}
@@ -310,13 +309,21 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
// might be duplicating requests.
a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, rpost.Id, PendingPostIDsCacheTTL)
// We make a copy of the post for the plugin hook to avoid a race condition,
// and to remove the non-GOB-encodable Metadata from it.
// We make a copy of the post for the plugin hook to avoid a race condition.
rPostCopy := rpost.Clone()
// FIXME: Removes PreviewPost from the post payload sent to the MessageHasBeenPosted hook so that plugins compiled with older versions of
// Mattermost—without the gob registration of the PreviewPost struct—won't crash.
if rPostCopy.Metadata != nil {
rPostCopy.Metadata = rPostCopy.Metadata.Copy()
}
rPostCopy.RemovePreviewPost()
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
a.Srv().Go(func() {
pluginContext := pluginContext(c)
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
hooks.MessageHasBeenPosted(pluginContext, rpost.ForPlugin())
hooks.MessageHasBeenPosted(pluginContext, rPostCopy)
return true
}, plugin.MessageHasBeenPostedID)
})
@@ -643,15 +650,12 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
var rejectionReason string
pluginContext := pluginContext(c)
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
newPost, rejectionReason = hooks.MessageWillBeUpdated(pluginContext, newPost.ForPlugin(), oldPost.ForPlugin())
newPost, rejectionReason = hooks.MessageWillBeUpdated(pluginContext, newPost, oldPost)
return post != nil
}, plugin.MessageWillBeUpdatedID)
if newPost == nil {
return nil, model.NewAppError("UpdatePost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest)
}
// Restore the post metadata that was stripped by the plugin. Set it to
// the last known good.
newPost.Metadata = oldPost.Metadata
}
rpost, nErr := a.Srv().Store.Post().Update(newPost, oldPost)
@@ -669,7 +673,7 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
a.Srv().Go(func() {
pluginContext := pluginContext(c)
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
hooks.MessageHasBeenUpdated(pluginContext, newPost.ForPlugin(), oldPost.ForPlugin())
hooks.MessageHasBeenUpdated(pluginContext, newPost, oldPost)
return true
}, plugin.MessageHasBeenUpdatedID)
})