From a7e212566d641e227ba67758f526dbb6b798142e Mon Sep 17 00:00:00 2001 From: Allan Guwatudde Date: Wed, 20 Jan 2021 19:57:29 +0300 Subject: [PATCH] [MM-31112] - Update license renewal email (#16747) * [MM-31112] - Update license renewal email * Feedback impl-1 * Update app/license.go Co-authored-by: Maria A Nunez * Feedback impl-2 Co-authored-by: Maria A Nunez --- api4/license.go | 4 +--- app/email.go | 11 +++++++++-- app/license.go | 10 ++++++++++ app/server.go | 2 +- i18n/en.json | 4 ++-- i18n/es.json | 2 +- i18n/uk.json | 4 ++-- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/api4/license.go b/api4/license.go index 1717686488..d81552acd1 100644 --- a/api4/license.go +++ b/api4/license.go @@ -11,7 +11,6 @@ import ( "io/ioutil" "net/http" - "github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/audit" "github.com/mattermost/mattermost-server/v5/model" ) @@ -229,12 +228,11 @@ func requestRenewalLink(c *Context, w http.ResponseWriter, r *http.Request) { return } - renewalToken, err := c.App.Srv().GenerateRenewalToken(app.JWTDefaultTokenExpiration) + renewalLink, err := c.App.Srv().GenerateLicenseRenewalLink() if err != nil { c.Err = err return } - renewalLink := app.LicenseRenewalURL + "?token=" + renewalToken auditRec.Success() c.LogAudit("success") diff --git a/app/email.go b/app/email.go index ec6bf16c0f..88d0de35ed 100644 --- a/app/email.go +++ b/app/email.go @@ -520,7 +520,14 @@ func (es *EmailService) SendDeactivateAccountEmail(email string, locale, siteURL return nil } -func (es *EmailService) SendRemoveExpiredLicenseEmail(email string, locale, siteURL string, licenseId string) *model.AppError { +// 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 *EmailService) SendRemoveExpiredLicenseEmail(email string, locale, siteURL string) *model.AppError { + renewalLink, err := es.srv.GenerateLicenseRenewalLink() + if err != nil { + return err + } + T := utils.GetUserTranslations(locale) subject := T("api.templates.remove_expired_license.subject", map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName}) @@ -528,7 +535,7 @@ func (es *EmailService) SendRemoveExpiredLicenseEmail(email string, locale, site bodyPage := es.newEmailTemplate("remove_expired_license", locale) bodyPage.Props["SiteURL"] = siteURL bodyPage.Props["Title"] = T("api.templates.remove_expired_license.body.title") - bodyPage.Props["Link"] = fmt.Sprintf("%s?id=%s", model.LICENSE_RENEWAL_LINK, licenseId) + bodyPage.Props["Link"] = renewalLink bodyPage.Props["LinkButton"] = T("api.templates.remove_expired_license.body.renew_button") if err := es.sendMail(email, subject, bodyPage.Render()); err != nil { diff --git a/app/license.go b/app/license.go index ed9637eb00..6719ce12cd 100644 --- a/app/license.go +++ b/app/license.go @@ -331,3 +331,13 @@ func (s *Server) renewalTokenValid(tokenString, signingKey string) (bool, error) } return true, nil } + +// GenerateLicenseRenewalLink returns a link that points to the CWS where clients can renew license +func (s *Server) GenerateLicenseRenewalLink() (string, *model.AppError) { + renewalToken, err := s.GenerateRenewalToken(JWTDefaultTokenExpiration) + if err != nil { + return "", err + } + renewalLink := LicenseRenewalURL + "?token=" + renewalToken + return renewalLink, nil +} diff --git a/app/server.go b/app/server.go index d3c8e3bd6f..df7669a2ad 100644 --- a/app/server.go +++ b/app/server.go @@ -1456,7 +1456,7 @@ func doLicenseExpirationCheck(a *App) { mlog.Debug("Sending license expired email.", mlog.String("user_email", user.Email)) a.Srv().Go(func() { - if err := a.Srv().EmailService.SendRemoveExpiredLicenseEmail(user.Email, user.Locale, *a.Config().ServiceSettings.SiteURL, license.Id); err != nil { + if err := a.Srv().EmailService.SendRemoveExpiredLicenseEmail(user.Email, user.Locale, *a.Config().ServiceSettings.SiteURL); err != nil { mlog.Error("Error while sending the license expired email.", mlog.String("user_email", user.Email), mlog.Err(err)) } }) diff --git a/i18n/en.json b/i18n/en.json index 36182284fd..1538f7aed6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -2896,11 +2896,11 @@ }, { "id": "api.templates.remove_expired_license.body.renew_button", - "translation": "Renew License" + "translation": "Renew License Now" }, { "id": "api.templates.remove_expired_license.body.title", - "translation": "Enterprise license has expired and some features may be disabled. Please renew." + "translation": "Your Enterprise Edition license has expired and some features may be disabled. Please renew your license now." }, { "id": "api.templates.remove_expired_license.subject", diff --git a/i18n/es.json b/i18n/es.json index d7b3e95efc..5f682034c6 100644 --- a/i18n/es.json +++ b/i18n/es.json @@ -5808,7 +5808,7 @@ }, { "id": "api.templates.remove_expired_license.body.renew_button", - "translation": "Renovar Licencia" + "translation": "Renovar Licencia ahora" }, { "id": "api.templates.invite_guest_subject", diff --git a/i18n/uk.json b/i18n/uk.json index eaf31efa3b..fbf847229b 100644 --- a/i18n/uk.json +++ b/i18n/uk.json @@ -5853,11 +5853,11 @@ }, { "id": "api.templates.remove_expired_license.body.title", - "translation": "Enterprise license has expired and some features may be disabled. Please renew." + "translation": "Your Enterprise Edition license has expired and some features may be disabled. Please renew your license now." }, { "id": "api.templates.remove_expired_license.body.renew_button", - "translation": "Renew License" + "translation": "Renew License Now" }, { "id": "api.templates.invite_guest_subject",