* Move plugins under Channels We move all plugin related fields under *Channels. This essentially migrates several methods from being under *Server to under *Channels. We also move the plugin startup and shutdown code to be under Channels.Start and Channels.Shutdown. While here, we remove the getPluginPublicKeyFiles method which was a one-line method which uselessly returned an error. Lastly, we fix the product initialization order which was incorrect previously. Products are dependent on the main server. So startup should be products -> server. And shutdown should be server -> products. ```release-note NONE ``` * Added app layer ```release-note NONE ``` * Incorporate suggestions ```release-note NONE ```
109 строки
3.5 KiB
Go
109 строки
3.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/model"
|
|
)
|
|
|
|
// GetPluginStatus returns the status for a plugin installed on this server.
|
|
func (ch *Channels) GetPluginStatus(id string) (*model.PluginStatus, *model.AppError) {
|
|
pluginsEnvironment := ch.GetPluginsEnvironment()
|
|
if pluginsEnvironment == nil {
|
|
return nil, model.NewAppError("GetPluginStatus", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
|
|
}
|
|
|
|
pluginStatuses, err := pluginsEnvironment.Statuses()
|
|
if err != nil {
|
|
return nil, model.NewAppError("GetPluginStatus", "app.plugin.get_statuses.app_error", nil, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
|
|
for _, status := range pluginStatuses {
|
|
if status.PluginId == id {
|
|
// Add our cluster ID
|
|
if ch.srv.Cluster != nil {
|
|
status.ClusterId = ch.srv.Cluster.GetClusterId()
|
|
}
|
|
|
|
return status, nil
|
|
}
|
|
}
|
|
|
|
return nil, model.NewAppError("GetPluginStatus", "app.plugin.not_installed.app_error", nil, "", http.StatusNotFound)
|
|
}
|
|
|
|
// GetPluginStatus returns the status for a plugin installed on this server.
|
|
func (a *App) GetPluginStatus(id string) (*model.PluginStatus, *model.AppError) {
|
|
return a.ch.GetPluginStatus(id)
|
|
}
|
|
|
|
// GetPluginStatuses returns the status for plugins installed on this server.
|
|
func (ch *Channels) GetPluginStatuses() (model.PluginStatuses, *model.AppError) {
|
|
pluginsEnvironment := ch.GetPluginsEnvironment()
|
|
if pluginsEnvironment == nil {
|
|
return nil, model.NewAppError("GetPluginStatuses", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
|
|
}
|
|
|
|
pluginStatuses, err := pluginsEnvironment.Statuses()
|
|
if err != nil {
|
|
return nil, model.NewAppError("GetPluginStatuses", "app.plugin.get_statuses.app_error", nil, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
|
|
// Add our cluster ID
|
|
for _, status := range pluginStatuses {
|
|
if ch.srv.Cluster != nil {
|
|
status.ClusterId = ch.srv.Cluster.GetClusterId()
|
|
} else {
|
|
status.ClusterId = ""
|
|
}
|
|
}
|
|
|
|
return pluginStatuses, nil
|
|
}
|
|
|
|
// GetPluginStatuses returns the status for plugins installed on this server.
|
|
func (a *App) GetPluginStatuses() (model.PluginStatuses, *model.AppError) {
|
|
return a.ch.GetPluginStatuses()
|
|
}
|
|
|
|
// GetClusterPluginStatuses returns the status for plugins installed anywhere in the cluster.
|
|
func (a *App) GetClusterPluginStatuses() (model.PluginStatuses, *model.AppError) {
|
|
return a.ch.getClusterPluginStatuses()
|
|
}
|
|
|
|
func (ch *Channels) getClusterPluginStatuses() (model.PluginStatuses, *model.AppError) {
|
|
pluginStatuses, err := ch.GetPluginStatuses()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if ch.srv.Cluster != nil && *ch.srv.Config().ClusterSettings.Enable {
|
|
clusterPluginStatuses, err := ch.srv.Cluster.GetPluginStatuses()
|
|
if err != nil {
|
|
return nil, model.NewAppError("GetClusterPluginStatuses", "app.plugin.get_cluster_plugin_statuses.app_error", nil, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
|
|
pluginStatuses = append(pluginStatuses, clusterPluginStatuses...)
|
|
}
|
|
|
|
return pluginStatuses, nil
|
|
}
|
|
|
|
func (ch *Channels) notifyPluginStatusesChanged() error {
|
|
pluginStatuses, err := ch.getClusterPluginStatuses()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Notify any system admins.
|
|
message := model.NewWebSocketEvent(model.WebsocketEventPluginStatusesChanged, "", "", "", nil)
|
|
message.Add("plugin_statuses", pluginStatuses)
|
|
message.GetBroadcast().ContainsSensitiveData = true
|
|
ch.srv.Publish(message)
|
|
|
|
return nil
|
|
}
|