diff --git a/api4/cloud.go b/api4/cloud.go index 173d975279..0dd56c3055 100644 --- a/api4/cloud.go +++ b/api4/cloud.go @@ -7,6 +7,7 @@ import ( "bytes" "encoding/binary" "encoding/json" + "fmt" "io" "net/http" "time" @@ -96,6 +97,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 +121,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 @@ -136,6 +139,17 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) { return } + changedProduct, err := c.App.Cloud().GetCloudProduct(userId, changedSub.ProductID) + if err != nil { + c.Err = model.NewAppError("Api4.changeSubscription", "api_cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err) + } + + starterSku := fmt.Sprintf("%s-%s", model.SubscriptionFamilyCloud, model.ProductSkuStarter) + if changedProduct.SKU != starterSku { + w.Write(json) + return + } + // Log failures for purchase confirmation email, but don't show an error to the user so as not to confuse them // At this point, the upgrade is complete. if appErr := c.App.SendUpgradeConfirmationEmail(); appErr != nil { diff --git a/model/cloud.go b/model/cloud.go index 2985c929ea..d4e7d614e0 100644 --- a/model/cloud.go +++ b/model/cloud.go @@ -40,6 +40,14 @@ const ( SubscriptionFamilyOnPrem = SubscriptionFamily("on-prem") ) +type ProductSku string + +const ( + ProductSkuStarter = ProductSku("starter") + ProductSkuProfessional = ProductSku("professional") + ProductSkuEnterprise = ProductSku("enterprise") +) + // Product model represents a product on the cloud system. type Product struct { ID string `json:"id"`