[MM-28694] Add MM User information in the CWS request headers (#15824)
* Include user data in the cloud endpoints Those headers will include the user ID and Email so we can use them in CWS * Removed AppError from enterprise/cloud We're removing the AppError from all the places that don't belong to the app or api4 packages. * Remove unused i18n strings * Move it to the server init of enterprise Also moved the initialization of the enterprise part in the server after the store is initialized * Initialize after the store is set in NewServer The ideal way to do it should be to move the initEnterprise call after the store is set but that would lead to undesired side-effects so we initialize the cloud part alone. Signed-off-by: Mario de Frutos <mario@defrutos.org>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
633d82f0ac
Коммит
5203fc8608
@@ -54,10 +54,9 @@ func getSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
subscription, appErr := c.App.Cloud().GetSubscription()
|
||||
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
subscription, err := c.App.Cloud().GetSubscription(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -76,7 +75,7 @@ func getSubscriptionStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
subscription, appErr := c.App.Cloud().GetSubscription()
|
||||
subscription, appErr := c.App.Cloud().GetSubscription("")
|
||||
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getSubscriptionStats", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
@@ -111,9 +110,9 @@ func getCloudProducts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
products, appErr := c.App.Cloud().GetCloudProducts()
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
products, err := c.App.Cloud().GetCloudProducts(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -137,9 +136,9 @@ func getCloudCustomer(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
customer, appErr := c.App.Cloud().GetCloudCustomer()
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudCustomer", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
customer, err := c.App.Cloud().GetCloudCustomer(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudCustomer", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -175,7 +174,7 @@ func updateCloudCustomer(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
customer, appErr := c.App.Cloud().UpdateCloudCustomer(customerInfo)
|
||||
customer, appErr := c.App.Cloud().UpdateCloudCustomer(c.App.Session().UserId, customerInfo)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomer", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -213,7 +212,7 @@ func updateCloudCustomerAddress(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
customer, appErr := c.App.Cloud().UpdateCloudCustomerAddress(address)
|
||||
customer, appErr := c.App.Cloud().UpdateCloudCustomerAddress(c.App.Session().UserId, address)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomerAddress", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -242,9 +241,9 @@ func createCustomerPayment(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec := c.MakeAuditRecord("createCustomerPayment", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
intent, appErr := c.App.Cloud().CreateCustomerPayment()
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
intent, err := c.App.Cloud().CreateCustomerPayment(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -285,9 +284,9 @@ func confirmCustomerPayment(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
appErr := c.App.Cloud().ConfirmCustomerPayment(confirmRequest)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
err = c.App.Cloud().ConfirmCustomerPayment(c.App.Session().UserId, confirmRequest)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -307,7 +306,7 @@ func getInvoicesForSubscription(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
invoices, appErr := c.App.Cloud().GetInvoicesForSubscription()
|
||||
invoices, appErr := c.App.Cloud().GetInvoicesForSubscription(c.App.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getInvoicesForSubscription", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -338,7 +337,7 @@ func getSubscriptionInvoicePDF(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
pdfData, filename, appErr := c.App.Cloud().GetInvoicePDF(c.Params.InvoiceId)
|
||||
pdfData, filename, appErr := c.App.Cloud().GetInvoicePDF(c.App.Session().UserId, c.Params.InvoiceId)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getSuscriptionInvoicePDF", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -398,20 +397,20 @@ func sendAdminUpgradeRequestEmail(c *Context, w http.ResponseWriter, r *http.Req
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.GetUser(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.sendAdminUpgradeRequestEmail", err.Id, nil, err.Error(), err.StatusCode)
|
||||
user, appErr := c.App.GetUser(c.App.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.sendAdminUpgradeRequestEmail", appErr.Id, nil, appErr.Error(), appErr.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
sub, err := c.App.Cloud().GetSubscription()
|
||||
sub, err := c.App.Cloud().GetSubscription(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.sendAdminUpgradeRequestEmail", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = c.App.SendAdminUpgradeRequestEmail(user.Username, sub, model.InviteLimitation); err != nil {
|
||||
c.Err = model.NewAppError("Api4.sendAdminUpgradeRequestEmail", err.Id, nil, err.Error(), err.StatusCode)
|
||||
if appErr = c.App.SendAdminUpgradeRequestEmail(user.Username, sub, model.InviteLimitation); appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.sendAdminUpgradeRequestEmail", appErr.Id, nil, appErr.Error(), appErr.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -424,14 +423,14 @@ func sendAdminUpgradeRequestEmailOnJoin(c *Context, w http.ResponseWriter, r *ht
|
||||
return
|
||||
}
|
||||
|
||||
sub, err := c.App.Cloud().GetSubscription()
|
||||
sub, err := c.App.Cloud().GetSubscription("")
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.sendAdminUpgradeRequestEmailOnJoin", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = c.App.SendAdminUpgradeRequestEmail("", sub, model.JoinLimitation); err != nil {
|
||||
c.Err = model.NewAppError("Api4.sendAdminUpgradeRequestEmail", err.Id, nil, err.Error(), err.StatusCode)
|
||||
if appErr := c.App.SendAdminUpgradeRequestEmail("", sub, model.JoinLimitation); appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.sendAdminUpgradeRequestEmail", appErr.Id, nil, appErr.Error(), appErr.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
20
api4/team.go
20
api4/team.go
@@ -1206,9 +1206,14 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cloudUserLimit := *c.App.Config().ExperimentalSettings.CloudUserLimit
|
||||
var invitesOverLimit []*model.EmailInviteWithError
|
||||
if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud && cloudUserLimit > 0 {
|
||||
subscription, subErr := c.App.Cloud().GetSubscription()
|
||||
subscription, subErr := c.App.Cloud().GetSubscription(c.App.Session().UserId)
|
||||
if subErr != nil {
|
||||
c.Err = subErr
|
||||
c.Err = model.NewAppError(
|
||||
"Api4.inviteUsersToTeam",
|
||||
"api.team.cloud.subscription.error",
|
||||
nil,
|
||||
subErr.Error(),
|
||||
http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if subscription == nil || subscription.IsPaidTier != "true" {
|
||||
@@ -1294,9 +1299,14 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
cloudUserLimit := *c.App.Config().ExperimentalSettings.CloudUserLimit
|
||||
var invitesOverLimit []*model.EmailInviteWithError
|
||||
if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud && cloudUserLimit > 0 && c.IsSystemAdmin() {
|
||||
subscription, subErr := c.App.Cloud().GetSubscription()
|
||||
if subErr != nil {
|
||||
c.Err = subErr
|
||||
subscription, err := c.App.Cloud().GetSubscription(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError(
|
||||
"Api4.inviteGuestsToChannel",
|
||||
"api.team.cloud.subscription.error",
|
||||
nil,
|
||||
err.Error(),
|
||||
http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if subscription == nil || subscription.IsPaidTier != "true" {
|
||||
|
||||
Ссылка в новой задаче
Block a user