Making private some methods that are not needed publicly (#13959)

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Jesús Espino
2020-03-03 22:43:48 +01:00
коммит произвёл GitHub
родитель ccc57e56c3
Коммит c9a0418a32
19 изменённых файлов: 182 добавлений и 224 удалений

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

@@ -59,28 +59,28 @@ func (a *App) SetupInviteEmailRateLimiting() error {
return nil
}
func (a *App) SendChangeUsernameEmail(oldUsername, newUsername, email, locale, siteURL string) *model.AppError {
func (a *App) sendChangeUsernameEmail(oldUsername, newUsername, email, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.username_change_subject",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"],
"TeamDisplayName": a.Config().TeamSettings.SiteName})
bodyPage := a.NewEmailTemplate("email_change_body", locale)
bodyPage := a.newEmailTemplate("email_change_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.username_change_body.title")
bodyPage.Props["Info"] = T("api.templates.username_change_body.info",
map[string]interface{}{"TeamDisplayName": a.Config().TeamSettings.SiteName, "NewUsername": newUsername})
bodyPage.Props["Warning"] = T("api.templates.email_warning")
if err := a.SendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendChangeUsernameEmail", "api.user.send_email_change_username_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
if err := a.sendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("sendChangeUsernameEmail", "api.user.send_email_change_username_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
}
func (a *App) SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token string) *model.AppError {
func (a *App) sendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token string) *model.AppError {
T := utils.GetUserTranslations(locale)
link := fmt.Sprintf("%s/do_verify_email?token=%s&email=%s", siteURL, token, url.QueryEscape(newUserEmail))
@@ -89,7 +89,7 @@ func (a *App) SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token st
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"],
"TeamDisplayName": a.Config().TeamSettings.SiteName})
bodyPage := a.NewEmailTemplate("email_change_verify_body", locale)
bodyPage := a.newEmailTemplate("email_change_verify_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.email_change_verify_body.title")
bodyPage.Props["Info"] = T("api.templates.email_change_verify_body.info",
@@ -97,35 +97,35 @@ func (a *App) SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token st
bodyPage.Props["VerifyUrl"] = link
bodyPage.Props["VerifyButton"] = T("api.templates.email_change_verify_body.button")
if err := a.SendMail(newUserEmail, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendEmailChangeVerifyEmail", "api.user.send_email_change_verify_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
if err := a.sendMail(newUserEmail, subject, bodyPage.Render()); err != nil {
return model.NewAppError("sendEmailChangeVerifyEmail", "api.user.send_email_change_verify_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
}
func (a *App) SendEmailChangeEmail(oldEmail, newEmail, locale, siteURL string) *model.AppError {
func (a *App) sendEmailChangeEmail(oldEmail, newEmail, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.email_change_subject",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"],
"TeamDisplayName": a.Config().TeamSettings.SiteName})
bodyPage := a.NewEmailTemplate("email_change_body", locale)
bodyPage := a.newEmailTemplate("email_change_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.email_change_body.title")
bodyPage.Props["Info"] = T("api.templates.email_change_body.info",
map[string]interface{}{"TeamDisplayName": a.Config().TeamSettings.SiteName, "NewEmail": newEmail})
bodyPage.Props["Warning"] = T("api.templates.email_warning")
if err := a.SendMail(oldEmail, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendEmailChangeEmail", "api.user.send_email_change_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
if err := a.sendMail(oldEmail, subject, bodyPage.Render()); err != nil {
return model.NewAppError("sendEmailChangeEmail", "api.user.send_email_change_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
}
func (a *App) SendVerifyEmail(userEmail, locale, siteURL, token string) *model.AppError {
func (a *App) sendVerifyEmail(userEmail, locale, siteURL, token string) *model.AppError {
T := utils.GetUserTranslations(locale)
link := fmt.Sprintf("%s/do_verify_email?token=%s&email=%s", siteURL, token, url.QueryEscape(userEmail))
@@ -135,14 +135,14 @@ func (a *App) SendVerifyEmail(userEmail, locale, siteURL, token string) *model.A
subject := T("api.templates.verify_subject",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"]})
bodyPage := a.NewEmailTemplate("verify_body", locale)
bodyPage := a.newEmailTemplate("verify_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.verify_body.title", map[string]interface{}{"ServerURL": serverURL})
bodyPage.Props["Info"] = T("api.templates.verify_body.info")
bodyPage.Props["VerifyUrl"] = link
bodyPage.Props["Button"] = T("api.templates.verify_body.button")
if err := a.SendMail(userEmail, subject, bodyPage.Render()); err != nil {
if err := a.sendMail(userEmail, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendVerifyEmail", "api.user.send_verify_email_and_forget.failed.error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -155,21 +155,21 @@ func (a *App) SendSignInChangeEmail(email, method, locale, siteURL string) *mode
subject := T("api.templates.signin_change_email.subject",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"]})
bodyPage := a.NewEmailTemplate("signin_change_body", locale)
bodyPage := a.newEmailTemplate("signin_change_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.signin_change_email.body.title")
bodyPage.Props["Info"] = T("api.templates.signin_change_email.body.info",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"], "Method": method})
bodyPage.Props["Warning"] = T("api.templates.email_warning")
if err := a.SendMail(email, subject, bodyPage.Render()); err != nil {
if err := a.sendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendSignInChangeEmail", "api.user.send_sign_in_change_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
}
func (a *App) SendWelcomeEmail(userId string, email string, verified bool, locale, siteURL string) *model.AppError {
func (a *App) sendWelcomeEmail(userId string, email string, verified bool, locale, siteURL string) *model.AppError {
if !*a.Config().EmailSettings.SendEmailNotifications && !*a.Config().EmailSettings.RequireEmailVerification {
return model.NewAppError("SendWelcomeEmail", "api.user.send_welcome_email_and_forget.failed.error", nil, "Send Email Notifications and Require Email Verification is disabled in the system console", http.StatusInternalServerError)
}
@@ -182,7 +182,7 @@ func (a *App) SendWelcomeEmail(userId string, email string, verified bool, local
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"],
"ServerURL": serverURL})
bodyPage := a.NewEmailTemplate("welcome_body", locale)
bodyPage := a.newEmailTemplate("welcome_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.welcome_body.title", map[string]interface{}{"ServerURL": serverURL})
bodyPage.Props["Info"] = T("api.templates.welcome_body.info")
@@ -205,49 +205,49 @@ func (a *App) SendWelcomeEmail(userId string, email string, verified bool, local
bodyPage.Props["VerifyUrl"] = link
}
if err := a.SendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendWelcomeEmail", "api.user.send_welcome_email_and_forget.failed.error", nil, err.Error(), http.StatusInternalServerError)
if err := a.sendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("sendWelcomeEmail", "api.user.send_welcome_email_and_forget.failed.error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
}
func (a *App) SendPasswordChangeEmail(email, method, locale, siteURL string) *model.AppError {
func (a *App) sendPasswordChangeEmail(email, method, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.password_change_subject",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"],
"TeamDisplayName": a.Config().TeamSettings.SiteName})
bodyPage := a.NewEmailTemplate("password_change_body", locale)
bodyPage := a.newEmailTemplate("password_change_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.password_change_body.title")
bodyPage.Props["Info"] = T("api.templates.password_change_body.info",
map[string]interface{}{"TeamDisplayName": a.Config().TeamSettings.SiteName, "TeamURL": siteURL, "Method": method})
bodyPage.Props["Warning"] = T("api.templates.email_warning")
if err := a.SendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendPasswordChangeEmail", "api.user.send_password_change_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
if err := a.sendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("sendPasswordChangeEmail", "api.user.send_password_change_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
}
func (a *App) SendUserAccessTokenAddedEmail(email, locale, siteURL string) *model.AppError {
func (a *App) sendUserAccessTokenAddedEmail(email, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.user_access_token_subject",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"]})
bodyPage := a.NewEmailTemplate("password_change_body", locale)
bodyPage := a.newEmailTemplate("password_change_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.user_access_token_body.title")
bodyPage.Props["Info"] = T("api.templates.user_access_token_body.info",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"], "SiteURL": siteURL})
bodyPage.Props["Warning"] = T("api.templates.email_warning")
if err := a.SendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendUserAccessTokenAddedEmail", "api.user.send_user_access_token.error", nil, err.Error(), http.StatusInternalServerError)
if err := a.sendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("sendUserAccessTokenAddedEmail", "api.user.send_user_access_token.error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
@@ -261,7 +261,7 @@ func (a *App) SendPasswordResetEmail(email string, token *model.Token, locale, s
subject := T("api.templates.reset_subject",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"]})
bodyPage := a.NewEmailTemplate("reset_body", locale)
bodyPage := a.newEmailTemplate("reset_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.reset_body.title")
bodyPage.Props["Info1"] = utils.TranslateAsHtml(T, "api.templates.reset_body.info1", nil)
@@ -269,20 +269,20 @@ func (a *App) SendPasswordResetEmail(email string, token *model.Token, locale, s
bodyPage.Props["ResetUrl"] = link
bodyPage.Props["Button"] = T("api.templates.reset_body.button")
if err := a.SendMail(email, subject, bodyPage.Render()); err != nil {
if err := a.sendMail(email, subject, bodyPage.Render()); err != nil {
return false, model.NewAppError("SendPasswordReset", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
}
return true, nil
}
func (a *App) SendMfaChangeEmail(email string, activated bool, locale, siteURL string) *model.AppError {
func (a *App) sendMfaChangeEmail(email string, activated bool, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.mfa_change_subject",
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"]})
bodyPage := a.NewEmailTemplate("mfa_change_body", locale)
bodyPage := a.newEmailTemplate("mfa_change_body", locale)
bodyPage.Props["SiteURL"] = siteURL
if activated {
@@ -294,7 +294,7 @@ func (a *App) SendMfaChangeEmail(email string, activated bool, locale, siteURL s
}
bodyPage.Props["Warning"] = T("api.templates.email_warning")
if err := a.SendMail(email, subject, bodyPage.Render()); err != nil {
if err := a.sendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendMfaChangeEmail", "api.user.send_mfa_change_email.error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -328,7 +328,7 @@ func (a *App) SendInviteEmails(team *model.Team, senderName string, senderUserId
"TeamDisplayName": team.DisplayName,
"SiteName": a.ClientConfig()["SiteName"]})
bodyPage := a.NewEmailTemplate("invite_body", model.DEFAULT_LOCALE)
bodyPage := a.newEmailTemplate("invite_body", model.DEFAULT_LOCALE)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = utils.T("api.templates.invite_body.title")
bodyPage.Html["Info"] = utils.TranslateAsHtml(utils.T, "api.templates.invite_body.info",
@@ -355,14 +355,14 @@ func (a *App) SendInviteEmails(team *model.Team, senderName string, senderUserId
}
bodyPage.Props["Link"] = fmt.Sprintf("%s/signup_user_complete/?d=%s&t=%s", siteURL, url.QueryEscape(data), url.QueryEscape(token.Token))
if err := a.SendMail(invite, subject, bodyPage.Render()); err != nil {
if err := a.sendMail(invite, subject, bodyPage.Render()); err != nil {
mlog.Error("Failed to send invite email successfully ", mlog.Err(err))
}
}
}
}
func (a *App) SendGuestInviteEmails(team *model.Team, channels []*model.Channel, senderName string, senderUserId string, invites []string, siteURL string, message string) {
func (a *App) sendGuestInviteEmails(team *model.Team, channels []*model.Channel, senderName string, senderUserId string, invites []string, siteURL string, message string) {
if a.Srv().EmailRateLimiter == nil {
a.Log().Error("Email invite not sent, rate limiting could not be setup.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id))
return
@@ -400,7 +400,7 @@ func (a *App) SendGuestInviteEmails(team *model.Team, channels []*model.Channel,
"TeamDisplayName": team.DisplayName,
"SiteName": a.ClientConfig()["SiteName"]})
bodyPage := a.NewEmailTemplate("invite_body", model.DEFAULT_LOCALE)
bodyPage := a.newEmailTemplate("invite_body", model.DEFAULT_LOCALE)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = utils.T("api.templates.invite_body.title")
bodyPage.Html["Info"] = utils.TranslateAsHtml(utils.T, "api.templates.invite_body_guest.info",
@@ -456,14 +456,14 @@ func (a *App) SendGuestInviteEmails(team *model.Team, channels []*model.Channel,
}
}
if err := a.SendMailWithEmbeddedFiles(invite, subject, bodyPage.Render(), embeddedFiles); err != nil {
if err := a.sendMailWithEmbeddedFiles(invite, subject, bodyPage.Render(), embeddedFiles); err != nil {
mlog.Error("Failed to send invite email successfully", mlog.Err(err))
}
}
}
}
func (a *App) NewEmailTemplate(name, locale string) *utils.HTMLTemplate {
func (a *App) newEmailTemplate(name, locale string) *utils.HTMLTemplate {
t := utils.NewHTMLTemplate(a.HTMLTemplates(), name)
var localT i18n.TranslateFunc
@@ -499,33 +499,33 @@ func (a *App) SendDeactivateAccountEmail(email string, locale, siteURL string) *
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"],
"ServerURL": serverURL})
bodyPage := a.NewEmailTemplate("deactivate_body", locale)
bodyPage := a.newEmailTemplate("deactivate_body", locale)
bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.deactivate_body.title", map[string]interface{}{"ServerURL": serverURL})
bodyPage.Props["Info"] = T("api.templates.deactivate_body.info",
map[string]interface{}{"SiteURL": siteURL})
bodyPage.Props["Warning"] = T("api.templates.deactivate_body.warning")
if err := a.SendMail(email, subject, bodyPage.Render()); err != nil {
if err := a.sendMail(email, subject, bodyPage.Render()); err != nil {
return model.NewAppError("SendDeactivateEmail", "api.user.send_deactivate_email_and_forget.failed.error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
}
func (a *App) SendNotificationMail(to, subject, htmlBody string) *model.AppError {
func (a *App) sendNotificationMail(to, subject, htmlBody string) *model.AppError {
if !*a.Config().EmailSettings.SendEmailNotifications {
return nil
}
return a.SendMail(to, subject, htmlBody)
return a.sendMail(to, subject, htmlBody)
}
func (a *App) SendMail(to, subject, htmlBody string) *model.AppError {
func (a *App) sendMail(to, subject, htmlBody string) *model.AppError {
license := a.License()
return mailservice.SendMailUsingConfig(to, subject, htmlBody, a.Config(), license != nil && *license.Features.Compliance)
}
func (a *App) SendMailWithEmbeddedFiles(to, subject, htmlBody string, embeddedFiles map[string]io.Reader) *model.AppError {
func (a *App) sendMailWithEmbeddedFiles(to, subject, htmlBody string, embeddedFiles map[string]io.Reader) *model.AppError {
license := a.License()
config := a.Config()