diff --git a/api4/cloud.go b/api4/cloud.go index 208fa4b6b1..02fab0752a 100644 --- a/api4/cloud.go +++ b/api4/cloud.go @@ -96,6 +96,8 @@ func getSubscription(c *Context, w http.ResponseWriter, r *http.Request) { } func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) { + userId := c.AppContext.Session().UserId + if !c.App.Channels().License().IsCloud() { c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.license_error", nil, "", http.StatusInternalServerError) return @@ -118,13 +120,13 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) { return } - currentSubscription, appErr := c.App.Cloud().GetSubscription(c.AppContext.Session().UserId) + currentSubscription, appErr := c.App.Cloud().GetSubscription(userId) if appErr != nil { c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr) return } - changedSub, err := c.App.Cloud().ChangeSubscription(c.AppContext.Session().UserId, currentSubscription.ID, subscriptionChange) + changedSub, err := c.App.Cloud().ChangeSubscription(userId, currentSubscription.ID, subscriptionChange) if err != nil { c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err) return @@ -141,6 +143,11 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) { c.Logger.Error("Error finding the new cloud product", mlog.Err(err)) } + if product.SKU == string(model.SkuCloudStarter) { + w.Write(json) + return + } + isYearly := product.IsYearly() // Log failures for purchase confirmation email, but don't show an error to the user so as not to confuse them diff --git a/model/cloud.go b/model/cloud.go index a409c77f98..6e66015a87 100644 --- a/model/cloud.go +++ b/model/cloud.go @@ -42,6 +42,20 @@ const ( SubscriptionFamilyOnPrem = SubscriptionFamily("on-prem") ) +type ProductSku string + +const ( + SkuStarterGov = ProductSku("starter-gov") + SkuProfessionalGov = ProductSku("professional-gov") + SkuEnterpriseGov = ProductSku("enterprise-gov") + SkuStarter = ProductSku("starter") + SkuProfessional = ProductSku("professional") + SkuEnterprise = ProductSku("enterprise") + SkuCloudStarter = ProductSku("cloud-starter") + SkuCloudProfessional = ProductSku("cloud-professional") + SkuCloudEnterprise = ProductSku("cloud-enterprise") +) + // Product model represents a product on the cloud system. type Product struct { ID string `json:"id"`