MPA: move product hooks out of plugins environment (#21772)
* product: add new hooks manager for porducts * move product hooks out of plugins environment * add hooks for plugin
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9e79ca7160
Коммит
43e26ccda2
@@ -346,7 +346,7 @@ func (a *App) CreateChannel(c request.CTX, channel *model.Channel, addMember boo
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.ChannelHasBeenCreated(pluginContext, sc)
|
||||
return true
|
||||
}, plugin.ChannelHasBeenCreatedID)
|
||||
@@ -432,7 +432,7 @@ func (a *App) handleCreationEvent(c request.CTX, userID, otherUserID string, cha
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.ChannelHasBeenCreated(pluginContext, channel)
|
||||
return true
|
||||
}, plugin.ChannelHasBeenCreatedID)
|
||||
@@ -1602,7 +1602,7 @@ func (a *App) AddChannelMember(c request.CTX, userID string, channel *model.Chan
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasJoinedChannel(pluginContext, cm, userRequestor)
|
||||
return true
|
||||
}, plugin.UserHasJoinedChannelID)
|
||||
@@ -2180,7 +2180,7 @@ func (a *App) JoinChannel(c request.CTX, channel *model.Channel, userID string)
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasJoinedChannel(pluginContext, cm, nil)
|
||||
return true
|
||||
}, plugin.UserHasJoinedChannelID)
|
||||
@@ -2492,7 +2492,7 @@ func (a *App) removeUserFromChannel(c request.CTX, userIDToRemove string, remove
|
||||
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasLeftChannel(pluginContext, cm, actorUser)
|
||||
return true
|
||||
}, plugin.UserHasLeftChannelID)
|
||||
|
||||
@@ -322,5 +322,33 @@ func (s *hooksService) RegisterHooks(productID string, hooks any) error {
|
||||
return errors.New("could not find plugins environment")
|
||||
}
|
||||
|
||||
return s.ch.pluginsEnvironment.AddProduct(productID, hooks)
|
||||
return s.ch.srv.hooksManager.AddProduct(productID, hooks)
|
||||
}
|
||||
|
||||
func (ch *Channels) RunMultiHook(hookRunnerFunc func(hooks plugin.Hooks) bool, hookId int) {
|
||||
if env := ch.pluginsEnvironment; env != nil {
|
||||
env.RunMultiPluginHook(hookRunnerFunc, hookId)
|
||||
}
|
||||
|
||||
// run hook for the products
|
||||
ch.srv.hooksManager.RunMultiHook(hookRunnerFunc, hookId)
|
||||
}
|
||||
|
||||
func (ch *Channels) HooksForPluginOrProduct(id string) (plugin.Hooks, error) {
|
||||
var hooks plugin.Hooks
|
||||
if env := ch.pluginsEnvironment; env != nil {
|
||||
// we intentionally ignore the error here, because the id can be a product id
|
||||
// we are going to check if we have the hooks or not
|
||||
hooks, _ = env.HooksForPlugin(id)
|
||||
if hooks != nil {
|
||||
return hooks, nil
|
||||
}
|
||||
}
|
||||
|
||||
hooks = ch.srv.hooksManager.HooksForProduct(id)
|
||||
if hooks != nil {
|
||||
return hooks, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("could not find hooks for id %s", id)
|
||||
}
|
||||
|
||||
@@ -28,10 +28,6 @@ func (s *Server) clusterRemovePluginHandler(msg *model.ClusterMessage) {
|
||||
}
|
||||
|
||||
func (s *Server) clusterPluginEventHandler(msg *model.ClusterMessage) {
|
||||
env := s.Channels().GetPluginsEnvironment()
|
||||
if env == nil {
|
||||
return
|
||||
}
|
||||
if msg.Props == nil {
|
||||
mlog.Warn("ClusterMessage.Props for plugin event should not be nil")
|
||||
return
|
||||
@@ -48,7 +44,12 @@ func (s *Server) clusterPluginEventHandler(msg *model.ClusterMessage) {
|
||||
return
|
||||
}
|
||||
|
||||
hooks, err := env.HooksForPlugin(pluginID)
|
||||
channels, ok := s.products["channels"].(*Channels)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
hooks, err := channels.HooksForPluginOrProduct(pluginID)
|
||||
if err != nil {
|
||||
mlog.Warn("Getting hooks for plugin failed", mlog.String("plugin_id", pluginID), mlog.Err(err))
|
||||
return
|
||||
|
||||
@@ -898,7 +898,7 @@ func (a *App) DoUploadFileExpectModification(c request.CTX, now time.Time, rawTe
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
var rejectionError *model.AppError
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
var newBytes bytes.Buffer
|
||||
replacementInfo, rejectionReason := hooks.FileWillBeUploaded(pluginContext, info, bytes.NewReader(data), &newBytes)
|
||||
if rejectionReason != "" {
|
||||
|
||||
@@ -160,7 +160,7 @@ func (a *App) DoLogin(c *request.Context, w http.ResponseWriter, r *http.Request
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
var rejectionReason string
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
rejectionReason = hooks.UserWillLogIn(pluginContext, user)
|
||||
return rejectionReason == ""
|
||||
}, plugin.UserWillLogInID)
|
||||
@@ -229,7 +229,7 @@ func (a *App) DoLogin(c *request.Context, w http.ResponseWriter, r *http.Request
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasLoggedIn(pluginContext, user)
|
||||
return true
|
||||
}, plugin.UserHasLoggedInID)
|
||||
|
||||
@@ -53,7 +53,7 @@ func (a *App) CompleteOnboarding(c *request.Context, request *model.CompleteOnbo
|
||||
return
|
||||
}
|
||||
|
||||
hooks, err := pluginsEnvironment.HooksForPlugin(id)
|
||||
hooks, err := a.ch.HooksForPluginOrProduct(id)
|
||||
if err != nil {
|
||||
mlog.Warn("Getting hooks for plugin failed", mlog.String("plugin_id", id), mlog.Err(err))
|
||||
return
|
||||
|
||||
@@ -95,7 +95,12 @@ type PlatformService struct {
|
||||
additionalClusterHandlers map[model.ClusterEvent]einterfaces.ClusterMessageHandler
|
||||
sharedChannelService SharedChannelServiceIFace
|
||||
|
||||
pluginEnv *plugin.Environment
|
||||
pluginEnv HookRunner
|
||||
}
|
||||
|
||||
type HookRunner interface {
|
||||
RunMultiHook(hookRunnerFunc func(hooks plugin.Hooks) bool, hookId int)
|
||||
GetPluginsEnvironment() *plugin.Environment
|
||||
}
|
||||
|
||||
// New creates a new PlatformService.
|
||||
@@ -426,17 +431,17 @@ func (ps *PlatformService) SetSharedChannelService(s SharedChannelServiceIFace)
|
||||
ps.sharedChannelService = s
|
||||
}
|
||||
|
||||
func (ps *PlatformService) SetPluginsEnvironment(env *plugin.Environment) {
|
||||
ps.pluginEnv = env
|
||||
func (ps *PlatformService) SetPluginsEnvironment(runner HookRunner) {
|
||||
ps.pluginEnv = runner
|
||||
}
|
||||
|
||||
// GetPluginStatuses meant to be used by cluster implementation
|
||||
func (ps *PlatformService) GetPluginStatuses() (model.PluginStatuses, *model.AppError) {
|
||||
if ps.pluginEnv == nil {
|
||||
if ps.pluginEnv == nil || ps.pluginEnv.GetPluginsEnvironment() == nil {
|
||||
return nil, model.NewAppError("GetPluginStatuses", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
pluginStatuses, err := ps.pluginEnv.Statuses()
|
||||
pluginStatuses, err := ps.pluginEnv.GetPluginsEnvironment().Statuses()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetPluginStatuses", "app.plugin.get_statuses.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
@@ -72,15 +72,15 @@ type WebConnConfig struct {
|
||||
// It contains all the necessary state to manage sending/receiving data to/from
|
||||
// a websocket.
|
||||
type WebConn struct {
|
||||
sessionExpiresAt int64 // This should stay at the top for 64-bit alignment of 64-bit words accessed atomically
|
||||
Platform *PlatformService
|
||||
Suite SuiteIFace
|
||||
PluginsEnvironment func() *plugin.Environment
|
||||
WebSocket *websocket.Conn
|
||||
T i18n.TranslateFunc
|
||||
Locale string
|
||||
Sequence int64
|
||||
UserId string
|
||||
sessionExpiresAt int64 // This should stay at the top for 64-bit alignment of 64-bit words accessed atomically
|
||||
Platform *PlatformService
|
||||
Suite SuiteIFace
|
||||
HookRunner HookRunner
|
||||
WebSocket *websocket.Conn
|
||||
T i18n.TranslateFunc
|
||||
Locale string
|
||||
Sequence int64
|
||||
UserId string
|
||||
|
||||
allChannelMembers map[string]string
|
||||
lastAllChannelMembersTime int64
|
||||
@@ -162,7 +162,7 @@ func (ps *PlatformService) PopulateWebConnConfig(s *model.Session, cfg *WebConnC
|
||||
}
|
||||
|
||||
// NewWebConn returns a new WebConn instance.
|
||||
func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, envFn func() *plugin.Environment) *WebConn {
|
||||
func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, runner HookRunner) *WebConn {
|
||||
if cfg.Session.UserId != "" {
|
||||
ps.Go(func() {
|
||||
suite.SetStatusOnline(cfg.Session.UserId, false)
|
||||
@@ -200,7 +200,7 @@ func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, envF
|
||||
wc := &WebConn{
|
||||
Platform: ps,
|
||||
Suite: suite,
|
||||
PluginsEnvironment: envFn,
|
||||
HookRunner: runner,
|
||||
send: cfg.activeQueue,
|
||||
deadQueue: cfg.deadQueue,
|
||||
deadQueuePointer: cfg.deadQueuePointer,
|
||||
@@ -222,14 +222,12 @@ func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, envF
|
||||
wc.SetSessionExpiresAt(cfg.Session.ExpiresAt)
|
||||
wc.SetConnectionID(cfg.ConnectionID)
|
||||
|
||||
if pluginsEnvironment := wc.PluginsEnvironment(); pluginsEnvironment != nil {
|
||||
wc.Platform.Go(func() {
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnWebSocketConnect(wc.GetConnectionID(), wc.UserId)
|
||||
return true
|
||||
}, plugin.OnWebSocketConnectID)
|
||||
})
|
||||
}
|
||||
wc.Platform.Go(func() {
|
||||
wc.HookRunner.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnWebSocketConnect(wc.GetConnectionID(), wc.UserId)
|
||||
return true
|
||||
}, plugin.OnWebSocketConnectID)
|
||||
})
|
||||
|
||||
return wc
|
||||
}
|
||||
@@ -238,12 +236,10 @@ func (wc *WebConn) pluginPostedConsumer(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
for msg := range wc.pluginPosted {
|
||||
if pluginsEnvironment := wc.PluginsEnvironment(); pluginsEnvironment != nil {
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.WebSocketMessageHasBeenPosted(msg.connectionID, msg.userID, msg.req)
|
||||
return true
|
||||
}, plugin.WebSocketMessageHasBeenPostedID)
|
||||
}
|
||||
wc.HookRunner.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.WebSocketMessageHasBeenPosted(msg.connectionID, msg.userID, msg.req)
|
||||
return true
|
||||
}, plugin.WebSocketMessageHasBeenPostedID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,14 +324,12 @@ func (wc *WebConn) Pump() {
|
||||
wc.Platform.HubUnregister(wc)
|
||||
close(wc.pumpFinished)
|
||||
|
||||
if pluginsEnvironment := wc.PluginsEnvironment(); pluginsEnvironment != nil {
|
||||
wc.Platform.Go(func() {
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnWebSocketDisconnect(wc.GetConnectionID(), wc.UserId)
|
||||
return true
|
||||
}, plugin.OnWebSocketDisconnectID)
|
||||
})
|
||||
}
|
||||
wc.Platform.Go(func() {
|
||||
wc.HookRunner.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnWebSocketDisconnect(wc.GetConnectionID(), wc.UserId)
|
||||
return true
|
||||
}, plugin.OnWebSocketDisconnectID)
|
||||
})
|
||||
}
|
||||
|
||||
func (wc *WebConn) readPump() {
|
||||
|
||||
@@ -5,6 +5,7 @@ package platform
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -18,13 +19,27 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
)
|
||||
|
||||
type hookRunner struct {
|
||||
}
|
||||
|
||||
func (h *hookRunner) RunMultiHook(hookRunnerFunc func(hooks plugin.Hooks) bool, hookId int) {
|
||||
|
||||
}
|
||||
func (h *hookRunner) HooksForPlugin(id string) (plugin.Hooks, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (h *hookRunner) GetPluginsEnvironment() *plugin.Environment {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestWebConnAddDeadQueue(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
wc := th.Service.NewWebConn(&WebConnConfig{
|
||||
WebSocket: &websocket.Conn{},
|
||||
}, th.Suite, func() *plugin.Environment { return nil })
|
||||
}, th.Suite, &hookRunner{})
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
msg := &model.WebSocketEvent{}
|
||||
@@ -53,7 +68,7 @@ func TestWebConnIsInDeadQueue(t *testing.T) {
|
||||
|
||||
wc := th.Service.NewWebConn(&WebConnConfig{
|
||||
WebSocket: &websocket.Conn{},
|
||||
}, th.Suite, func() *plugin.Environment { return nil })
|
||||
}, th.Suite, &hookRunner{})
|
||||
|
||||
var i int
|
||||
for ; i < 2; i++ {
|
||||
@@ -114,7 +129,7 @@ func TestWebConnClearDeadQueue(t *testing.T) {
|
||||
|
||||
wc := th.Service.NewWebConn(&WebConnConfig{
|
||||
WebSocket: &websocket.Conn{},
|
||||
}, th.Suite, func() *plugin.Environment { return nil })
|
||||
}, th.Suite, &hookRunner{})
|
||||
|
||||
var i int
|
||||
for ; i < 2; i++ {
|
||||
@@ -140,7 +155,7 @@ func TestWebConnDrainDeadQueue(t *testing.T) {
|
||||
cfg := &WebConnConfig{
|
||||
WebSocket: c,
|
||||
}
|
||||
return th.Service.NewWebConn(cfg, th.Suite, func() *plugin.Environment { return nil })
|
||||
return th.Service.NewWebConn(cfg, th.Suite, &hookRunner{})
|
||||
}
|
||||
|
||||
t.Run("Empty Queue", func(t *testing.T) {
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
|
||||
platform_mocks "github.com/mattermost/mattermost-server/v6/app/platform/mocks"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/i18n"
|
||||
"github.com/mattermost/mattermost-server/v6/store/storetest/mocks"
|
||||
"github.com/mattermost/mattermost-server/v6/testlib"
|
||||
@@ -50,7 +49,7 @@ func registerDummyWebConn(t *testing.T, th *TestHelper, addr net.Addr, session *
|
||||
TFunc: i18n.IdentityTfunc(),
|
||||
Locale: "en",
|
||||
}
|
||||
wc := th.Service.NewWebConn(cfg, th.Suite, func() *plugin.Environment { return nil })
|
||||
wc := th.Service.NewWebConn(cfg, th.Suite, &hookRunner{})
|
||||
th.Service.HubRegister(wc)
|
||||
go wc.Pump()
|
||||
return wc
|
||||
|
||||
@@ -93,7 +93,7 @@ func (ch *Channels) SetPluginsEnvironment(pluginsEnvironment *plugin.Environment
|
||||
defer ch.pluginsLock.Unlock()
|
||||
|
||||
ch.pluginsEnvironment = pluginsEnvironment
|
||||
ch.srv.Platform().SetPluginsEnvironment(pluginsEnvironment)
|
||||
ch.srv.Platform().SetPluginsEnvironment(ch)
|
||||
}
|
||||
|
||||
func (ch *Channels) syncPluginsActiveState() {
|
||||
@@ -213,7 +213,7 @@ func (a *App) InitPlugins(c *request.Context, pluginDir, webappPluginDir string)
|
||||
func (ch *Channels) initPlugins(c *request.Context, pluginDir, webappPluginDir string) {
|
||||
// Acquiring lock manually, as plugins might be disabled. See GetPluginsEnvironment.
|
||||
defer func() {
|
||||
ch.srv.Platform().SetPluginsEnvironment(ch.pluginsEnvironment)
|
||||
ch.srv.Platform().SetPluginsEnvironment(ch)
|
||||
}()
|
||||
|
||||
ch.pluginsLock.RLock()
|
||||
@@ -279,7 +279,7 @@ func (ch *Channels) initPlugins(c *request.Context, pluginDir, webappPluginDir s
|
||||
ch.syncPluginsActiveState()
|
||||
}
|
||||
if pluginsEnvironment := ch.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
if err := hooks.OnConfigurationChange(); err != nil {
|
||||
ch.srv.Log().Error("Plugin OnConfigurationChange hook failed", mlog.Err(err))
|
||||
}
|
||||
|
||||
@@ -1234,7 +1234,7 @@ func TestHookRunDataRetention(t *testing.T) {
|
||||
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||
|
||||
hookCalled := false
|
||||
th.App.GetPluginsEnvironment().RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
th.App.Channels().RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
n, _ := hooks.RunDataRetention(0, 0)
|
||||
// Ensure return it correct
|
||||
assert.Equal(t, int64(100), n)
|
||||
@@ -1278,7 +1278,7 @@ func TestHookOnSendDailyTelemetry(t *testing.T) {
|
||||
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||
|
||||
hookCalled := false
|
||||
th.App.GetPluginsEnvironment().RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
th.App.Channels().RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnSendDailyTelemetry()
|
||||
|
||||
hookCalled = true
|
||||
@@ -1322,7 +1322,7 @@ func TestHookOnCloudLimitsUpdated(t *testing.T) {
|
||||
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||
|
||||
hookCalled := false
|
||||
th.App.GetPluginsEnvironment().RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
th.App.Channels().RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnCloudLimitsUpdated(nil)
|
||||
|
||||
hookCalled = true
|
||||
|
||||
@@ -270,7 +270,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 {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
replacementPost, rejectionReason := hooks.MessageWillBePosted(pluginContext, post.ForPlugin())
|
||||
if rejectionReason != "" {
|
||||
id := "Post rejected by plugin. " + rejectionReason
|
||||
@@ -332,7 +332,7 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
|
||||
pluginPost := rpost.ForPlugin()
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.MessageHasBeenPosted(pluginContext, pluginPost)
|
||||
return true
|
||||
}, plugin.MessageHasBeenPostedID)
|
||||
@@ -661,7 +661,7 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
var rejectionReason string
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
newPost, rejectionReason = hooks.MessageWillBeUpdated(pluginContext, newPost.ForPlugin(), oldPost.ForPlugin())
|
||||
return post != nil
|
||||
}, plugin.MessageWillBeUpdatedID)
|
||||
@@ -689,7 +689,7 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
|
||||
pluginNewPost := newPost.ForPlugin()
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.MessageHasBeenUpdated(pluginContext, pluginNewPost, pluginOldPost)
|
||||
return true
|
||||
}, plugin.MessageHasBeenUpdatedID)
|
||||
|
||||
@@ -46,7 +46,7 @@ func (a *App) SaveReactionForPost(c *request.Context, reaction *model.Reaction)
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.ReactionHasBeenAdded(pluginContext, reaction)
|
||||
return true
|
||||
}, plugin.ReactionHasBeenAddedID)
|
||||
@@ -145,7 +145,7 @@ func (a *App) DeleteReactionForPost(c *request.Context, reaction *model.Reaction
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.ReactionHasBeenRemoved(pluginContext, reaction)
|
||||
return true
|
||||
}, plugin.ReactionHasBeenRemovedID)
|
||||
|
||||
@@ -161,6 +161,8 @@ type Server struct {
|
||||
tracer *tracing.Tracer
|
||||
|
||||
products map[string]Product
|
||||
|
||||
hooksManager *product.HooksManager
|
||||
}
|
||||
|
||||
func (s *Server) Store() store.Store {
|
||||
@@ -255,6 +257,8 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
return nil, errors.Wrapf(err, "unable to create teams service")
|
||||
}
|
||||
|
||||
s.hooksManager = product.NewHooksManager(s.GetMetrics())
|
||||
|
||||
// ensure app implements `product.UserService`
|
||||
var _ product.UserService = (*App)(nil)
|
||||
|
||||
|
||||
@@ -854,7 +854,7 @@ func (a *App) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User,
|
||||
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasJoinedTeam(pluginContext, teamMember, actor)
|
||||
return true
|
||||
}, plugin.UserHasJoinedTeamID)
|
||||
@@ -1228,7 +1228,7 @@ func (a *App) postProcessTeamMemberLeave(c request.CTX, teamMember *model.TeamMe
|
||||
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasLeftTeam(pluginContext, teamMember, actor)
|
||||
return true
|
||||
}, plugin.UserHasLeftTeamID)
|
||||
|
||||
@@ -67,7 +67,7 @@ func (a *App) runPluginsHook(c *request.Context, info *model.FileInfo, file io.R
|
||||
var rejErr *model.AppError
|
||||
var once sync.Once
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
once.Do(func() {
|
||||
hookHasRunCh <- struct{}{}
|
||||
})
|
||||
|
||||
@@ -311,7 +311,7 @@ func (a *App) createUserOrGuest(c request.CTX, user *model.User, guest bool) (*m
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasBeenCreated(pluginContext, ruser)
|
||||
return true
|
||||
}, plugin.UserHasBeenCreatedID)
|
||||
|
||||
@@ -16,5 +16,5 @@ func (a *App) PopulateWebConnConfig(s *model.Session, cfg *platform.WebConnConfi
|
||||
|
||||
// NewWebConn returns a new WebConn instance.
|
||||
func (a *App) NewWebConn(cfg *platform.WebConnConfig) *platform.WebConn {
|
||||
return a.Srv().Platform().NewWebConn(cfg, a, a.ch.GetPluginsEnvironment)
|
||||
return a.Srv().Platform().NewWebConn(cfg, a, a.ch)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user