[MM-29999] User Limit Email Notifications (Part 2) (#16220)

* Adding files commiting to do something else

* Stashing to merge master

* Adding files, commit of working code, pre-test

* Changing up logic according to new conversations, adding template and functions for 7 day and 14 day emails

* Add subscription active check

* Add a comment around subscription status

* Fix i18n

* Update jobs/cloud/worker.go

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>

* Add a check for cloud license and exit early

* remove log

* Update jobs/cloud/worker.go

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>

* Remove case for 91st day

* Change var name

* Fix i18n

* Change value for dates in email

* Add email template and send logic for support email on 30th day of arrears

* Fix EETests?

* add one to the day so the count starts on first day of next cycle

* use the license for the enabled check

* Moved scheduler and worker into enterprise

* Add the user count to the support email

* remove a line

* Use the date for the 14 day email

* Fix for design review

* More font changes

* Fixes for PR

* Change feature flag name

* Add cloud_interface to einterfaces/jobs

* Add back & for running job server

* Remove unused constant

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Nick Misasi
2020-11-12 09:07:31 -05:00
коммит произвёл GitHub
родитель cae59d327c
Коммит 1d15900f84
18 изменённых файлов: 680 добавлений и 0 удалений

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

@@ -119,6 +119,11 @@ func (a *App) initJobs() {
if jobsActiveUsersInterface != nil {
a.srv.Jobs.ActiveUsers = jobsActiveUsersInterface(a)
}
if jobsCloudInterface != nil {
a.srv.Jobs.Cloud = jobsCloudInterface(a.srv)
}
a.srv.Jobs.Workers = a.srv.Jobs.InitWorkers()
a.srv.Jobs.Schedulers = a.srv.Jobs.InitSchedulers()
}

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

@@ -11,6 +11,7 @@ import (
"net/url"
"path"
"strings"
"time"
"net/http"
@@ -633,3 +634,135 @@ func (es *EmailService) SendOverUserLimitWarningEmail(email string, locale strin
return true, nil
}
func (es *EmailService) SendOverUserLimitThirtyDayWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.over_limit_30_days_subject")
bodyPage := es.newEmailTemplate("over_user_limit_30_days_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.over_limit_30_days_title")
bodyPage.Props["Info1"] = T("api.templates.over_limit_30_days_info1")
bodyPage.Props["Info2"] = T("api.templates.over_limit_30_days_info2")
bodyPage.Props["Info2Item1"] = T("api.templates.over_limit_30_days_info2_item1")
bodyPage.Props["Info2Item2"] = T("api.templates.over_limit_30_days_info2_item2")
bodyPage.Props["Info2Item3"] = T("api.templates.over_limit_30_days_info2_item3")
bodyPage.Props["Button"] = T("api.templates.over_limit_fix_now")
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
}
func (es *EmailService) SendOverUserLimitNinetyDayWarningEmail(email string, locale string, siteURL string, overLimitDate string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.over_limit_90_days_subject")
bodyPage := es.newEmailTemplate("over_user_limit_90_days_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.over_limit_90_days_title")
bodyPage.Props["Info1"] = T("api.templates.over_limit_90_days_info1", map[string]interface{}{"OverLimitDate": overLimitDate})
bodyPage.Props["Info2"] = T("api.templates.over_limit_90_days_info2")
bodyPage.Props["Info3"] = T("api.templates.over_limit_90_days_info3")
bodyPage.Props["Info4"] = T("api.templates.over_limit_90_days_info4")
bodyPage.Props["Button"] = T("api.templates.over_limit_fix_now")
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
}
func (es *EmailService) SendOverUserLimitWorkspaceSuspendedWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.over_limit_suspended_subject")
bodyPage := es.newEmailTemplate("over_user_limit_workspace_suspended_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.over_limit_suspended_title")
bodyPage.Props["Info1"] = T("api.templates.over_limit_suspended_info1")
bodyPage.Props["Info2"] = T("api.templates.over_limit_suspended_info2")
bodyPage.Props["Button"] = T("api.templates.over_limit_suspended_contact_support")
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
}
func (es *EmailService) SendOverUserFourteenDayWarningEmail(email string, locale string, siteURL string, overLimitDate string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.over_limit_14_days_subject")
bodyPage := es.newEmailTemplate("over_user_limit_7_days_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.over_limit_14_days_title")
bodyPage.Props["Info1"] = T("api.templates.over_limit_14_days_info1", map[string]interface{}{"OverLimitDate": overLimitDate})
bodyPage.Props["Button"] = T("api.templates.over_limit_fix_now")
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
}
func (es *EmailService) SendOverUserSevenDayWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.over_limit_7_days_subject")
bodyPage := es.newEmailTemplate("over_user_limit_7_days_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.over_limit_7_days_title")
bodyPage.Props["Info1"] = T("api.templates.over_limit_7_days_info1")
bodyPage.Props["Button"] = T("api.templates.over_limit_fix_now")
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
}
func (es *EmailService) SendSuspensionEmailToSupport(email string, installationID string, customerID string, subscriptionID string, siteURL string, userCount int64) (bool, *model.AppError) {
// Localization not needed
subject := fmt.Sprintf("Cloud Installation %s Scheduled Suspension", installationID)
bodyPage := es.newEmailTemplate("over_user_limit_support_body", "en")
bodyPage.Props["CustomerID"] = customerID
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["SubscriptionID"] = subscriptionID
bodyPage.Props["InstallationID"] = installationID
bodyPage.Props["SuspensionDate"] = time.Now().AddDate(0, 0, 61).Format("2006-01-02")
bodyPage.Props["UserCount"] = userCount
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
}

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

@@ -96,6 +96,12 @@ func RegisterJobsActiveUsersInterface(f func(*App) tjobs.ActiveUsersJobInterface
jobsActiveUsersInterface = f
}
var jobsCloudInterface func(*Server) ejobs.CloudJobInterface
func RegisterJobsCloudInterface(f func(*Server) ejobs.CloudJobInterface) {
jobsCloudInterface = f
}
var jobsExpiryNotifyInterface func(*App) tjobs.ExpiryNotifyJobInterface
func RegisterJobsExpiryNotifyJobInterface(f func(*App) tjobs.ExpiryNotifyJobInterface) {