[MM-28363] User Limit Overage Warning Emails (#16053)
* Adding files, commit of UI in good shape * Translations added, working with activation and deactivation * Add check for error * Fix i18n? * Push without subscription check so Steve and Matt can look at it * Fix font-weight in chrome * Fix font-weight on button * UX fixes * Fixes for PR * Add back subscription stuff * Fix tests Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -388,6 +388,7 @@ type AppIface interface {
|
||||
CancelJob(jobId string) *model.AppError
|
||||
ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError)
|
||||
ChannelMembersToRemove(teamID *string) ([]*model.ChannelMember, *model.AppError)
|
||||
CheckAndSendUserLimitWarningEmails() *model.AppError
|
||||
CheckForClientSideCert(r *http.Request) (string, string, string)
|
||||
CheckPasswordAndAllCriteria(user *model.User, password string, mfaToken string) *model.AppError
|
||||
CheckRolesExist(roleNames []string) *model.AppError
|
||||
|
||||
57
app/cloud.go
Обычный файл
57
app/cloud.go
Обычный файл
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
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
|
||||
return nil
|
||||
}
|
||||
|
||||
subscription, subErr := a.Cloud().GetSubscription()
|
||||
if subErr != nil {
|
||||
return subErr
|
||||
}
|
||||
|
||||
if subscription != nil && subscription.IsPaidTier == "true" {
|
||||
// Paid subscription, do nothing
|
||||
return nil
|
||||
}
|
||||
|
||||
cloudUserLimit := *a.Config().ExperimentalSettings.CloudUserLimit
|
||||
systemUserCount, _ := a.Srv().Store.User().Count(model.UserCountOptions{})
|
||||
remainingUsers := cloudUserLimit - systemUserCount
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// -1 means they are 1 user over the limit - we only want to send the email for the 11th user
|
||||
if remainingUsers == -1 {
|
||||
// Over limit by 1 user
|
||||
for admin := range sysAdmins {
|
||||
a.Srv().EmailService.SendOverUserLimitWarningEmail(sysAdmins[admin].Email, sysAdmins[admin].Locale, *a.Config().ServiceSettings.SiteURL)
|
||||
}
|
||||
} else if remainingUsers == 0 {
|
||||
// At limit
|
||||
for admin := range sysAdmins {
|
||||
a.Srv().EmailService.SendAtUserLimitWarningEmail(sysAdmins[admin].Email, sysAdmins[admin].Locale, *a.Config().ServiceSettings.SiteURL)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
44
app/email.go
44
app/email.go
@@ -589,3 +589,47 @@ func (es *EmailService) CreateVerifyEmailToken(userId string, newEmail string) (
|
||||
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (es *EmailService) SendAtUserLimitWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
subject := T("api.templates.at_limit_subject")
|
||||
|
||||
bodyPage := es.newEmailTemplate("reached_user_limit_body", locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = T("api.templates.at_limit_title")
|
||||
bodyPage.Props["Info1"] = T("api.templates.at_limit_info1")
|
||||
bodyPage.Props["Info2"] = T("api.templates.at_limit_info2")
|
||||
bodyPage.Props["Button"] = T("api.templates.upgrade_mattermost_cloud")
|
||||
bodyPage.Props["EmailUs"] = T("api.templates.email_us_anytime_at")
|
||||
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendAtUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (es *EmailService) SendOverUserLimitWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
subject := T("api.templates.over_limit_subject")
|
||||
|
||||
bodyPage := es.newEmailTemplate("reached_user_limit_body", locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = T("api.templates.over_limit_title")
|
||||
bodyPage.Props["Info1"] = T("api.templates.over_limit_info1")
|
||||
bodyPage.Props["Info2"] = T("api.templates.over_limit_info2")
|
||||
bodyPage.Props["Button"] = T("api.templates.upgrade_mattermost_cloud")
|
||||
bodyPage.Props["EmailUs"] = T("api.templates.email_us_anytime_at")
|
||||
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -1010,6 +1010,28 @@ func (a *OpenTracingAppLayer) ChannelMembersToRemove(teamID *string) ([]*model.C
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CheckAndSendUserLimitWarningEmails() *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CheckAndSendUserLimitWarningEmails")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.CheckAndSendUserLimitWarningEmails()
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CheckForClientSideCert(r *http.Request) (string, string, string) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CheckForClientSideCert")
|
||||
|
||||
Ссылка в новой задаче
Block a user