MM-18818 Prompt admins to set the Support Email (#17296)
* MM-18818 Set default support to empty and handled the same in email templates * #MM-18818 Admin advisor now warns for inconfigured support email address * Updated text * #MM-18818 gofmt'ed files * #MM-18818 updated text and removed unused i18n strings: * #MM-18818 updated i18n string ordering * #MM-18818 Added test for support email advisory * MM-18818 gofmt'd the file * MM-18818 separated contextual notifications from configuration notifications in Admin Advisor * #MM-18818 prevented support email with whitepsaces from being detected as filled Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
dc7a425e77
Коммит
79dd9b13dc
15
app/app.go
15
app/app.go
@@ -94,6 +94,7 @@ func (a *App) InitServer() {
|
||||
if a.Srv().runEssentialJobs {
|
||||
a.Srv().Go(func() {
|
||||
runLicenseExpirationCheckJob(a)
|
||||
runCheckAdminSupportStatusJob(a)
|
||||
})
|
||||
a.srv.runJobs()
|
||||
}
|
||||
@@ -326,6 +327,9 @@ func (a *App) getWarnMetricStatusAndDisplayTextsForId(warnMetricId string, T i18
|
||||
warnMetricDisplayTexts.EmailBody = T("api.server.warn_metric.number_of_posts_2M.contact_us.email_body")
|
||||
warnMetricDisplayTexts.BotMessageBody = T("api.server.warn_metric.number_of_posts_2M.notification_body")
|
||||
}
|
||||
case model.SYSTEM_METRIC_SUPPORT_EMAIL_NOT_CONFIGURED:
|
||||
warnMetricDisplayTexts.BotTitle = T("api.server.warn_metric.support_email_not_configured.notification_title")
|
||||
warnMetricDisplayTexts.BotMessageBody = T("api.server.warn_metric.support_email_not_configured.start_trial.notification_body")
|
||||
default:
|
||||
mlog.Debug("Invalid metric id", mlog.String("id", warnMetricId))
|
||||
return nil, nil
|
||||
@@ -378,6 +382,11 @@ func (a *App) notifyAdminsOfWarnMetricStatus(warnMetricId string, isE0Edition bo
|
||||
return err
|
||||
}
|
||||
|
||||
warnMetric, ok := model.WarnMetricsTable[warnMetricId]
|
||||
if !ok {
|
||||
return model.NewAppError("NotifyAdminsOfWarnMetricStatus", "app.system.warn_metric.notification.invalid_metric.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, sysAdmin := range sysAdmins {
|
||||
T := i18n.GetUserTranslations(sysAdmin.Locale)
|
||||
bot.DisplayName = T("app.system.warn_metric.bot_displayname")
|
||||
@@ -442,8 +451,12 @@ func (a *App) notifyAdminsOfWarnMetricStatus(warnMetricId string, isE0Edition bo
|
||||
AuthorName: "",
|
||||
Title: warnMetricDisplayTexts.BotTitle,
|
||||
Text: warnMetricDisplayTexts.BotMessageBody,
|
||||
Actions: actions,
|
||||
}}
|
||||
|
||||
if !warnMetric.SkipAction {
|
||||
attachments[0].Actions = actions
|
||||
}
|
||||
|
||||
model.ParseSlackAttachment(botPost, attachments)
|
||||
|
||||
mlog.Debug("Post admin advisory for metric", mlog.String("warnMetricId", warnMetricId), mlog.String("userid", botPost.UserId))
|
||||
|
||||
@@ -1422,6 +1422,13 @@ func runCheckWarnMetricStatusJob(a *App) {
|
||||
}, time.Hour*model.WARN_METRIC_JOB_INTERVAL)
|
||||
}
|
||||
|
||||
func runCheckAdminSupportStatusJob(a *App) {
|
||||
doCheckAdminSupportStatus(a)
|
||||
model.CreateRecurringTask("Check Admin Support Status Job", func() {
|
||||
doCheckAdminSupportStatus(a)
|
||||
}, time.Hour*model.WARN_METRIC_JOB_INTERVAL)
|
||||
}
|
||||
|
||||
func doSecurity(s *Server) {
|
||||
s.DoSecurityUpdateCheck()
|
||||
}
|
||||
@@ -1586,6 +1593,16 @@ func doCheckWarnMetricStatus(a *App) {
|
||||
}
|
||||
}
|
||||
|
||||
func doCheckAdminSupportStatus(a *App) {
|
||||
isE0Edition := model.BuildEnterpriseReady == "true"
|
||||
|
||||
if strings.TrimSpace(*a.Config().SupportSettings.SupportEmail) == model.SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL {
|
||||
if err := a.notifyAdminsOfWarnMetricStatus(model.SYSTEM_METRIC_SUPPORT_EMAIL_NOT_CONFIGURED, isE0Edition); err != nil {
|
||||
mlog.Error("Failed to send notifications to admin users.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) StopMetricsServer() {
|
||||
s.metricsLock.Lock()
|
||||
defer s.metricsLock.Unlock()
|
||||
|
||||
@@ -695,3 +695,61 @@ func TestSentry(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestAdminAdvisor(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
// creating a system user to whole admin advisor will send post
|
||||
user := model.User{
|
||||
Email: strings.ToLower(model.NewId()) + "success+test@example.com",
|
||||
Nickname: "Darth Vader",
|
||||
Username: "vader" + model.NewId(),
|
||||
Password: "passwd1",
|
||||
AuthService: "",
|
||||
Roles: model.SYSTEM_ADMIN_ROLE_ID,
|
||||
}
|
||||
ruser, err := th.App.CreateUser(&user)
|
||||
assert.Nil(t, err, "User should be created")
|
||||
defer th.App.PermanentDeleteUser(&user)
|
||||
|
||||
t.Run("Should notify admin of un-configured support email", func(t *testing.T) {
|
||||
doCheckAdminSupportStatus(th.App)
|
||||
|
||||
bot, err := th.App.GetUserByUsername(model.BOT_WARN_METRIC_BOT_USERNAME)
|
||||
assert.NotNil(t, bot, "Bot should have been created now")
|
||||
assert.Nil(t, err, "No error should be generated")
|
||||
|
||||
channel, err := th.App.getDirectChannel(bot.Id, ruser.Id)
|
||||
assert.NotNil(t, channel, "DM channel should exist between Admin Advisor and system admin")
|
||||
assert.Nil(t, err, "No error should be generated")
|
||||
})
|
||||
|
||||
t.Run("Should NOT notify admin when support email is configured", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(m *model.Config) {
|
||||
email := "success+test@example.com"
|
||||
m.SupportSettings.SupportEmail = &email
|
||||
})
|
||||
|
||||
bot, err := th.App.GetUserByUsername(model.BOT_WARN_METRIC_BOT_USERNAME)
|
||||
assert.NotNil(t, bot, "Bot should be already created")
|
||||
assert.Nil(t, err, "No error should be generated")
|
||||
|
||||
channel, err := th.App.getDirectChannel(bot.Id, ruser.Id)
|
||||
assert.NotNil(t, channel, "DM channel should already exist")
|
||||
assert.Nil(t, err, "No error should be generated")
|
||||
|
||||
err = th.App.PermanentDeleteChannel(channel)
|
||||
assert.Nil(t, err, "No error should be generated")
|
||||
|
||||
doCheckAdminSupportStatus(th.App)
|
||||
|
||||
channel, err = th.App.getDirectChannel(bot.Id, ruser.Id)
|
||||
assert.NotNil(t, channel, "DM channel should exist between Admin Advisor and system admin")
|
||||
assert.Nil(t, err, "No error should be generated")
|
||||
|
||||
posts, err := th.App.GetPosts(channel.Id, 0, 100)
|
||||
assert.Nil(t, err, "No error should be generated")
|
||||
assert.Equal(t, 0, len(posts.Posts))
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user