Merge pull request #1962 from ZBoxApp/PLT-7-go

PLT-7: Refactoring api to use translations (chunk 3)
Этот коммит содержится в:
Corey Hulen
2016-01-24 06:36:30 -06:00
родитель 1a0b12313b eb58e631e7
Коммит 1dfd8c78c9
7 изменённых файлов: 1504 добавлений и 1348 удалений

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

@@ -8,6 +8,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
"github.com/mattermost/platform/store" "github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
"time" "time"
) )
@@ -33,11 +34,11 @@ func NewWebConn(ws *websocket.Conn, teamId string, userId string, sessionId stri
pchan := Srv.Store.User().UpdateLastPingAt(userId, model.GetMillis()) pchan := Srv.Store.User().UpdateLastPingAt(userId, model.GetMillis())
if result := <-achan; result.Err != nil { if result := <-achan; result.Err != nil {
l4g.Error("Failed to update LastActivityAt for user_id=%v and session_id=%v, err=%v", userId, sessionId, result.Err) l4g.Error(utils.T("api.web_conn.new_web_conn.last_activity.error"), userId, sessionId, result.Err)
} }
if result := <-pchan; result.Err != nil { if result := <-pchan; result.Err != nil {
l4g.Error("Failed to updated LastPingAt for user_id=%v, err=%v", userId, result.Err) l4g.Error(utils.T("api.web_conn.new_web_conn.last_ping.error"), userId, result.Err)
} }
}() }()
@@ -56,7 +57,7 @@ func (c *WebConn) readPump() {
go func() { go func() {
if result := <-Srv.Store.User().UpdateLastPingAt(c.UserId, model.GetMillis()); result.Err != nil { if result := <-Srv.Store.User().UpdateLastPingAt(c.UserId, model.GetMillis()); result.Err != nil {
l4g.Error("Failed to updated LastPingAt for user_id=%v, err=%v", c.UserId, result.Err) l4g.Error(utils.T("api.web_conn.new_web_conn.last_ping.error"), c.UserId, result.Err)
} }
}() }()

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

@@ -6,6 +6,7 @@ package api
import ( import (
l4g "github.com/alecthomas/log4go" l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
) )
type Hub struct { type Hub struct {
@@ -86,7 +87,7 @@ func (h *Hub) Start() {
nh.broadcast <- msg nh.broadcast <- msg
} }
case s := <-h.stop: case s := <-h.stop:
l4g.Debug("stopping %v connections", s) l4g.Debug(utils.T("api.web_hub.start.stopping.debug"), s)
for _, v := range h.teamHubs { for _, v := range h.teamHubs {
v.Stop() v.Stop()
} }

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

@@ -8,11 +8,12 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"net/http" "net/http"
) )
func InitWebSocket(r *mux.Router) { func InitWebSocket(r *mux.Router) {
l4g.Debug("Initializing web socket api routes") l4g.Debug(utils.T("api.web_socket.init.debug"))
r.Handle("/websocket", ApiUserRequired(connect)).Methods("GET") r.Handle("/websocket", ApiUserRequired(connect)).Methods("GET")
hub.Start() hub.Start()
} }
@@ -28,8 +29,8 @@ func connect(c *Context, w http.ResponseWriter, r *http.Request) {
ws, err := upgrader.Upgrade(w, r, nil) ws, err := upgrader.Upgrade(w, r, nil)
if err != nil { if err != nil {
l4g.Error("websocket connect err: %v", err) l4g.Error(utils.T("api.web_socket.connect.error"), err)
c.Err = model.NewAppError("connect", "Failed to upgrade websocket connection", "") c.Err = model.NewLocAppError("connect", "api.web_socket.connect.upgrade.app_error", nil, "")
return return
} }

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

@@ -6,6 +6,7 @@ package api
import ( import (
l4g "github.com/alecthomas/log4go" l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
) )
type TeamHub struct { type TeamHub struct {
@@ -65,7 +66,7 @@ func (h *TeamHub) Start() {
case s := <-h.stop: case s := <-h.stop:
if s { if s {
l4g.Debug("team hub stopping for teamId=%v", h.teamId) l4g.Debug(utils.T("api.web_team_hun.start.debug"), h.teamId)
for webCon := range h.connections { for webCon := range h.connections {
webCon.WebSocket.Close() webCon.WebSocket.Close()

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

@@ -12,7 +12,7 @@ import (
) )
func InitWebhook(r *mux.Router) { func InitWebhook(r *mux.Router) {
l4g.Debug("Initializing webhook api routes") l4g.Debug(utils.T("api.webhook.init.debug"))
sr := r.PathPrefix("/hooks").Subrouter() sr := r.PathPrefix("/hooks").Subrouter()
sr.Handle("/incoming/create", ApiUserRequired(createIncomingHook)).Methods("POST") sr.Handle("/incoming/create", ApiUserRequired(createIncomingHook)).Methods("POST")
@@ -27,7 +27,7 @@ func InitWebhook(r *mux.Router) {
func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) { func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks { if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
c.Err = model.NewAppError("createIncomingHook", "Incoming webhooks have been disabled by the system admin.", "") c.Err = model.NewLocAppError("createIncomingHook", "api.webhook.create_incoming.disabled.app_errror", nil, "")
c.Err.StatusCode = http.StatusNotImplemented c.Err.StatusCode = http.StatusNotImplemented
return return
} }
@@ -74,7 +74,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) { func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks { if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
c.Err = model.NewAppError("deleteIncomingHook", "Incoming webhooks have been disabled by the system admin.", "") c.Err = model.NewLocAppError("deleteIncomingHook", "api.webhook.delete_incoming.disabled.app_errror", nil, "")
c.Err.StatusCode = http.StatusNotImplemented c.Err.StatusCode = http.StatusNotImplemented
return return
} }
@@ -95,7 +95,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
} else { } else {
if c.Session.UserId != result.Data.(*model.IncomingWebhook).UserId && !c.IsTeamAdmin() { if c.Session.UserId != result.Data.(*model.IncomingWebhook).UserId && !c.IsTeamAdmin() {
c.LogAudit("fail - inappropriate permissions") c.LogAudit("fail - inappropriate permissions")
c.Err = model.NewAppError("deleteIncomingHook", "Inappropriate permissions to delete incoming webhook", "user_id="+c.Session.UserId) c.Err = model.NewLocAppError("deleteIncomingHook", "api.webhook.delete_incoming.permissions.app_errror", nil, "user_id="+c.Session.UserId)
return return
} }
} }
@@ -111,7 +111,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) { func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks { if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
c.Err = model.NewAppError("getIncomingHooks", "Incoming webhooks have been disabled by the system admin.", "") c.Err = model.NewLocAppError("getIncomingHooks", "api.webhook.get_incoming.disabled.app_error", nil, "")
c.Err.StatusCode = http.StatusNotImplemented c.Err.StatusCode = http.StatusNotImplemented
return return
} }
@@ -127,7 +127,7 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) { func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks { if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
c.Err = model.NewAppError("createOutgoingHook", "Outgoing webhooks have been disabled by the system admin.", "") c.Err = model.NewLocAppError("createOutgoingHook", "api.webhook.create_outgoing.disabled.app_error", nil, "")
c.Err.StatusCode = http.StatusNotImplemented c.Err.StatusCode = http.StatusNotImplemented
return return
} }
@@ -167,7 +167,7 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
} }
} }
} else if len(hook.TriggerWords) == 0 { } else if len(hook.TriggerWords) == 0 {
c.Err = model.NewAppError("createOutgoingHook", "Either trigger_words or channel_id must be set", "") c.Err = model.NewLocAppError("createOutgoingHook", "api.webhook.create_outgoing.triggers.app_error", nil, "")
return return
} }
@@ -183,7 +183,7 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) { func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks { if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
c.Err = model.NewAppError("getOutgoingHooks", "Outgoing webhooks have been disabled by the system admin.", "") c.Err = model.NewLocAppError("getOutgoingHooks", "api.webhook.get_outgoing.disabled.app_error", nil, "")
c.Err.StatusCode = http.StatusNotImplemented c.Err.StatusCode = http.StatusNotImplemented
return return
} }
@@ -199,7 +199,7 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) { func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks { if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
c.Err = model.NewAppError("deleteOutgoingHook", "Outgoing webhooks have been disabled by the system admin.", "") c.Err = model.NewLocAppError("deleteOutgoingHook", "api.webhook.delete_outgoing.disabled.app_error", nil, "")
c.Err.StatusCode = http.StatusNotImplemented c.Err.StatusCode = http.StatusNotImplemented
return return
} }
@@ -220,7 +220,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
} else { } else {
if c.Session.UserId != result.Data.(*model.OutgoingWebhook).CreatorId && !c.IsTeamAdmin() { if c.Session.UserId != result.Data.(*model.OutgoingWebhook).CreatorId && !c.IsTeamAdmin() {
c.LogAudit("fail - inappropriate permissions") c.LogAudit("fail - inappropriate permissions")
c.Err = model.NewAppError("deleteOutgoingHook", "Inappropriate permissions to delete outcoming webhook", "user_id="+c.Session.UserId) c.Err = model.NewLocAppError("deleteOutgoingHook", "api.webhook.delete_outgoing.permissions.app_error", nil, "user_id="+c.Session.UserId)
return return
} }
} }
@@ -236,7 +236,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request) { func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks { if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
c.Err = model.NewAppError("regenOutgoingHookToken", "Outgoing webhooks have been disabled by the system admin.", "") c.Err = model.NewLocAppError("regenOutgoingHookToken", "api.webhook.regen_outgoing_token.disabled.app_error", nil, "")
c.Err.StatusCode = http.StatusNotImplemented c.Err.StatusCode = http.StatusNotImplemented
return return
} }
@@ -260,7 +260,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
if c.Session.UserId != hook.CreatorId && !c.IsTeamAdmin() { if c.Session.UserId != hook.CreatorId && !c.IsTeamAdmin() {
c.LogAudit("fail - inappropriate permissions") c.LogAudit("fail - inappropriate permissions")
c.Err = model.NewAppError("regenOutgoingHookToken", "Inappropriate permissions to regenerate outcoming webhook token", "user_id="+c.Session.UserId) c.Err = model.NewLocAppError("regenOutgoingHookToken", "api.webhook.regen_outgoing_token.permissions.app_error", nil, "user_id="+c.Session.UserId)
return return
} }
} }

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@@ -1,4 +1,8 @@
[ [
{
"id": "",
"translation": "Webhooks entrantes han sido deshabilitados por el administrador del sistema."
},
{ {
"id": "api.admin.file_read_error", "id": "api.admin.file_read_error",
"translation": "Error leyendo el archivo de registro" "translation": "Error leyendo el archivo de registro"
@@ -1319,6 +1323,78 @@
"id": "api.user.upload_profile_user.too_large.app_error", "id": "api.user.upload_profile_user.too_large.app_error",
"translation": "No se pudo actualizar la imagen del perfil. El archivo es muy grande." "translation": "No se pudo actualizar la imagen del perfil. El archivo es muy grande."
}, },
{
"id": "api.web_conn.new_web_conn.last_activity.error",
"translation": "Falla al actualizar LastActivityAt para user_id=%v and session_id=%v, err=%v"
},
{
"id": "api.web_conn.new_web_conn.last_ping.error",
"translation": "Failed to update LastPingAt for user_id=%v, err=%v"
},
{
"id": "api.web_hub.start.stopping.debug",
"translation": "deteniendo todas las conexiones"
},
{
"id": "api.web_socket.connect.error",
"translation": "conexión al websocket err: %v"
},
{
"id": "api.web_socket.connect.upgrade.app_error",
"translation": "Falla al actualizar la conexión del websocket"
},
{
"id": "api.web_socket.init.debug",
"translation": "Inicializando rutas del API para los web socket"
},
{
"id": "api.web_team_hun.start.debug",
"translation": "deteniendo el hub de equipo para teamId=%v"
},
{
"id": "api.webhook.create_outgoing.disabled.app_error",
"translation": "Webhooks de Salida han sido deshabilitados por el administrador del sistema."
},
{
"id": "api.webhook.create_outgoing.triggers.app_error",
"translation": "Debe establecerse palabras gatilladoras o un channel_id"
},
{
"id": "api.webhook.delete_incoming.disabled.app_errror",
"translation": "Webhooks entrantes han sido deshabilitados por el administrador del sistema."
},
{
"id": "api.webhook.delete_incoming.permissions.app_errror",
"translation": "Permisos inapropiados para eliminar un webhook entrante"
},
{
"id": "api.webhook.delete_outgoing.disabled.app_error",
"translation": "Webhooks de Salida han sido deshabilitados por el administrador del sistema."
},
{
"id": "api.webhook.delete_outgoing.permissions.app_error",
"translation": "Permisos inapropiados para eliminar el webhook saliente"
},
{
"id": "api.webhook.get_incoming.disabled.app_error",
"translation": "Webhooks entrantes han sido deshabilitados por el administrador del sistema."
},
{
"id": "api.webhook.get_outgoing.disabled.app_error",
"translation": "Webhooks de Salida han sido deshabilitados por el administrador del sistema."
},
{
"id": "api.webhook.init.debug",
"translation": "Inicializando rutas del API para los Webhooks"
},
{
"id": "api.webhook.regen_outgoing_token.disabled.app_error",
"translation": "Webhooks de Salida han sido deshabilitados por el administrador del sistema."
},
{
"id": "api.webhook.regen_outgoing_token.permissions.app_error",
"translation": "Permisos inapropiados para regenerar un token para el Webhook saliente"
},
{ {
"id": "mattermost.current_version", "id": "mattermost.current_version",
"translation": "La versión actual es %v (%v/%v/%v)" "translation": "La versión actual es %v (%v/%v/%v)"