MM-16369: include potential subpath in emails (#11311)
* MM-16369: include potential subpath in emails Various email templates were extracting the `Host` but not the `Path` from the SiteURL, excluding a potential subpath defined therein. * improve coverage of condenseSiteURL
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
56e629e842
Коммит
5acb0ad227
26
app/email.go
26
app/email.go
@@ -6,6 +6,7 @@ package app
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"net/http"
|
||||
|
||||
@@ -26,6 +27,15 @@ const (
|
||||
emailRateLimitingMaxBurst = 20
|
||||
)
|
||||
|
||||
func condenseSiteURL(siteURL string) string {
|
||||
parsedSiteURL, _ := url.Parse(siteURL)
|
||||
if parsedSiteURL.Path == "" || parsedSiteURL.Path == "/" {
|
||||
return parsedSiteURL.Host
|
||||
}
|
||||
|
||||
return path.Join(parsedSiteURL.Host, parsedSiteURL.Path)
|
||||
}
|
||||
|
||||
func (a *App) SetupInviteEmailRateLimiting() error {
|
||||
store, err := memstore.New(emailRateLimitingMemstoreSize)
|
||||
if err != nil {
|
||||
@@ -117,14 +127,14 @@ func (a *App) SendVerifyEmail(userEmail, locale, siteURL, token string) *model.A
|
||||
|
||||
link := fmt.Sprintf("%s/do_verify_email?token=%s&email=%s", siteURL, token, url.QueryEscape(userEmail))
|
||||
|
||||
url, _ := url.Parse(siteURL)
|
||||
serverURL := condenseSiteURL(siteURL)
|
||||
|
||||
subject := T("api.templates.verify_subject",
|
||||
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"]})
|
||||
|
||||
bodyPage := a.NewEmailTemplate("verify_body", locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = T("api.templates.verify_body.title", map[string]interface{}{"ServerURL": url.Host})
|
||||
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")
|
||||
@@ -159,15 +169,15 @@ func (a *App) SendSignInChangeEmail(email, method, locale, siteURL string) *mode
|
||||
func (a *App) SendWelcomeEmail(userId string, email string, verified bool, locale, siteURL string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
rawUrl, _ := url.Parse(siteURL)
|
||||
serverURL := condenseSiteURL(siteURL)
|
||||
|
||||
subject := T("api.templates.welcome_subject",
|
||||
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"],
|
||||
"ServerURL": rawUrl.Host})
|
||||
"ServerURL": serverURL})
|
||||
|
||||
bodyPage := a.NewEmailTemplate("welcome_body", locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = T("api.templates.welcome_body.title", map[string]interface{}{"ServerURL": rawUrl.Host})
|
||||
bodyPage.Props["Title"] = T("api.templates.welcome_body.title", map[string]interface{}{"ServerURL": serverURL})
|
||||
bodyPage.Props["Info"] = T("api.templates.welcome_body.info")
|
||||
bodyPage.Props["Button"] = T("api.templates.welcome_body.button")
|
||||
bodyPage.Props["Info2"] = T("api.templates.welcome_body.info2")
|
||||
@@ -382,15 +392,15 @@ func (a *App) NewEmailTemplate(name, locale string) *utils.HTMLTemplate {
|
||||
func (a *App) SendDeactivateAccountEmail(email string, locale, siteURL string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
rawUrl, _ := url.Parse(siteURL)
|
||||
serverURL := condenseSiteURL(siteURL)
|
||||
|
||||
subject := T("api.templates.deactivate_subject",
|
||||
map[string]interface{}{"SiteName": a.ClientConfig()["SiteName"],
|
||||
"ServerURL": rawUrl.Host})
|
||||
"ServerURL": serverURL})
|
||||
|
||||
bodyPage := a.NewEmailTemplate("deactivate_body", locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = T("api.templates.deactivate_body.title", map[string]interface{}{"ServerURL": rawUrl.Host})
|
||||
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")
|
||||
|
||||
28
app/email_test.go
Обычный файл
28
app/email_test.go
Обычный файл
@@ -0,0 +1,28 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCondenseSiteURL(t *testing.T) {
|
||||
require.Equal(t, "", condenseSiteURL(""))
|
||||
require.Equal(t, "mattermost.com", condenseSiteURL("mattermost.com"))
|
||||
require.Equal(t, "mattermost.com", condenseSiteURL("mattermost.com/"))
|
||||
require.Equal(t, "chat.mattermost.com", condenseSiteURL("chat.mattermost.com"))
|
||||
require.Equal(t, "chat.mattermost.com", condenseSiteURL("chat.mattermost.com/"))
|
||||
require.Equal(t, "mattermost.com/subpath", condenseSiteURL("mattermost.com/subpath"))
|
||||
require.Equal(t, "mattermost.com/subpath", condenseSiteURL("mattermost.com/subpath/"))
|
||||
require.Equal(t, "chat.mattermost.com/subpath", condenseSiteURL("chat.mattermost.com/subpath"))
|
||||
require.Equal(t, "chat.mattermost.com/subpath", condenseSiteURL("chat.mattermost.com/subpath/"))
|
||||
|
||||
require.Equal(t, "mattermost.com:8080", condenseSiteURL("http://mattermost.com:8080"))
|
||||
require.Equal(t, "mattermost.com:8080", condenseSiteURL("http://mattermost.com:8080/"))
|
||||
require.Equal(t, "chat.mattermost.com:8080", condenseSiteURL("http://chat.mattermost.com:8080"))
|
||||
require.Equal(t, "chat.mattermost.com:8080", condenseSiteURL("http://chat.mattermost.com:8080/"))
|
||||
require.Equal(t, "mattermost.com:8080/subpath", condenseSiteURL("http://mattermost.com:8080/subpath"))
|
||||
require.Equal(t, "mattermost.com:8080/subpath", condenseSiteURL("http://mattermost.com:8080/subpath/"))
|
||||
require.Equal(t, "chat.mattermost.com:8080/subpath", condenseSiteURL("http://chat.mattermost.com:8080/subpath"))
|
||||
require.Equal(t, "chat.mattermost.com:8080/subpath", condenseSiteURL("http://chat.mattermost.com:8080/subpath/"))
|
||||
}
|
||||
Ссылка в новой задаче
Block a user