From a1e16f7b0292b9b083c89395249e71072c868835 Mon Sep 17 00:00:00 2001 From: Nick Misasi Date: Tue, 22 Nov 2022 13:22:45 -0500 Subject: [PATCH] Call Cloud HandleLicenseChange when license is changed in Cloud (#21583) * Call Cloud HandleLicenseChange when license is changed in a cloud context * Remove UpdateSubscriptionFromHook as its no longer necessary * Update mocks * Remove another reference * Remove translation Co-authored-by: Mattermod --- api4/cloud.go | 18 ------------------ api4/license.go | 2 +- einterfaces/cloud.go | 2 +- einterfaces/mocks/CloudInterface.go | 28 ++++++++++++++-------------- i18n/en.json | 4 ---- 5 files changed, 16 insertions(+), 38 deletions(-) diff --git a/api4/cloud.go b/api4/cloud.go index 4537828afb..3e38324b06 100644 --- a/api4/cloud.go +++ b/api4/cloud.go @@ -13,7 +13,6 @@ import ( "github.com/mattermost/mattermost-server/v6/audit" "github.com/mattermost/mattermost-server/v6/model" - "github.com/mattermost/mattermost-server/v6/plugin" "github.com/mattermost/mattermost-server/v6/shared/mlog" ) @@ -630,23 +629,6 @@ func handleCWSWebhook(c *Context, w http.ResponseWriter, r *http.Request) { c.Err = model.NewAppError("SendCloudWelcomeEmail", "api.user.send_cloud_welcome_email.error", nil, err.Error(), http.StatusInternalServerError) return } - case model.EventTypeSubscriptionChanged: - // event.ProductLimits is nil if there was no change - if event.ProductLimits != nil { - if pluginsEnvironment := c.App.GetPluginsEnvironment(); pluginsEnvironment != nil { - pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool { - hooks.OnCloudLimitsUpdated(event.ProductLimits) - return true - }, plugin.OnCloudLimitsUpdatedID) - } - c.App.AdjustInProductLimits(event.ProductLimits, event.Subscription) - } - - if err := c.App.Cloud().UpdateSubscriptionFromHook(event.ProductLimits, event.Subscription); err != nil { - c.Err = model.NewAppError("Api4.handleCWSWebhook", "api.cloud.subscription.update_error", nil, err.Error(), http.StatusInternalServerError) - return - } - c.Logger.Info("Updated subscription from webhook event") case model.EventTypeTriggerDelinquencyEmail: var emailToTrigger model.DelinquencyEmail if event.DelinquencyEmail != nil { diff --git a/api4/license.go b/api4/license.go index 15c0b34fa8..bc89f7e1e2 100644 --- a/api4/license.go +++ b/api4/license.go @@ -139,7 +139,7 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { if c.App.Channels().License().IsCloud() { // If cloud, invalidate the caches when a new license is loaded - defer c.App.Srv().Cloud.InvalidateCaches() + defer c.App.Srv().Cloud.HandleLicenseChange() } auditRec.Success() diff --git a/einterfaces/cloud.go b/einterfaces/cloud.go index 26e7f3c5ab..854b54fdf5 100644 --- a/einterfaces/cloud.go +++ b/einterfaces/cloud.go @@ -10,7 +10,6 @@ import ( type CloudInterface interface { GetCloudProducts(userID string, includeLegacyProducts bool) ([]*model.Product, error) GetCloudLimits(userID string) (*model.ProductLimits, error) - UpdateSubscriptionFromHook(*model.ProductLimits, *model.Subscription) error CreateCustomerPayment(userID string) (*model.StripeSetupIntent, error) ConfirmCustomerPayment(userID string, confirmRequest *model.ConfirmPaymentMethodRequest) error @@ -31,4 +30,5 @@ type CloudInterface interface { // GetLicenseRenewalStatus checks on the portal whether it is possible to use token to renew a license GetLicenseRenewalStatus(userID, token string) error InvalidateCaches() error + HandleLicenseChange() error } diff --git a/einterfaces/mocks/CloudInterface.go b/einterfaces/mocks/CloudInterface.go index 1e5ba2b0a1..3157ecfc44 100644 --- a/einterfaces/mocks/CloudInterface.go +++ b/einterfaces/mocks/CloudInterface.go @@ -233,6 +233,20 @@ func (_m *CloudInterface) GetSubscription(userID string) (*model.Subscription, e return r0, r1 } +// HandleLicenseChange provides a mock function with given fields: +func (_m *CloudInterface) HandleLicenseChange() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + // InvalidateCaches provides a mock function with given fields: func (_m *CloudInterface) InvalidateCaches() error { ret := _m.Called() @@ -316,20 +330,6 @@ func (_m *CloudInterface) UpdateCloudCustomerAddress(userID string, address *mod return r0, r1 } -// UpdateSubscriptionFromHook provides a mock function with given fields: _a0, _a1 -func (_m *CloudInterface) UpdateSubscriptionFromHook(_a0 *model.ProductLimits, _a1 *model.Subscription) error { - ret := _m.Called(_a0, _a1) - - var r0 error - if rf, ok := ret.Get(0).(func(*model.ProductLimits, *model.Subscription) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - // ValidateBusinessEmail provides a mock function with given fields: userID, email func (_m *CloudInterface) ValidateBusinessEmail(userID string, email string) error { ret := _m.Called(userID, email) diff --git a/i18n/en.json b/i18n/en.json index 9943569b7d..b9ebaa8eb6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -487,10 +487,6 @@ "id": "api.cloud.request_error", "translation": "Error processing request to CWS." }, - { - "id": "api.cloud.subscription.update_error", - "translation": "Error updating subscription from webhook." - }, { "id": "api.cloud.teams_limit_reached.create", "translation": "Unable to create team because teams limit has been reached"