Add check for subscription change to product with sku cloud-starter.
Этот коммит содержится в:
@@ -7,6 +7,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"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) {
|
func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
userId := c.AppContext.Session().UserId
|
||||||
|
|
||||||
if !c.App.Channels().License().IsCloud() {
|
if !c.App.Channels().License().IsCloud() {
|
||||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.license_error", nil, "", http.StatusInternalServerError)
|
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.license_error", nil, "", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -118,13 +121,13 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSubscription, appErr := c.App.Cloud().GetSubscription(c.AppContext.Session().UserId)
|
currentSubscription, appErr := c.App.Cloud().GetSubscription(userId)
|
||||||
if appErr != nil {
|
if appErr != nil {
|
||||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||||
return
|
return
|
||||||
@@ -136,6 +139,17 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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
|
// 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.
|
// At this point, the upgrade is complete.
|
||||||
if appErr := c.App.SendUpgradeConfirmationEmail(); appErr != nil {
|
if appErr := c.App.SendUpgradeConfirmationEmail(); appErr != nil {
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ const (
|
|||||||
SubscriptionFamilyOnPrem = SubscriptionFamily("on-prem")
|
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.
|
// Product model represents a product on the cloud system.
|
||||||
type Product struct {
|
type Product struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user