[MM-48542] Removing integration limits (#21282)

* Removing integration limits

* Remove freemium limit test

* Remove test assertion regarding cloud limits

* Remove GetIntegrationsUsage

* Removing integrations usage notifications

* This shouldn't be removed

* Removing client call and websocket event

* Remove old translations

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Javier Aguirre
2022-11-23 10:42:23 +01:00
коммит произвёл GitHub
родитель 0509e78744
Коммит 7f419ea091
28 изменённых файлов: 1 добавлений и 559 удалений

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

@@ -157,12 +157,7 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
if cfg.PluginSettings.PluginStates[model.PluginIdFocalboard].Enable && cfg.FeatureFlags.BoardsProduct {
c.Err = model.NewAppError("EnablePlugin", "app.plugin.product_mode.app_error", map[string]any{"Name": model.PluginIdFocalboard}, "", http.StatusBadRequest)
return
}
if appErr := c.App.CheckFreemiumLimitsForConfigSave(appCfg, cfg); appErr != nil {
c.Err = appErr
c.Err = model.NewAppError("EnablePlugin", "app.plugin.product_mode.app_error", map[string]any{"Name": model.PluginIdFocalboard}, "", http.StatusInternalServerError)
return
}
@@ -304,11 +299,6 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if appErr := c.App.CheckFreemiumLimitsForConfigSave(appCfg, cfg); appErr != nil {
c.Err = appErr
return
}
// There are some settings that cannot be changed in a cloud env
if c.App.Channels().License().IsCloud() {
if cfg.ComplianceSettings.Directory != nil && *appCfg.ComplianceSettings.Directory != *cfg.ComplianceSettings.Directory {

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

@@ -17,9 +17,7 @@ import (
"github.com/mattermost/mattermost-server/v6/app"
"github.com/mattermost/mattermost-server/v6/config"
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin/plugintest/mock"
)
func TestGetConfig(t *testing.T) {
@@ -249,59 +247,6 @@ func TestUpdateConfig(t *testing.T) {
assert.Equal(t, newURL, *cfg2.PluginSettings.MarketplaceURL)
})
t.Run("Should not be able to save config if the new config exceeds Freemium limits", func(t *testing.T) {
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
defer th.App.Srv().RemoveLicense()
cloud := &mocks.CloudInterface{}
cloudImpl := th.App.Srv().Cloud
defer func() {
th.App.Srv().Cloud = cloudImpl
}()
th.App.Srv().Cloud = cloud
cloud.Mock.On("GetCloudLimits", mock.Anything).Return(&model.ProductLimits{
Integrations: &model.IntegrationsLimits{
Enabled: model.NewInt(0),
},
}, nil).Once()
// Exceed freemium limit. Should throw error.
cfg1 := th.App.Config().Clone()
cfg1.PluginSettings.PluginStates["new-plugin"] = &model.PluginState{Enable: true}
_, _, err1 := th.SystemAdminClient.UpdateConfig(cfg1)
require.Error(t, err1)
// No attempt to enable a plugin. Should not throw error.
cfg1 = th.App.Config().Clone()
cfg1.PluginSettings.PluginStates["new-plugin"] = &model.PluginState{Enable: false}
_, _, err1 = th.SystemAdminClient.UpdateConfig(cfg1)
require.NoError(t, err1)
cloud.Mock.On("GetCloudLimits", mock.Anything).Return(&model.ProductLimits{
Integrations: &model.IntegrationsLimits{
Enabled: model.NewInt(1),
},
}, nil).Twice()
// Exceed freemium limit while enabling more than one plugin. Should throw error.
cfg1 = th.App.Config().Clone()
cfg1.PluginSettings.PluginStates["new-plugin"] = &model.PluginState{Enable: true}
cfg1.PluginSettings.PluginStates["new-plugin2"] = &model.PluginState{Enable: true}
_, _, err1 = th.SystemAdminClient.PatchConfig(cfg1)
require.Error(t, err1)
// Match freemium limit. Should not throw error.
cfg1 = th.App.Config().Clone()
cfg1.PluginSettings.PluginStates["new-plugin"] = &model.PluginState{Enable: true}
_, _, err1 = th.SystemAdminClient.UpdateConfig(cfg1)
require.NoError(t, err1)
// Save same config with same plugin enabled. Should not throw error.
_, _, err1 = th.SystemAdminClient.UpdateConfig(cfg1)
require.NoError(t, err1)
})
t.Run("Should not be able to modify ComplianceSettings.Directory in cloud", func(t *testing.T) {
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
defer th.App.Srv().RemoveLicense()
@@ -847,59 +792,6 @@ func TestPatchConfig(t *testing.T) {
assert.Equal(t, newURL, *cfg.PluginSettings.MarketplaceURL)
})
t.Run("Should not be able to save config if the new config exceeds Freemium limits", func(t *testing.T) {
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
defer th.App.Srv().RemoveLicense()
cloud := &mocks.CloudInterface{}
cloudImpl := th.App.Srv().Cloud
defer func() {
th.App.Srv().Cloud = cloudImpl
}()
th.App.Srv().Cloud = cloud
cloud.Mock.On("GetCloudLimits", mock.Anything).Return(&model.ProductLimits{
Integrations: &model.IntegrationsLimits{
Enabled: model.NewInt(0),
},
}, nil).Once()
// Exceed freemium limit. Should throw error.
cfg1 := th.App.Config().Clone()
cfg1.PluginSettings.PluginStates["new-plugin"] = &model.PluginState{Enable: true}
_, _, err1 := th.SystemAdminClient.PatchConfig(cfg1)
require.Error(t, err1)
// No attempt to enable a plugin. Should not throw error.
cfg1 = th.App.Config().Clone()
cfg1.PluginSettings.PluginStates["new-plugin"] = &model.PluginState{Enable: false}
_, _, err1 = th.SystemAdminClient.PatchConfig(cfg1)
require.NoError(t, err1)
cloud.Mock.On("GetCloudLimits", mock.Anything).Return(&model.ProductLimits{
Integrations: &model.IntegrationsLimits{
Enabled: model.NewInt(1),
},
}, nil).Twice()
// Exceed freemium limit while enabling more than one plugin. Should throw error.
cfg1 = th.App.Config().Clone()
cfg1.PluginSettings.PluginStates["new-plugin"] = &model.PluginState{Enable: true}
cfg1.PluginSettings.PluginStates["new-plugin2"] = &model.PluginState{Enable: true}
_, _, err1 = th.SystemAdminClient.PatchConfig(cfg1)
require.Error(t, err1)
// Match freemium limit. Should not throw error.
cfg1 = th.App.Config().Clone()
cfg1.PluginSettings.PluginStates["new-plugin"] = &model.PluginState{Enable: true}
_, _, err1 = th.SystemAdminClient.PatchConfig(cfg1)
require.NoError(t, err1)
// Save same config with same plugin enabled. Should not throw error.
_, _, err1 = th.SystemAdminClient.PatchConfig(cfg1)
require.NoError(t, err1)
})
t.Run("System Admin should not be able to clear Site URL", func(t *testing.T) {
cfg, _, err := th.SystemAdminClient.GetConfig()
require.NoError(t, err)

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

@@ -18,8 +18,6 @@ func (api *API) InitUsage() {
api.BaseRoutes.Usage.Handle("/storage", api.APISessionRequired(getStorageUsage)).Methods("GET")
// GET /api/v4/usage/teams
api.BaseRoutes.Usage.Handle("/teams", api.APISessionRequired(getTeamsUsage)).Methods("GET")
// GET /api/v4/usage/integrations
api.BaseRoutes.Usage.Handle("/integrations", api.APISessionRequired(getIntegrationsUsage)).Methods("GET")
}
func getPostsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -74,30 +72,3 @@ func getTeamsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write(json)
}
func getIntegrationsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
if !*c.App.Config().PluginSettings.Enable {
json, err := json.Marshal(&model.IntegrationsUsage{})
if err != nil {
c.Err = model.NewAppError("Api4.getIntegrationsUsage", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
return
}
w.Write(json)
return
}
usage, appErr := c.App.GetIntegrationsUsage()
if appErr != nil {
c.Err = appErr
return
}
json, err := json.Marshal(usage)
if err != nil {
c.Err = model.NewAppError("Api4.getIntegrationsUsage", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
return
}
w.Write(json)
}

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

@@ -91,28 +91,3 @@ func TestGetTeamsUsage(t *testing.T) {
assert.Equal(t, int64(3), usage.Active)
})
}
func TestGetIntegrationsUsage(t *testing.T) {
t.Run("unauthenticated users can not access", func(t *testing.T) {
th := Setup(t)
defer th.TearDown()
th.Client.Logout()
usage, r, err := th.Client.GetIntegrationsUsage()
assert.Error(t, err)
assert.Nil(t, usage)
assert.Equal(t, http.StatusUnauthorized, r.StatusCode)
})
t.Run("good request returns response", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
usage, r, err := th.Client.GetIntegrationsUsage()
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, r.StatusCode)
assert.NotNil(t, usage)
assert.Equal(t, 0, usage.Enabled)
})
}