github.com/lologarithm/mattermost-server@v5.3.2-0.20181002060438-c82a84ed765b+incompatible/app/plugin_statuses.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"net/http"
     8  
     9  	"github.com/mattermost/mattermost-server/model"
    10  )
    11  
    12  // GetPluginStatuses returns the status for plugins installed on this server.
    13  func (a *App) GetPluginStatuses() (model.PluginStatuses, *model.AppError) {
    14  	if a.Plugins == nil || !*a.Config().PluginSettings.Enable {
    15  		return nil, model.NewAppError("GetPluginStatuses", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
    16  	}
    17  
    18  	pluginStatuses, err := a.Plugins.Statuses()
    19  	if err != nil {
    20  		return nil, model.NewAppError("GetPluginStatuses", "app.plugin.get_statuses.app_error", nil, err.Error(), http.StatusInternalServerError)
    21  	}
    22  
    23  	// Add our cluster ID
    24  	for _, status := range pluginStatuses {
    25  		status.ClusterId = a.GetClusterId()
    26  	}
    27  
    28  	return pluginStatuses, nil
    29  }
    30  
    31  // GetClusterPluginStatuses returns the status for plugins installed anywhere in the cluster.
    32  func (a *App) GetClusterPluginStatuses() (model.PluginStatuses, *model.AppError) {
    33  	pluginStatuses, err := a.GetPluginStatuses()
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  
    38  	if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
    39  		clusterPluginStatuses, err := a.Cluster.GetPluginStatuses()
    40  		if err != nil {
    41  			return nil, model.NewAppError("GetClusterPluginStatuses", "app.plugin.get_cluster_plugin_statuses.app_error", nil, err.Error(), http.StatusInternalServerError)
    42  		}
    43  
    44  		pluginStatuses = append(pluginStatuses, clusterPluginStatuses...)
    45  	}
    46  
    47  	return pluginStatuses, nil
    48  }
    49  
    50  func (a *App) notifyPluginStatusesChanged() error {
    51  	pluginStatuses, err := a.GetClusterPluginStatuses()
    52  	if err != nil {
    53  		return err
    54  	}
    55  
    56  	// Notify any system admins.
    57  	message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PLUGIN_STATUSES_CHANGED, "", "", "", nil)
    58  	message.Add("plugin_statuses", pluginStatuses)
    59  	message.Broadcast.ContainsSensitiveData = true
    60  	a.Publish(message)
    61  
    62  	return nil
    63  }