Merge pull request #21801 from mattermost/MM-48125-downgrade-to-starter-email-says-upgrade-with-billing-start-date

- Ensure upgrade emails are not sent out when downgrading to the starter/free plan by checking if the new subscription's product SKU is cloud-starter.
Этот коммит содержится в:
Conor Macpherson
2022-12-07 10:53:18 -05:00
коммит произвёл GitHub
родитель 3872f24b0c cdc8476032
Коммит 91ee9ed2eb
2 изменённых файлов: 23 добавлений и 2 удалений

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

@@ -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

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

@@ -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"`