[MM-25284] Include license type in Marketplace request (#14586)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d317dd2dde
Коммит
23ecc9ad0a
@@ -555,6 +555,85 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
CheckNoError(t, resp)
|
||||
require.Empty(t, plugins)
|
||||
})
|
||||
|
||||
t.Run("verify EnterprisePlugins is false for TE", func(t *testing.T) {
|
||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
licenseType, ok := req.URL.Query()["enterprise_plugins"]
|
||||
require.True(t, ok)
|
||||
require.Len(t, licenseType, 1)
|
||||
require.Equal(t, "false", licenseType[0])
|
||||
|
||||
res.WriteHeader(http.StatusOK)
|
||||
json, err := json.Marshal([]*model.MarketplacePlugin{})
|
||||
require.NoError(t, err)
|
||||
res.Write(json)
|
||||
}))
|
||||
defer func() { testServer.Close() }()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PluginSettings.EnableMarketplace = true
|
||||
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
||||
})
|
||||
|
||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
CheckNoError(t, resp)
|
||||
require.Empty(t, plugins)
|
||||
})
|
||||
|
||||
t.Run("verify EnterprisePlugins is false for E10", func(t *testing.T) {
|
||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
licenseType, ok := req.URL.Query()["enterprise_plugins"]
|
||||
require.True(t, ok)
|
||||
require.Len(t, licenseType, 1)
|
||||
require.Equal(t, "false", licenseType[0])
|
||||
|
||||
res.WriteHeader(http.StatusOK)
|
||||
json, err := json.Marshal([]*model.MarketplacePlugin{})
|
||||
require.NoError(t, err)
|
||||
res.Write(json)
|
||||
}))
|
||||
defer func() { testServer.Close() }()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PluginSettings.EnableMarketplace = true
|
||||
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
||||
})
|
||||
|
||||
l := model.NewTestLicense()
|
||||
// model.NewTestLicense generates a E20 license
|
||||
*l.Features.EnterprisePlugins = false
|
||||
th.App.SetLicense(l)
|
||||
|
||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
CheckNoError(t, resp)
|
||||
require.Empty(t, plugins)
|
||||
})
|
||||
|
||||
t.Run("verify EnterprisePlugins is false for E20", func(t *testing.T) {
|
||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
licenseType, ok := req.URL.Query()["enterprise_plugins"]
|
||||
require.True(t, ok)
|
||||
require.Len(t, licenseType, 1)
|
||||
require.Equal(t, "true", licenseType[0])
|
||||
|
||||
res.WriteHeader(http.StatusOK)
|
||||
json, err := json.Marshal([]*model.MarketplacePlugin{})
|
||||
require.NoError(t, err)
|
||||
res.Write(json)
|
||||
}))
|
||||
defer func() { testServer.Close() }()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PluginSettings.EnableMarketplace = true
|
||||
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
||||
})
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense("enterprise_plugins"))
|
||||
|
||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
CheckNoError(t, resp)
|
||||
require.Empty(t, plugins)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetInstalledMarketplacePlugins(t *testing.T) {
|
||||
|
||||
@@ -428,7 +428,7 @@ func (a *App) GetMarketplacePlugins(filter *model.MarketplacePluginFilter) ([]*m
|
||||
plugins := map[string]*model.MarketplacePlugin{}
|
||||
|
||||
if *a.Config().PluginSettings.EnableRemoteMarketplace && !filter.LocalOnly {
|
||||
p, appErr := a.getRemotePlugins(filter)
|
||||
p, appErr := a.getRemotePlugins()
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
@@ -497,7 +497,7 @@ func (a *App) getRemoteMarketplacePlugin(pluginId, version string) (*model.BaseM
|
||||
return plugin, nil
|
||||
}
|
||||
|
||||
func (a *App) getRemotePlugins(filter *model.MarketplacePluginFilter) (map[string]*model.MarketplacePlugin, *model.AppError) {
|
||||
func (a *App) getRemotePlugins() (map[string]*model.MarketplacePlugin, *model.AppError) {
|
||||
result := map[string]*model.MarketplacePlugin{}
|
||||
|
||||
pluginsEnvironment := a.GetPluginsEnvironment()
|
||||
@@ -514,10 +514,21 @@ func (a *App) getRemotePlugins(filter *model.MarketplacePluginFilter) (map[strin
|
||||
}
|
||||
|
||||
// Fetch all plugins from marketplace.
|
||||
marketplacePlugins, err := marketplaceClient.GetPlugins(&model.MarketplacePluginFilter{
|
||||
filter := &model.MarketplacePluginFilter{
|
||||
PerPage: -1,
|
||||
ServerVersion: model.CurrentVersion,
|
||||
})
|
||||
}
|
||||
|
||||
license := a.License()
|
||||
if license != nil && *license.Features.EnterprisePlugins {
|
||||
filter.EnterprisePlugins = true
|
||||
}
|
||||
|
||||
if model.BuildEnterpriseReady == "true" {
|
||||
filter.BuildEnterpriseReady = true
|
||||
}
|
||||
|
||||
marketplacePlugins, err := marketplaceClient.GetPlugins(filter)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("getRemotePlugins", "app.plugin.marketplace_client.failed_to_fetch", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ type Features struct {
|
||||
GuestAccountsPermissions *bool `json:"guest_accounts_permissions"`
|
||||
IDLoadedPushNotifications *bool `json:"id_loaded"`
|
||||
LockTeammateNameDisplay *bool `json:"lock_teammate_name_display"`
|
||||
EnterprisePlugins *bool `json:"enterprise_plugins"`
|
||||
|
||||
// after we enabled more features we'll need to control them with this
|
||||
FutureFeatures *bool `json:"future_features"`
|
||||
@@ -90,6 +91,7 @@ func (f *Features) ToMap() map[string]interface{} {
|
||||
"guest_accounts_permissions": *f.GuestAccountsPermissions,
|
||||
"id_loaded": *f.IDLoadedPushNotifications,
|
||||
"lock_teammate_name_display": *f.LockTeammateNameDisplay,
|
||||
"enterprise_plugins": *f.EnterprisePlugins,
|
||||
"future": *f.FutureFeatures,
|
||||
}
|
||||
}
|
||||
@@ -190,6 +192,10 @@ func (f *Features) SetDefaults() {
|
||||
if f.LockTeammateNameDisplay == nil {
|
||||
f.LockTeammateNameDisplay = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.EnterprisePlugins == nil {
|
||||
f.EnterprisePlugins = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *License) IsExpired() bool {
|
||||
|
||||
@@ -74,11 +74,13 @@ func (plugin *BaseMarketplacePlugin) DecodeSignature() (io.ReadSeeker, error) {
|
||||
|
||||
// MarketplacePluginFilter describes the parameters to request a list of plugins.
|
||||
type MarketplacePluginFilter struct {
|
||||
Page int
|
||||
PerPage int
|
||||
Filter string
|
||||
ServerVersion string
|
||||
LocalOnly bool
|
||||
Page int
|
||||
PerPage int
|
||||
Filter string
|
||||
ServerVersion string
|
||||
BuildEnterpriseReady bool
|
||||
EnterprisePlugins bool
|
||||
LocalOnly bool
|
||||
}
|
||||
|
||||
// ApplyToURL modifies the given url to include query string parameters for the request.
|
||||
@@ -90,6 +92,8 @@ func (filter *MarketplacePluginFilter) ApplyToURL(u *url.URL) {
|
||||
}
|
||||
q.Add("filter", filter.Filter)
|
||||
q.Add("server_version", filter.ServerVersion)
|
||||
q.Add("build_enterprise_ready", strconv.FormatBool(filter.BuildEnterpriseReady))
|
||||
q.Add("enterprise_plugins", strconv.FormatBool(filter.EnterprisePlugins))
|
||||
q.Add("local_only", strconv.FormatBool(filter.LocalOnly))
|
||||
u.RawQuery = q.Encode()
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user