[MM-29845] Add CWS Webhook endpoint and payment failed email (#16351)
* Add a new handler to allow authentication via CWS API Key * Make error better * Add tests and cases for new handler functions * Move some code around * Add test for GetCloudSession function * unset the env after test completion * Remove white space * Add CWS Webhook endpoint and email code * handle returned errors from email sending function * Change FailureCode to FailureMessage * Remove unnecessary translations * Fix translations * Forgot to add template * Update api4/cloud.go Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> * Update api4/cloud.go Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> * Update api4/cloud.go Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> * PR changes * Update app/email.go Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org> * Close body in proper spot Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org>
Этот коммит содержится в:
34
app/cloud.go
34
app/cloud.go
@@ -4,9 +4,20 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
func (a *App) getSysAdminsEmailRecipients() ([]*model.User, *model.AppError) {
|
||||
userOptions := &model.UserGetOptions{
|
||||
Page: 0,
|
||||
PerPage: 100,
|
||||
Role: model.SYSTEM_ADMIN_ROLE_ID,
|
||||
Inactive: false,
|
||||
}
|
||||
return a.GetUsers(userOptions)
|
||||
}
|
||||
|
||||
func (a *App) CheckAndSendUserLimitWarningEmails() *model.AppError {
|
||||
if a.Srv().License() == nil || (a.Srv().License() != nil && !*a.Srv().License().Features.Cloud) {
|
||||
// Not cloud instance, do nothing
|
||||
@@ -30,13 +41,7 @@ func (a *App) CheckAndSendUserLimitWarningEmails() *model.AppError {
|
||||
if remainingUsers > 0 {
|
||||
return nil
|
||||
}
|
||||
userOptions := &model.UserGetOptions{
|
||||
Page: 0,
|
||||
PerPage: 100,
|
||||
Role: model.SYSTEM_ADMIN_ROLE_ID,
|
||||
Inactive: false,
|
||||
}
|
||||
sysAdmins, err := a.GetUsers(userOptions)
|
||||
sysAdmins, err := a.getSysAdminsEmailRecipients()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -55,3 +60,18 @@ func (a *App) CheckAndSendUserLimitWarningEmails() *model.AppError {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) SendPaymentFailedEmail(failedPayment *model.FailedPayment) *model.AppError {
|
||||
sysAdmins, err := a.getSysAdminsEmailRecipients()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, admin := range sysAdmins {
|
||||
_, err := a.Srv().EmailService.SendPaymentFailedEmail(admin.Email, admin.Locale, failedPayment, *a.Config().ServiceSettings.SiteURL)
|
||||
if err != nil {
|
||||
a.Log().Error("Error sending payment failed email", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user