Check for cloud license and CWS error when checking integration freemium limits (#20387)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
71cdd9e486
Коммит
e18b1cf89f
@@ -250,6 +250,8 @@ func TestUpdateConfig(t *testing.T) {
|
||||
})
|
||||
|
||||
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()
|
||||
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
|
||||
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
|
||||
th.App.ReloadConfig()
|
||||
@@ -853,6 +855,8 @@ func TestPatchConfig(t *testing.T) {
|
||||
})
|
||||
|
||||
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()
|
||||
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
|
||||
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
|
||||
th.App.ReloadConfig()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *App) checkIntegrationLimitsForConfigSave(oldConfig, newConfig *model.Config) *model.AppError {
|
||||
@@ -73,6 +74,10 @@ func (a *App) checkIfIntegrationsMeetFreemiumLimits(originalPluginIds []string)
|
||||
return nil
|
||||
}
|
||||
|
||||
if a.License() == nil || !*a.License().Features.Cloud {
|
||||
return nil
|
||||
}
|
||||
|
||||
pluginIds := map[string]bool{}
|
||||
for _, pluginId := range originalPluginIds {
|
||||
if _, ok := model.InstalledIntegrationsIgnoredPlugins[pluginId]; !ok {
|
||||
@@ -82,7 +87,8 @@ func (a *App) checkIfIntegrationsMeetFreemiumLimits(originalPluginIds []string)
|
||||
|
||||
limits, err := a.Cloud().GetCloudLimits("")
|
||||
if err != nil {
|
||||
return model.NewAppError("checkIfIntegrationMeetsFreemiumLimits", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
a.Log().Error("Error fetching cloud limits for enabled integrations", mlog.Err(err))
|
||||
return nil
|
||||
}
|
||||
|
||||
if limits == nil || limits.Integrations == nil || limits.Integrations.Enabled == nil {
|
||||
@@ -91,7 +97,8 @@ func (a *App) checkIfIntegrationsMeetFreemiumLimits(originalPluginIds []string)
|
||||
|
||||
installed, appErr := a.ch.getInstalledIntegrations()
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
a.Log().Error("Failed to get installed integrations to check cloud limit", mlog.Err(appErr))
|
||||
return nil
|
||||
}
|
||||
|
||||
enableCount := len(pluginIds)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -1025,8 +1026,26 @@ func TestEnablePluginWithCloudLimits(t *testing.T) {
|
||||
checkError(t, appErr)
|
||||
require.Equal(t, "app.install_integration.reached_max_limit.error", appErr.Id)
|
||||
|
||||
th.App.Srv().RemoveLicense()
|
||||
appErr = th.App.EnablePlugin("testplugin2")
|
||||
checkNoError(t, appErr)
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
appErr = th.App.EnablePlugin("testplugin2")
|
||||
checkError(t, appErr)
|
||||
|
||||
os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
|
||||
th.App.ReloadConfig()
|
||||
appErr = th.App.EnablePlugin("testplugin2")
|
||||
checkNoError(t, appErr)
|
||||
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
|
||||
th.App.ReloadConfig()
|
||||
appErr = th.App.EnablePlugin("testplugin2")
|
||||
checkError(t, appErr)
|
||||
|
||||
// Let enable succeed if a CWS error occurs
|
||||
cloud = &mocks.CloudInterface{}
|
||||
th.App.Srv().Cloud = cloud
|
||||
cloud.Mock.On("GetCloudLimits", mock.Anything).Return(nil, errors.New("error getting limits"))
|
||||
|
||||
appErr = th.App.EnablePlugin("testplugin2")
|
||||
checkNoError(t, appErr)
|
||||
|
||||
Ссылка в новой задаче
Block a user