[MM-40962-2] - Fix unnecessary logging in license expiration check (#19826)

* [MM-40962-2] - Fix unnecessary logging in license expiration check

* skip check for TE

* document

* feedback impl-1

* fix logic

* remove saving of renewal token

* fix lint

* remove commented code

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Allan Guwatudde
2022-03-31 18:25:46 +03:00
коммит произвёл GitHub
родитель fa56ee9d9a
Коммит c17e210dd0
4 изменённых файлов: 20 добавлений и 103 удалений

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

@@ -1721,6 +1721,15 @@ func (s *Server) sendLicenseUpForRenewalEmail(users map[string]*model.User, lice
func (s *Server) doLicenseExpirationCheck() {
s.LoadLicense()
// This takes care of a rare edge case reported here https://mattermost.atlassian.net/browse/MM-40962
// To reproduce that case locally, attach a license to a server that was started with enterprise enabled
// Then restart using BUILD_ENTERPRISE=false make restart-server to enter Team Edition
if model.BuildEnterpriseReady != "true" {
mlog.Debug("Skipping license expiration check because no license is expected on Team Edition")
return
}
license := s.License()
if license == nil {
@@ -1744,6 +1753,7 @@ func (s *Server) doLicenseExpirationCheck() {
if appErr != nil {
mlog.Debug(appErr.Error())
}
return
}
if !license.IsPastGracePeriod() {
@@ -1751,6 +1761,12 @@ func (s *Server) doLicenseExpirationCheck() {
return
}
renewalLink, _, appErr := s.GenerateLicenseRenewalLink()
if appErr != nil {
mlog.Error("Error while sending the license expired email.", mlog.Err(appErr))
return
}
//send email to admin(s)
for _, user := range users {
user := user
@@ -1761,7 +1777,7 @@ func (s *Server) doLicenseExpirationCheck() {
mlog.Debug("Sending license expired email.", mlog.String("user_email", user.Email))
s.Go(func() {
if err := s.SendRemoveExpiredLicenseEmail(user.Email, user.Locale, *s.Config().ServiceSettings.SiteURL); err != nil {
if err := s.SendRemoveExpiredLicenseEmail(user.Email, renewalLink, user.Locale, *s.Config().ServiceSettings.SiteURL); err != nil {
mlog.Error("Error while sending the license expired email.", mlog.String("user_email", user.Email), mlog.Err(err))
}
})
@@ -1773,11 +1789,7 @@ 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, locale, siteURL string) *model.AppError {
renewalLink, _, err := s.GenerateLicenseRenewalLink()
if err != nil {
return err
}
func (s *Server) SendRemoveExpiredLicenseEmail(email string, renewalLink, locale, siteURL string) *model.AppError {
if err := s.EmailService.SendRemoveExpiredLicenseEmail(renewalLink, email, locale, siteURL); err != nil {
return model.NewAppError("SendRemoveExpiredLicenseEmail", "api.license.remove_expired_license.failed.error", nil, err.Error(), http.StatusInternalServerError)