[MM-25284] Include license type in Marketplace request (#14586)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d317dd2dde
Коммит
23ecc9ad0a
@@ -555,6 +555,85 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Empty(t, plugins)
|
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) {
|
func TestGetInstalledMarketplacePlugins(t *testing.T) {
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ func (a *App) GetMarketplacePlugins(filter *model.MarketplacePluginFilter) ([]*m
|
|||||||
plugins := map[string]*model.MarketplacePlugin{}
|
plugins := map[string]*model.MarketplacePlugin{}
|
||||||
|
|
||||||
if *a.Config().PluginSettings.EnableRemoteMarketplace && !filter.LocalOnly {
|
if *a.Config().PluginSettings.EnableRemoteMarketplace && !filter.LocalOnly {
|
||||||
p, appErr := a.getRemotePlugins(filter)
|
p, appErr := a.getRemotePlugins()
|
||||||
if appErr != nil {
|
if appErr != nil {
|
||||||
return nil, appErr
|
return nil, appErr
|
||||||
}
|
}
|
||||||
@@ -497,7 +497,7 @@ func (a *App) getRemoteMarketplacePlugin(pluginId, version string) (*model.BaseM
|
|||||||
return plugin, nil
|
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{}
|
result := map[string]*model.MarketplacePlugin{}
|
||||||
|
|
||||||
pluginsEnvironment := a.GetPluginsEnvironment()
|
pluginsEnvironment := a.GetPluginsEnvironment()
|
||||||
@@ -514,10 +514,21 @@ func (a *App) getRemotePlugins(filter *model.MarketplacePluginFilter) (map[strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch all plugins from marketplace.
|
// Fetch all plugins from marketplace.
|
||||||
marketplacePlugins, err := marketplaceClient.GetPlugins(&model.MarketplacePluginFilter{
|
filter := &model.MarketplacePluginFilter{
|
||||||
PerPage: -1,
|
PerPage: -1,
|
||||||
ServerVersion: model.CurrentVersion,
|
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 {
|
if err != nil {
|
||||||
return nil, model.NewAppError("getRemotePlugins", "app.plugin.marketplace_client.failed_to_fetch", nil, err.Error(), http.StatusInternalServerError)
|
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"`
|
GuestAccountsPermissions *bool `json:"guest_accounts_permissions"`
|
||||||
IDLoadedPushNotifications *bool `json:"id_loaded"`
|
IDLoadedPushNotifications *bool `json:"id_loaded"`
|
||||||
LockTeammateNameDisplay *bool `json:"lock_teammate_name_display"`
|
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
|
// after we enabled more features we'll need to control them with this
|
||||||
FutureFeatures *bool `json:"future_features"`
|
FutureFeatures *bool `json:"future_features"`
|
||||||
@@ -90,6 +91,7 @@ func (f *Features) ToMap() map[string]interface{} {
|
|||||||
"guest_accounts_permissions": *f.GuestAccountsPermissions,
|
"guest_accounts_permissions": *f.GuestAccountsPermissions,
|
||||||
"id_loaded": *f.IDLoadedPushNotifications,
|
"id_loaded": *f.IDLoadedPushNotifications,
|
||||||
"lock_teammate_name_display": *f.LockTeammateNameDisplay,
|
"lock_teammate_name_display": *f.LockTeammateNameDisplay,
|
||||||
|
"enterprise_plugins": *f.EnterprisePlugins,
|
||||||
"future": *f.FutureFeatures,
|
"future": *f.FutureFeatures,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,6 +192,10 @@ func (f *Features) SetDefaults() {
|
|||||||
if f.LockTeammateNameDisplay == nil {
|
if f.LockTeammateNameDisplay == nil {
|
||||||
f.LockTeammateNameDisplay = NewBool(*f.FutureFeatures)
|
f.LockTeammateNameDisplay = NewBool(*f.FutureFeatures)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if f.EnterprisePlugins == nil {
|
||||||
|
f.EnterprisePlugins = NewBool(*f.FutureFeatures)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *License) IsExpired() bool {
|
func (l *License) IsExpired() bool {
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ type MarketplacePluginFilter struct {
|
|||||||
PerPage int
|
PerPage int
|
||||||
Filter string
|
Filter string
|
||||||
ServerVersion string
|
ServerVersion string
|
||||||
|
BuildEnterpriseReady bool
|
||||||
|
EnterprisePlugins bool
|
||||||
LocalOnly bool
|
LocalOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +92,8 @@ func (filter *MarketplacePluginFilter) ApplyToURL(u *url.URL) {
|
|||||||
}
|
}
|
||||||
q.Add("filter", filter.Filter)
|
q.Add("filter", filter.Filter)
|
||||||
q.Add("server_version", filter.ServerVersion)
|
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))
|
q.Add("local_only", strconv.FormatBool(filter.LocalOnly))
|
||||||
u.RawQuery = q.Encode()
|
u.RawQuery = q.Encode()
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user