[MM-50534] - Renew email adds portal link when not eligible for self-serve renewal (#22350)

* [MM-50534] - Renew email adds portal link when not eligible for self-serve renewal

* fix translations

* make more checks

* improve endpoint to make checks

* use new checks

* fix translations

* fix lint

* add meaningful names

* rename struct

* rename endpoint
Этот коммит содержится в:
Allan Guwatudde
2023-03-03 18:33:18 +03:00
коммит произвёл GitHub
родитель 9c7aab24f5
Коммит 1f5a6e439e
12 изменённых файлов: 91 добавлений и 69 удалений

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

@@ -989,7 +989,7 @@ func (es *Service) SendLicenseInactivityEmail(email, name, locale, siteURL strin
return nil
}
func (es *Service) SendLicenseUpForRenewalEmail(email, name, locale, siteURL, renewalLink string, daysToExpiration int) error {
func (es *Service) SendLicenseUpForRenewalEmail(email, name, locale, siteURL, ctaTitle, ctaLink, ctaText string, daysToExpiration int) error {
T := i18n.GetUserTranslations(locale)
subject := T("api.templates.license_up_for_renewal_subject")
@@ -997,10 +997,10 @@ func (es *Service) SendLicenseUpForRenewalEmail(email, name, locale, siteURL, re
data.Props["SiteURL"] = siteURL
data.Props["Title"] = T("api.templates.license_up_for_renewal_title")
data.Props["SubTitle"] = T("api.templates.license_up_for_renewal_subtitle", map[string]any{"UserName": name, "Days": daysToExpiration})
data.Props["SubTitleTwo"] = T("api.templates.license_up_for_renewal_subtitle_two")
data.Props["SubTitleTwo"] = ctaTitle
data.Props["EmailUs"] = T("api.templates.email_us_anytime_at")
data.Props["Button"] = T("api.templates.license_up_for_renewal_renew_now")
data.Props["ButtonURL"] = renewalLink
data.Props["Button"] = ctaText
data.Props["ButtonURL"] = ctaLink
data.Props["QuestionTitle"] = T("api.templates.questions_footer.title")
data.Props["SupportEmail"] = "feedback@mattermost.com"
data.Props["QuestionInfo"] = T("api.templates.questions_footer.info")
@@ -1298,7 +1298,7 @@ func (es *Service) SendDelinquencyEmail90(email, locale, siteURL string) error {
// SendRemoveExpiredLicenseEmail formats an email and uses the email service to send the email to user with link pointing to CWS
// to renew the user license
func (es *Service) SendRemoveExpiredLicenseEmail(renewalLink, email string, locale, siteURL string) error {
func (es *Service) SendRemoveExpiredLicenseEmail(ctaText, ctaLink, email, locale, siteURL string) error {
T := i18n.GetUserTranslations(locale)
subject := T("api.templates.remove_expired_license.subject",
map[string]any{"SiteName": es.config().TeamSettings.SiteName})
@@ -1306,8 +1306,8 @@ func (es *Service) SendRemoveExpiredLicenseEmail(renewalLink, email string, loca
data := es.NewEmailTemplateData(locale)
data.Props["SiteURL"] = siteURL
data.Props["Title"] = T("api.templates.remove_expired_license.body.title")
data.Props["Link"] = renewalLink
data.Props["LinkButton"] = T("api.templates.remove_expired_license.body.renew_button")
data.Props["Link"] = ctaLink
data.Props["LinkButton"] = ctaText
body, err := es.templatesContainer.RenderToString("remove_expired_license", data)
if err != nil {

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

@@ -358,13 +358,13 @@ func (_m *ServiceInterface) SendLicenseInactivityEmail(_a0 string, name string,
return r0
}
// SendLicenseUpForRenewalEmail provides a mock function with given fields: _a0, name, locale, siteURL, renewalLink, daysToExpiration
func (_m *ServiceInterface) SendLicenseUpForRenewalEmail(_a0 string, name string, locale string, siteURL string, renewalLink string, daysToExpiration int) error {
ret := _m.Called(_a0, name, locale, siteURL, renewalLink, daysToExpiration)
// SendLicenseUpForRenewalEmail provides a mock function with given fields: _a0, name, locale, siteURL, ctaTitle, ctaLink, ctaText, daysToExpiration
func (_m *ServiceInterface) SendLicenseUpForRenewalEmail(_a0 string, name string, locale string, siteURL string, ctaTitle string, ctaLink string, ctaText string, daysToExpiration int) error {
ret := _m.Called(_a0, name, locale, siteURL, ctaTitle, ctaLink, ctaText, daysToExpiration)
var r0 error
if rf, ok := ret.Get(0).(func(string, string, string, string, string, int) error); ok {
r0 = rf(_a0, name, locale, siteURL, renewalLink, daysToExpiration)
if rf, ok := ret.Get(0).(func(string, string, string, string, string, string, string, int) error); ok {
r0 = rf(_a0, name, locale, siteURL, ctaTitle, ctaLink, ctaText, daysToExpiration)
} else {
r0 = ret.Error(0)
}
@@ -484,13 +484,13 @@ func (_m *ServiceInterface) SendPaymentFailedEmail(_a0 string, locale string, fa
return r0, r1
}
// SendRemoveExpiredLicenseEmail provides a mock function with given fields: renewalLink, _a1, locale, siteURL
func (_m *ServiceInterface) SendRemoveExpiredLicenseEmail(renewalLink string, _a1 string, locale string, siteURL string) error {
ret := _m.Called(renewalLink, _a1, locale, siteURL)
// SendRemoveExpiredLicenseEmail provides a mock function with given fields: ctaText, ctaLink, _a2, locale, siteURL
func (_m *ServiceInterface) SendRemoveExpiredLicenseEmail(ctaText string, ctaLink string, _a2 string, locale string, siteURL string) error {
ret := _m.Called(ctaText, ctaLink, _a2, locale, siteURL)
var r0 error
if rf, ok := ret.Get(0).(func(string, string, string, string) error); ok {
r0 = rf(renewalLink, _a1, locale, siteURL)
if rf, ok := ret.Get(0).(func(string, string, string, string, string) error); ok {
r0 = rf(ctaText, ctaLink, _a2, locale, siteURL)
} else {
r0 = ret.Error(0)
}

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

@@ -141,7 +141,7 @@ type ServiceInterface interface {
SendDeactivateAccountEmail(email string, locale, siteURL string) error
SendNotificationMail(to, subject, htmlBody string) error
SendMailWithEmbeddedFiles(to, subject, htmlBody string, embeddedFiles map[string]io.Reader, messageID string, inReplyTo string, references string, category string) error
SendLicenseUpForRenewalEmail(email, name, locale, siteURL, renewalLink string, daysToExpiration int) error
SendLicenseUpForRenewalEmail(email, name, locale, siteURL, ctaTitle, ctaLink, ctaText string, daysToExpiration int) error
SendPaymentFailedEmail(email string, locale string, failedPayment *model.FailedPayment, planName, siteURL string) (bool, error)
// Cloud delinquency email sequence
SendDelinquencyEmail7(email, locale, siteURL, planName string) error
@@ -152,7 +152,7 @@ type ServiceInterface interface {
SendDelinquencyEmail75(email, locale, siteURL, planName, delinquencyDate string) error
SendDelinquencyEmail90(email, locale, siteURL string) error
SendNoCardPaymentFailedEmail(email string, locale string, siteURL string) error
SendRemoveExpiredLicenseEmail(renewalLink, email string, locale, siteURL string) error
SendRemoveExpiredLicenseEmail(ctaText, ctaLink, email, locale, siteURL string) error
AddNotificationEmailToBatch(user *model.User, post *model.Post, team *model.Team) *model.AppError
GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFunc) string
InitEmailBatching()

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

@@ -1288,11 +1288,16 @@ func (s *Server) sendLicenseUpForRenewalEmail(users map[string]*model.User, lice
daysToExpiration := license.DaysToExpiration()
renewalLink, _, appErr := s.GenerateLicenseRenewalLink()
ctaLink, tokenToBeUsedForRenew, appErr := s.GenerateLicenseRenewalLink()
if appErr != nil {
return model.NewAppError("s.sendLicenseUpForRenewalEmail", "api.server.license_up_for_renewal.error_generating_link", nil, "", http.StatusInternalServerError).Wrap(appErr)
}
status, err := s.Cloud.GetLicenseSelfServeStatus("", tokenToBeUsedForRenew)
if err != nil {
return model.NewAppError("s.sendLicenseUpForRenewalEmail", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
// we want to at least have one email sent out to an admin
countNotOks := 0
@@ -1301,7 +1306,16 @@ func (s *Server) sendLicenseUpForRenewalEmail(users map[string]*model.User, lice
if name == "" {
name = user.Username
}
if err := s.EmailService.SendLicenseUpForRenewalEmail(user.Email, name, user.Locale, *s.platform.Config().ServiceSettings.SiteURL, renewalLink, daysToExpiration); err != nil {
T := i18n.GetUserTranslations(user.Locale)
ctaTitle := T("api.templates.license_up_for_renewal_subtitle_two")
ctaText := T("api.templates.license_up_for_renewal_renew_now")
if !status.IsRenewable {
ctaTitle = ""
ctaText = T("api.templates.license_up_for_renewal_contact_sales")
ctaLink = "https://mattermost.com/contact-sales/"
}
if err := s.EmailService.SendLicenseUpForRenewalEmail(user.Email, name, user.Locale, *s.platform.Config().ServiceSettings.SiteURL, ctaTitle, ctaLink, ctaText, daysToExpiration); err != nil {
mlog.Error("Error sending license up for renewal email to", mlog.String("user_email", user.Email), mlog.Err(err))
countNotOks++
}
@@ -1366,9 +1380,15 @@ func (s *Server) doLicenseExpirationCheck() {
return
}
renewalLink, _, appErr := s.GenerateLicenseRenewalLink()
ctaLink, tokenToBeUsedForRenew, appErr := s.GenerateLicenseRenewalLink()
if appErr != nil {
mlog.Error("Error while sending the license expired email.", mlog.Err(appErr))
mlog.Debug(model.NewAppError("s.sendLicenseUpForRenewalEmail", "api.server.license_up_for_renewal.error_generating_link", nil, "", http.StatusInternalServerError).Wrap(appErr).Error())
return
}
status, err := s.Cloud.GetLicenseSelfServeStatus("", tokenToBeUsedForRenew)
if err != nil {
mlog.Debug(model.NewAppError("s.sendLicenseUpForRenewalEmail", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(err).Error())
return
}
@@ -1380,9 +1400,16 @@ func (s *Server) doLicenseExpirationCheck() {
continue
}
T := i18n.GetUserTranslations(user.Locale)
ctaText := T("api.templates.remove_expired_license.body.renew_button")
if !status.IsRenewable {
ctaText = T("api.templates.license_up_for_renewal_contact_sales")
ctaLink = "https://mattermost.com/contact-sales/"
}
mlog.Debug("Sending license expired email.", mlog.String("user_email", user.Email))
s.Go(func() {
if err := s.SendRemoveExpiredLicenseEmail(user.Email, renewalLink, user.Locale, *s.platform.Config().ServiceSettings.SiteURL); err != nil {
if err := s.SendRemoveExpiredLicenseEmail(user.Email, ctaText, ctaLink, user.Locale, *s.platform.Config().ServiceSettings.SiteURL); err != nil {
mlog.Error("Error while sending the license expired email.", mlog.String("user_email", user.Email), mlog.Err(err))
}
})
@@ -1394,9 +1421,9 @@ func (s *Server) doLicenseExpirationCheck() {
// SendRemoveExpiredLicenseEmail formats an email and uses the email service to send the email to user with link pointing to CWS
// to renew the user license
func (s *Server) SendRemoveExpiredLicenseEmail(email string, renewalLink, locale, siteURL string) *model.AppError {
func (s *Server) SendRemoveExpiredLicenseEmail(email, ctaText, ctaLink, locale, siteURL string) *model.AppError {
if err := s.EmailService.SendRemoveExpiredLicenseEmail(renewalLink, email, locale, siteURL); err != nil {
if err := s.EmailService.SendRemoveExpiredLicenseEmail(ctaText, ctaLink, email, locale, siteURL); err != nil {
return model.NewAppError("SendRemoveExpiredLicenseEmail", "api.license.remove_expired_license.failed.error", nil, "", http.StatusInternalServerError).Wrap(err)
}