Only pull active plugins from the mattermost marketplace.

Этот коммит содержится в:
Conor Macpherson
2023-01-03 11:47:05 -05:00
родитель 84fe5514fc
Коммит e4fe76d01f
3 изменённых файлов: 38 добавлений и 22 удалений

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

@@ -17,6 +17,34 @@ import (
"github.com/mattermost/mattermost-server/v6/utils" "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) { func (a *App) getTrueUpProfile() (*model.TrueUpReviewProfile, error) {
license := a.Channels().License() license := a.Channels().License()
@@ -42,20 +70,12 @@ func (a *App) getTrueUpProfile() (*model.TrueUpReviewProfile, error) {
// Plugin Data // Plugin Data
trueUpReviewPlugins := model.TrueUpReviewPlugins{ trueUpReviewPlugins := model.TrueUpReviewPlugins{
ActivePluginNames: []string{}, PluginNames: []string{},
InactivePluginNames: []string{},
} }
if pluginResponse, err := a.GetPlugins(); err == nil { if plugins, err := a.getMarketplacePlugins(); err == nil {
for _, plugin := range pluginResponse.Active { trueUpReviewPlugins.PluginNames = plugins
trueUpReviewPlugins.ActivePluginNames = append(trueUpReviewPlugins.ActivePluginNames, plugin.Name) trueUpReviewPlugins.TotalPlugins = len(plugins)
}
trueUpReviewPlugins.TotalActivePlugins = len(trueUpReviewPlugins.ActivePluginNames)
for _, plugin := range pluginResponse.Inactive {
trueUpReviewPlugins.InactivePluginNames = append(trueUpReviewPlugins.InactivePluginNames, plugin.Name)
}
trueUpReviewPlugins.TotalInactivePlugins = len(trueUpReviewPlugins.InactivePluginNames)
} }
// Authentication Features // Authentication Features

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

@@ -21,18 +21,14 @@ type TrueUpReviewProfile struct {
} }
type TrueUpReviewPlugins struct { type TrueUpReviewPlugins struct {
TotalActivePlugins int `json:"total_active_plugins"` TotalPlugins int `json:"total_plugins"`
TotalInactivePlugins int `json:"total_inactive_plugins"` PluginNames []string `json:"plugin_names"`
ActivePluginNames []string `json:"active_plugin_names"`
InactivePluginNames []string `json:"inactive_plugin_names"`
} }
func (t *TrueUpReviewPlugins) ToMap() map[string]interface{} { func (t *TrueUpReviewPlugins) ToMap() map[string]interface{} {
return map[string]interface{}{ return map[string]interface{}{
"total_active_plugins": t.TotalActivePlugins, "total_plugins": t.TotalPlugins,
"total_inactive_plugins": t.TotalInactivePlugins, "plugin_names": strings.Join(t.PluginNames, ","),
"active_plugin_names": strings.Join(t.ActivePluginNames, ","),
"inactive_plugin_names": strings.Join(t.InactivePluginNames, ","),
} }
} }

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

@@ -1418,7 +1418,7 @@ func (ts *TelemetryService) trackPluginConfig(cfg *model.Config, marketplaceURL
"focalboard", "focalboard",
} }
marketplacePlugins, err := ts.getAllMarketplaceplugins(marketplaceURL) marketplacePlugins, err := ts.GetAllMarketplacePlugins(marketplaceURL)
if err != nil { if err != nil {
mlog.Info("Failed to fetch marketplace plugins for telemetry. Using predefined list.", mlog.Err(err)) 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) 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( marketplaceClient, err := marketplace.NewClient(
marketplaceURL, marketplaceURL,
ts.srv.HTTPService(), ts.srv.HTTPService(),