From e4fe76d01f71784f31b60f18061a470008a15018 Mon Sep 17 00:00:00 2001 From: Conor Macpherson Date: Tue, 3 Jan 2023 11:47:05 -0500 Subject: [PATCH] Only pull active plugins from the mattermost marketplace. --- app/true_up.go | 44 ++++++++++++++++++++++++--------- model/true_up_review_profile.go | 12 +++------ services/telemetry/telemetry.go | 4 +-- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/app/true_up.go b/app/true_up.go index b80ed77333..b782e956ea 100644 --- a/app/true_up.go +++ b/app/true_up.go @@ -17,6 +17,34 @@ import ( "github.com/mattermost/mattermost-server/v6/utils" ) +func pluginActivated(pluginStates map[string]*model.PluginState, pluginId string) bool { + state, ok := pluginStates[pluginId] + if !ok { + return false + } + return state.Enable +} + +func (a *App) getMarketplacePlugins() ([]string, error) { + ts := a.Srv().telemetryService + config := a.Srv().Config() + + marketplacePlugins, err := ts.GetAllMarketplacePlugins(model.PluginSettingsDefaultMarketplaceURL) + if err != nil { + return nil, err + } + + activePlugins := []string{} + for _, p := range marketplacePlugins { + id := p.Manifest.Id + if pluginActivated(config.PluginSettings.PluginStates, id) { + activePlugins = append(activePlugins, id) + } + } + + return activePlugins, nil +} + func (a *App) getTrueUpProfile() (*model.TrueUpReviewProfile, error) { license := a.Channels().License() @@ -42,20 +70,12 @@ func (a *App) getTrueUpProfile() (*model.TrueUpReviewProfile, error) { // Plugin Data trueUpReviewPlugins := model.TrueUpReviewPlugins{ - ActivePluginNames: []string{}, - InactivePluginNames: []string{}, + PluginNames: []string{}, } - if pluginResponse, err := a.GetPlugins(); err == nil { - for _, plugin := range pluginResponse.Active { - trueUpReviewPlugins.ActivePluginNames = append(trueUpReviewPlugins.ActivePluginNames, plugin.Name) - } - trueUpReviewPlugins.TotalActivePlugins = len(trueUpReviewPlugins.ActivePluginNames) - - for _, plugin := range pluginResponse.Inactive { - trueUpReviewPlugins.InactivePluginNames = append(trueUpReviewPlugins.InactivePluginNames, plugin.Name) - } - trueUpReviewPlugins.TotalInactivePlugins = len(trueUpReviewPlugins.InactivePluginNames) + if plugins, err := a.getMarketplacePlugins(); err == nil { + trueUpReviewPlugins.PluginNames = plugins + trueUpReviewPlugins.TotalPlugins = len(plugins) } // Authentication Features diff --git a/model/true_up_review_profile.go b/model/true_up_review_profile.go index 250032dcf2..bb6b6d9dd6 100644 --- a/model/true_up_review_profile.go +++ b/model/true_up_review_profile.go @@ -21,18 +21,14 @@ type TrueUpReviewProfile struct { } type TrueUpReviewPlugins struct { - TotalActivePlugins int `json:"total_active_plugins"` - TotalInactivePlugins int `json:"total_inactive_plugins"` - ActivePluginNames []string `json:"active_plugin_names"` - InactivePluginNames []string `json:"inactive_plugin_names"` + TotalPlugins int `json:"total_plugins"` + PluginNames []string `json:"plugin_names"` } func (t *TrueUpReviewPlugins) ToMap() map[string]interface{} { return map[string]interface{}{ - "total_active_plugins": t.TotalActivePlugins, - "total_inactive_plugins": t.TotalInactivePlugins, - "active_plugin_names": strings.Join(t.ActivePluginNames, ","), - "inactive_plugin_names": strings.Join(t.InactivePluginNames, ","), + "total_plugins": t.TotalPlugins, + "plugin_names": strings.Join(t.PluginNames, ","), } } diff --git a/services/telemetry/telemetry.go b/services/telemetry/telemetry.go index 5f319b03a5..a426fbd80b 100644 --- a/services/telemetry/telemetry.go +++ b/services/telemetry/telemetry.go @@ -1418,7 +1418,7 @@ func (ts *TelemetryService) trackPluginConfig(cfg *model.Config, marketplaceURL "focalboard", } - marketplacePlugins, err := ts.getAllMarketplaceplugins(marketplaceURL) + marketplacePlugins, err := ts.GetAllMarketplacePlugins(marketplaceURL) if err != nil { mlog.Info("Failed to fetch marketplace plugins for telemetry. Using predefined list.", mlog.Err(err)) @@ -1456,7 +1456,7 @@ func (ts *TelemetryService) trackPluginConfig(cfg *model.Config, marketplaceURL ts.SendTelemetry(TrackConfigPlugin, pluginConfigData) } -func (ts *TelemetryService) getAllMarketplaceplugins(marketplaceURL string) ([]*model.BaseMarketplacePlugin, error) { +func (ts *TelemetryService) GetAllMarketplacePlugins(marketplaceURL string) ([]*model.BaseMarketplacePlugin, error) { marketplaceClient, err := marketplace.NewClient( marketplaceURL, ts.srv.HTTPService(),