[MM-36457] - Send email when license is up for renewal (#17816)
* [MM-36457] - Send email when license is up for renewal * i18n-extract * feedback impl * feedback impl * fix translations * Change license key to test for testing purposes * Revert license key * Trying test license key once more * revert license change Co-authored-by: marianunez <maria.nunez@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e1f8c62ac8
Коммит
98d170894d
@@ -1781,6 +1781,52 @@ func (s *Server) startMetricsServer() {
|
||||
s.Log.Info("Metrics and profiling server is started", mlog.String("address", l.Addr().String()))
|
||||
}
|
||||
|
||||
func (s *Server) sendLicenseUpForRenewalEmail(users map[string]*model.User, license *model.License) *model.AppError {
|
||||
key := model.LICENSE_UP_FOR_RENEWAL_EMAIL_SENT + license.Id
|
||||
if _, err := s.Store.System().GetByName(key); err == nil {
|
||||
// return early because the key already exists and that means we already executed the code below to send email successfully
|
||||
return nil
|
||||
}
|
||||
|
||||
daysToExpiration := license.DaysToExpiration()
|
||||
|
||||
renewalLink, appErr := s.GenerateLicenseRenewalLink()
|
||||
if appErr != nil {
|
||||
return model.NewAppError("s.sendLicenseUpForRenewalEmail", "api.server.license_up_for_renewal.error_generating_link", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// we want to at least have one email sent out to an admin
|
||||
countNotOks := 0
|
||||
|
||||
for _, user := range users {
|
||||
name := user.FirstName
|
||||
if name == "" {
|
||||
name = user.Username
|
||||
}
|
||||
ok, err := s.EmailService.SendLicenseUpForRenewalEmail(user.Email, name, user.Locale, *s.Config().ServiceSettings.SiteURL, renewalLink, daysToExpiration)
|
||||
if !ok || err != nil {
|
||||
mlog.Error("Error sending license up for renewal email to", mlog.String("user_email", user.Email))
|
||||
countNotOks++
|
||||
}
|
||||
}
|
||||
|
||||
// if not even one admin got an email, we consider that this operation errored
|
||||
if countNotOks == len(users) {
|
||||
return model.NewAppError("s.sendLicenseUpForRenewalEmail", "api.server.license_up_for_renewal.error_sending_email", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
system := model.System{
|
||||
Name: key,
|
||||
Value: "true",
|
||||
}
|
||||
|
||||
if err := s.Store.System().Save(&system); err != nil {
|
||||
mlog.Debug("Failed to mark license up for renewal email sending as completed.", mlog.Err(err))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) doLicenseExpirationCheck() {
|
||||
s.LoadLicense()
|
||||
license := s.License()
|
||||
@@ -1790,17 +1836,24 @@ func (s *Server) doLicenseExpirationCheck() {
|
||||
return
|
||||
}
|
||||
|
||||
if !license.IsPastGracePeriod() {
|
||||
mlog.Debug("License is not past the grace period.")
|
||||
return
|
||||
}
|
||||
|
||||
users, err := s.Store.User().GetSystemAdminProfiles()
|
||||
if err != nil {
|
||||
mlog.Error("Failed to get system admins for license expired message from Mattermost.")
|
||||
return
|
||||
}
|
||||
|
||||
if license.IsWithinExpirationPeriod() {
|
||||
appErr := s.sendLicenseUpForRenewalEmail(users, license)
|
||||
if appErr != nil {
|
||||
mlog.Debug(appErr.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if !license.IsPastGracePeriod() {
|
||||
mlog.Debug("License is not past the grace period.")
|
||||
return
|
||||
}
|
||||
|
||||
//send email to admin(s)
|
||||
for _, user := range users {
|
||||
user := user
|
||||
|
||||
Ссылка в новой задаче
Block a user