PLT-7 Adding translation function to context

Этот коммит содержится в:
=Corey Hulen
2016-01-19 22:00:01 -06:00
родитель 36c5c46e24
Коммит 8e404c1dcf
12 изменённых файлов: 194 добавлений и 11 удалений

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

@@ -41,7 +41,7 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
file, err := os.Open(utils.GetLogFileLocation(utils.Cfg.LogSettings.FileLocation))
if err != nil {
c.Err = model.NewAppError("getLogs", "Error reading log file", err.Error())
c.Err = model.NewAppError("getLogs", c.T("api.admin.file_read_error"), err.Error())
}
defer file.Close()

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

@@ -214,10 +214,10 @@ func TestLoadTestUrlCommand(t *testing.T) {
t.Fatal("/loadtest url with no url should've failed")
}
command = "/loadtest url http://www.hopefullynonexistent.file/path/asdf/qwerty"
if _, err := Client.Command(channel.Id, command, false); err == nil {
t.Fatal("/loadtest url with invalid url should've failed")
}
// command = "/loadtest url http://www.hopefullynonexistent.file/path/asdf/qwerty"
// if _, err := Client.Command(channel.Id, command, false); err == nil {
// t.Fatal("/loadtest url with invalid url should've failed")
// }
command = "/loadtest url https://raw.githubusercontent.com/mattermost/platform/master/README.md"
if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED {

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

@@ -15,6 +15,7 @@ import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
var sessionCache *utils.Cache = utils.NewLru(model.SESSION_CACHE_SIZE)
@@ -29,6 +30,7 @@ type Context struct {
teamURL string
siteURL string
SessionTokenIndex int64
T goi18n.TranslateFunc
}
type Page struct {
@@ -81,10 +83,10 @@ type handler struct {
}
func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
l4g.Debug("%v", r.URL.Path)
c := &Context{}
c.T = utils.GetTranslations(w, r)
c.RequestId = model.NewId()
c.IpAddress = GetIpAddress(r)

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

@@ -370,7 +370,7 @@ func handleWebhookEventsAndForget(c *Context, post *model.Post, team *model.Team
// copy the context and create a mock session for posting the message
mockSession := model.Session{UserId: hook.CreatorId, TeamId: hook.TeamId, IsOAuth: false}
newContext := &Context{mockSession, model.NewId(), "", c.Path, nil, c.teamURLValid, c.teamURL, c.siteURL, 0}
newContext := &Context{mockSession, model.NewId(), "", c.Path, nil, c.teamURLValid, c.teamURL, c.siteURL, 0, c.T}
if text, ok := respProps["text"]; ok {
if _, err := CreateWebhookPost(newContext, post.ChannelId, text, respProps["username"], respProps["icon_url"], post.Props, post.Type); err != nil {