summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-01-20 07:59:56 -0600
committer=Corey Hulen <corey@hulen.com>2016-01-20 07:59:56 -0600
commitf5eb3c1bcb0c7e367f64bd8e5a0d2d5418f8e2ef (patch)
treec40d7064cd2045c36b5c95db8faa9997497e459a
parent1acd38b7b19521d06d274c42c00ce7072cd92196 (diff)
downloadchat-f5eb3c1bcb0c7e367f64bd8e5a0d2d5418f8e2ef.tar.gz
chat-f5eb3c1bcb0c7e367f64bd8e5a0d2d5418f8e2ef.tar.bz2
chat-f5eb3c1bcb0c7e367f64bd8e5a0d2d5418f8e2ef.zip
PLT-7 adding loc for db calls audits and prefs
-rw-r--r--api/channel.go2
-rw-r--r--api/context.go4
-rw-r--r--api/post.go22
-rw-r--r--api/post_test.go2
-rw-r--r--api/preference.go8
-rw-r--r--api/team.go13
-rw-r--r--api/user.go44
-rw-r--r--mattermost.go2
-rw-r--r--store/sql_audit_store.go7
-rw-r--r--store/sql_audit_store_test.go15
-rw-r--r--store/sql_preference_store.go27
-rw-r--r--store/sql_preference_store_test.go43
-rw-r--r--store/sql_store.go4
-rw-r--r--store/store.go22
-rw-r--r--web/web.go13
15 files changed, 120 insertions, 108 deletions
diff --git a/api/channel.go b/api/channel.go
index 706baa004..17a0f2031 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -692,7 +692,7 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) {
Value: id,
}
- Srv.Store.Preference().Save(&model.Preferences{preference})
+ Srv.Store.Preference().Save(c.T, &model.Preferences{preference})
message := model.NewMessage(c.Session.TeamId, id, c.Session.UserId, model.ACTION_CHANNEL_VIEWED)
message.Add("channel_id", id)
diff --git a/api/context.go b/api/context.go
index b6ffb1a29..fdca52085 100644
--- a/api/context.go
+++ b/api/context.go
@@ -233,7 +233,7 @@ func GetProtocol(r *http.Request) string {
func (c *Context) LogAudit(extraInfo string) {
audit := &model.Audit{UserId: c.Session.UserId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id}
- if r := <-Srv.Store.Audit().Save(audit); r.Err != nil {
+ if r := <-Srv.Store.Audit().Save(c.T, audit); r.Err != nil {
c.LogError(r.Err)
}
}
@@ -245,7 +245,7 @@ func (c *Context) LogAuditWithUserId(userId, extraInfo string) {
}
audit := &model.Audit{UserId: userId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id}
- if r := <-Srv.Store.Audit().Save(audit); r.Err != nil {
+ if r := <-Srv.Store.Audit().Save(c.T, audit); r.Err != nil {
c.LogError(r.Err)
}
}
diff --git a/api/post.go b/api/post.go
index 7cd45d310..a662cc147 100644
--- a/api/post.go
+++ b/api/post.go
@@ -5,11 +5,6 @@ package api
import (
"fmt"
- l4g "github.com/alecthomas/log4go"
- "github.com/gorilla/mux"
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/store"
- "github.com/mattermost/platform/utils"
"net/http"
"net/url"
"path/filepath"
@@ -17,6 +12,13 @@ import (
"strconv"
"strings"
"time"
+
+ l4g "github.com/alecthomas/log4go"
+ "github.com/gorilla/mux"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/store"
+ "github.com/mattermost/platform/utils"
+ goi18n "github.com/nicksnyder/go-i18n/i18n"
)
func InitPost(r *mux.Router) {
@@ -238,12 +240,12 @@ func handlePostEventsAndForget(c *Context, post *model.Post, triggerWebhooks boo
}
if channel.Type == model.CHANNEL_DIRECT {
- go makeDirectChannelVisible(c.Session.TeamId, post.ChannelId)
+ go makeDirectChannelVisible(c.T, c.Session.TeamId, post.ChannelId)
}
}()
}
-func makeDirectChannelVisible(teamId string, channelId string) {
+func makeDirectChannelVisible(T goi18n.TranslateFunc, teamId string, channelId string) {
var members []model.ChannelMember
if result := <-Srv.Store.Channel().GetMembers(channelId); result.Err != nil {
l4g.Error("Failed to get channel members channel_id=%v err=%v", channelId, result.Err.Message)
@@ -261,7 +263,7 @@ func makeDirectChannelVisible(teamId string, channelId string) {
for i, member := range members {
otherUserId := members[1-i].UserId
- if result := <-Srv.Store.Preference().Get(member.UserId, model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW, otherUserId); result.Err != nil {
+ if result := <-Srv.Store.Preference().Get(T, member.UserId, model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW, otherUserId); result.Err != nil {
// create a new preference since one doesn't exist yet
preference := &model.Preference{
UserId: member.UserId,
@@ -270,7 +272,7 @@ func makeDirectChannelVisible(teamId string, channelId string) {
Value: "true",
}
- if saveResult := <-Srv.Store.Preference().Save(&model.Preferences{*preference}); saveResult.Err != nil {
+ if saveResult := <-Srv.Store.Preference().Save(T, &model.Preferences{*preference}); saveResult.Err != nil {
l4g.Error("Failed to save direct channel preference user_id=%v other_user_id=%v err=%v", member.UserId, otherUserId, saveResult.Err.Message)
} else {
message := model.NewMessage(teamId, channelId, member.UserId, model.ACTION_PREFERENCE_CHANGED)
@@ -285,7 +287,7 @@ func makeDirectChannelVisible(teamId string, channelId string) {
// update the existing preference to make the channel visible
preference.Value = "true"
- if updateResult := <-Srv.Store.Preference().Save(&model.Preferences{preference}); updateResult.Err != nil {
+ if updateResult := <-Srv.Store.Preference().Save(T, &model.Preferences{preference}); updateResult.Err != nil {
l4g.Error("Failed to update direct channel preference user_id=%v other_user_id=%v err=%v", member.UserId, otherUserId, updateResult.Err.Message)
} else {
message := model.NewMessage(teamId, channelId, member.UserId, model.ACTION_PREFERENCE_CHANGED)
diff --git a/api/post_test.go b/api/post_test.go
index a0b8cc9bd..fc98333a8 100644
--- a/api/post_test.go
+++ b/api/post_test.go
@@ -837,7 +837,7 @@ func TestMakeDirectChannelVisible(t *testing.T) {
channel := Client.Must(Client.CreateDirectChannel(map[string]string{"user_id": user2.Id})).Data.(*model.Channel)
- makeDirectChannelVisible(team.Id, channel.Id)
+ makeDirectChannelVisible(utils.T, team.Id, channel.Id)
if result, err := Client.GetPreference(model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW, user2.Id); err != nil {
t.Fatal("Errored trying to set direct channel to be visible for user1")
diff --git a/api/preference.go b/api/preference.go
index f5c96f1dd..cb38370f1 100644
--- a/api/preference.go
+++ b/api/preference.go
@@ -21,7 +21,7 @@ func InitPreference(r *mux.Router) {
}
func getAllPreferences(c *Context, w http.ResponseWriter, r *http.Request) {
- if result := <-Srv.Store.Preference().GetAll(c.Session.UserId); result.Err != nil {
+ if result := <-Srv.Store.Preference().GetAll(c.T, c.Session.UserId); result.Err != nil {
c.Err = result.Err
} else {
data := result.Data.(model.Preferences)
@@ -46,7 +46,7 @@ func savePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
- if result := <-Srv.Store.Preference().Save(&preferences); result.Err != nil {
+ if result := <-Srv.Store.Preference().Save(c.T, &preferences); result.Err != nil {
c.Err = result.Err
return
}
@@ -58,7 +58,7 @@ func getPreferenceCategory(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
category := params["category"]
- if result := <-Srv.Store.Preference().GetCategory(c.Session.UserId, category); result.Err != nil {
+ if result := <-Srv.Store.Preference().GetCategory(c.T, c.Session.UserId, category); result.Err != nil {
c.Err = result.Err
} else {
data := result.Data.(model.Preferences)
@@ -72,7 +72,7 @@ func getPreference(c *Context, w http.ResponseWriter, r *http.Request) {
category := params["category"]
name := params["name"]
- if result := <-Srv.Store.Preference().Get(c.Session.UserId, category, name); result.Err != nil {
+ if result := <-Srv.Store.Preference().Get(c.T, c.Session.UserId, category, name); result.Err != nil {
c.Err = result.Err
} else {
data := result.Data.(model.Preference)
diff --git a/api/team.go b/api/team.go
index e2dd8807e..e94e60326 100644
--- a/api/team.go
+++ b/api/team.go
@@ -6,16 +6,17 @@ package api
import (
"bytes"
"fmt"
- l4g "github.com/alecthomas/log4go"
- "github.com/gorilla/mux"
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/store"
- "github.com/mattermost/platform/utils"
"net/http"
"net/url"
"strconv"
"strings"
"time"
+
+ l4g "github.com/alecthomas/log4go"
+ "github.com/gorilla/mux"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/store"
+ "github.com/mattermost/platform/utils"
)
func InitTeam(r *mux.Router) {
@@ -222,7 +223,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
teamSignup.User.TeamId = rteam.Id
teamSignup.User.EmailVerified = true
- ruser, err := CreateUser(rteam, &teamSignup.User)
+ ruser, err := CreateUser(c.T, rteam, &teamSignup.User)
if err != nil {
c.Err = err
return
diff --git a/api/user.go b/api/user.go
index a6b4fb654..c8c6a6fb9 100644
--- a/api/user.go
+++ b/api/user.go
@@ -7,15 +7,6 @@ import (
"bytes"
b64 "encoding/base64"
"fmt"
- l4g "github.com/alecthomas/log4go"
- "github.com/disintegration/imaging"
- "github.com/golang/freetype"
- "github.com/gorilla/mux"
- "github.com/mattermost/platform/einterfaces"
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/store"
- "github.com/mattermost/platform/utils"
- "github.com/mssola/user_agent"
"hash/fnv"
"image"
"image/color"
@@ -29,6 +20,17 @@ import (
"net/url"
"strconv"
"strings"
+
+ l4g "github.com/alecthomas/log4go"
+ "github.com/disintegration/imaging"
+ "github.com/golang/freetype"
+ "github.com/gorilla/mux"
+ "github.com/mattermost/platform/einterfaces"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/store"
+ "github.com/mattermost/platform/utils"
+ "github.com/mssola/user_agent"
+ goi18n "github.com/nicksnyder/go-i18n/i18n"
)
func InitUser(r *mux.Router) {
@@ -127,14 +129,14 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- ruser, err := CreateUser(team, user)
+ ruser, err := CreateUser(c.T, team, user)
if err != nil {
c.Err = err
return
}
if sendWelcomeEmail {
- sendWelcomeEmailAndForget(ruser.Id, ruser.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team), ruser.EmailVerified)
+ sendWelcomeEmailAndForget(c.T, ruser.Id, ruser.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team), ruser.EmailVerified)
}
w.Write([]byte(ruser.ToJson()))
@@ -183,7 +185,7 @@ func IsVerifyHashRequired(user *model.User, team *model.Team, hash string) bool
return shouldVerifyHash
}
-func CreateUser(team *model.Team, user *model.User) (*model.User, *model.AppError) {
+func CreateUser(T goi18n.TranslateFunc, team *model.Team, user *model.User) (*model.User, *model.AppError) {
channelRole := ""
if team.Email == user.Email {
@@ -218,7 +220,7 @@ func CreateUser(team *model.Team, user *model.User) (*model.User, *model.AppErro
l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, err)
}
- addDirectChannelsAndForget(ruser)
+ addDirectChannelsAndForget(T, ruser)
if user.EmailVerified {
if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
@@ -227,7 +229,7 @@ func CreateUser(team *model.Team, user *model.User) (*model.User, *model.AppErro
}
pref := model.Preference{UserId: ruser.Id, Category: model.PREFERENCE_CATEGORY_TUTORIAL_STEPS, Name: ruser.Id, Value: "0"}
- if presult := <-Srv.Store.Preference().Save(&model.Preferences{pref}); presult.Err != nil {
+ if presult := <-Srv.Store.Preference().Save(T, &model.Preferences{pref}); presult.Err != nil {
l4g.Error("Encountered error saving tutorial preference, err=%v", presult.Err.Message)
}
@@ -292,7 +294,7 @@ func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service
user.TeamId = team.Id
user.EmailVerified = true
- ruser, err := CreateUser(team, user)
+ ruser, err := CreateUser(c.T, team, user)
if err != nil {
c.Err = err
return nil
@@ -306,7 +308,7 @@ func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service
return ruser
}
-func sendWelcomeEmailAndForget(userId, email, teamName, teamDisplayName, siteURL, teamURL string, verified bool) {
+func sendWelcomeEmailAndForget(T goi18n.TranslateFunc, userId, email, teamName, teamDisplayName, siteURL, teamURL string, verified bool) {
go func() {
subjectPage := NewServerTemplatePage("welcome_subject")
@@ -326,7 +328,7 @@ func sendWelcomeEmailAndForget(userId, email, teamName, teamDisplayName, siteURL
}()
}
-func addDirectChannelsAndForget(user *model.User) {
+func addDirectChannelsAndForget(T goi18n.TranslateFunc, user *model.User) {
go func() {
var profiles map[string]*model.User
if result := <-Srv.Store.User().GetProfiles(user.TeamId); result.Err != nil {
@@ -359,7 +361,7 @@ func addDirectChannelsAndForget(user *model.User) {
}
}
- if result := <-Srv.Store.Preference().Save(&preferences); result.Err != nil {
+ if result := <-Srv.Store.Preference().Save(T, &preferences); result.Err != nil {
l4g.Error("Failed to add direct channel preferences for new user user_id=%s, eam_id=%s, err=%v", user.Id, user.TeamId, result.Err.Error())
}
}()
@@ -883,7 +885,7 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) {
}
userChan := Srv.Store.User().Get(id)
- auditChan := Srv.Store.Audit().Get(id, 20)
+ auditChan := Srv.Store.Audit().Get(c.T, id, 20)
if c.Err = (<-userChan).Err; c.Err != nil {
return
@@ -1450,7 +1452,7 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
return result.Err
}
- if result := <-Srv.Store.Preference().PermanentDeleteByUser(user.Id); result.Err != nil {
+ if result := <-Srv.Store.Preference().PermanentDeleteByUser(c.T, user.Id); result.Err != nil {
return result.Err
}
@@ -1466,7 +1468,7 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
return result.Err
}
- if result := <-Srv.Store.Audit().PermanentDeleteByUser(user.Id); result.Err != nil {
+ if result := <-Srv.Store.Audit().PermanentDeleteByUser(c.T, user.Id); result.Err != nil {
return result.Err
}
diff --git a/mattermost.go b/mattermost.go
index 9786a6abd..4b0d5d0ad 100644
--- a/mattermost.go
+++ b/mattermost.go
@@ -309,7 +309,7 @@ func cmdCreateUser() {
user.TeamId = team.Id
}
- _, err := api.CreateUser(team, user)
+ _, err := api.CreateUser(utils.T, team, user)
if err != nil {
if err.Message != "An account with that email already exists." {
l4g.Error("%v", err)
diff --git a/store/sql_audit_store.go b/store/sql_audit_store.go
index f4fd29aab..720e4f483 100644
--- a/store/sql_audit_store.go
+++ b/store/sql_audit_store.go
@@ -5,6 +5,7 @@ package store
import (
"github.com/mattermost/platform/model"
+ goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlAuditStore struct {
@@ -34,7 +35,7 @@ func (s SqlAuditStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_audits_user_id", "Audits", "UserId")
}
-func (s SqlAuditStore) Save(audit *model.Audit) StoreChannel {
+func (s SqlAuditStore) Save(T goi18n.TranslateFunc, audit *model.Audit) StoreChannel {
storeChannel := make(StoreChannel)
@@ -57,7 +58,7 @@ func (s SqlAuditStore) Save(audit *model.Audit) StoreChannel {
return storeChannel
}
-func (s SqlAuditStore) Get(user_id string, limit int) StoreChannel {
+func (s SqlAuditStore) Get(T goi18n.TranslateFunc, user_id string, limit int) StoreChannel {
storeChannel := make(StoreChannel)
@@ -87,7 +88,7 @@ func (s SqlAuditStore) Get(user_id string, limit int) StoreChannel {
return storeChannel
}
-func (s SqlAuditStore) PermanentDeleteByUser(userId string) StoreChannel {
+func (s SqlAuditStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel)
diff --git a/store/sql_audit_store_test.go b/store/sql_audit_store_test.go
index b395631f1..55147ad6f 100644
--- a/store/sql_audit_store_test.go
+++ b/store/sql_audit_store_test.go
@@ -5,6 +5,7 @@ package store
import (
"github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
"testing"
"time"
)
@@ -13,19 +14,19 @@ func TestSqlAuditStore(t *testing.T) {
Setup()
audit := &model.Audit{UserId: model.NewId(), IpAddress: "ipaddress", Action: "Action"}
- Must(store.Audit().Save(audit))
+ Must(store.Audit().Save(utils.T, audit))
time.Sleep(100 * time.Millisecond)
- Must(store.Audit().Save(audit))
+ Must(store.Audit().Save(utils.T, audit))
time.Sleep(100 * time.Millisecond)
- Must(store.Audit().Save(audit))
+ Must(store.Audit().Save(utils.T, audit))
time.Sleep(100 * time.Millisecond)
audit.ExtraInfo = "extra"
time.Sleep(100 * time.Millisecond)
- Must(store.Audit().Save(audit))
+ Must(store.Audit().Save(utils.T, audit))
time.Sleep(100 * time.Millisecond)
- c := store.Audit().Get(audit.UserId, 100)
+ c := store.Audit().Get(utils.T, audit.UserId, 100)
result := <-c
audits := result.Data.(model.Audits)
@@ -37,7 +38,7 @@ func TestSqlAuditStore(t *testing.T) {
t.Fatal("Failed to save property for extra info")
}
- c = store.Audit().Get("missing", 100)
+ c = store.Audit().Get(utils.T, "missing", 100)
result = <-c
audits = result.Data.(model.Audits)
@@ -45,7 +46,7 @@ func TestSqlAuditStore(t *testing.T) {
t.Fatal("Should have returned empty because user_id is missing")
}
- if r2 := <-store.Audit().PermanentDeleteByUser(audit.UserId); r2.Err != nil {
+ if r2 := <-store.Audit().PermanentDeleteByUser(utils.T, audit.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
}
diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go
index 6302d2f4f..234396058 100644
--- a/store/sql_preference_store.go
+++ b/store/sql_preference_store.go
@@ -8,6 +8,7 @@ import (
"github.com/go-gorp/gorp"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
+ goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlPreferenceStore struct {
@@ -41,7 +42,7 @@ func (s SqlPreferenceStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_preferences_name", "Preferences", "Name")
}
-func (s SqlPreferenceStore) DeleteUnusedFeatures() {
+func (s SqlPreferenceStore) DeleteUnusedFeatures(T goi18n.TranslateFunc) {
l4g.Debug("Deleting any unused pre-release features")
sql := `DELETE
@@ -58,7 +59,7 @@ func (s SqlPreferenceStore) DeleteUnusedFeatures() {
s.GetMaster().Exec(sql, queryParams)
}
-func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel {
+func (s SqlPreferenceStore) Save(T goi18n.TranslateFunc, preferences *model.Preferences) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -70,7 +71,7 @@ func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel {
result.Err = model.NewAppError("SqlPreferenceStore.Save", "Unable to open transaction to save preferences", err.Error())
} else {
for _, preference := range *preferences {
- if upsertResult := s.save(transaction, &preference); upsertResult.Err != nil {
+ if upsertResult := s.save(T, transaction, &preference); upsertResult.Err != nil {
result = upsertResult
break
}
@@ -97,7 +98,7 @@ func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel {
return storeChannel
}
-func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
+func (s SqlPreferenceStore) save(T goi18n.TranslateFunc, transaction *gorp.Transaction, preference *model.Preference) StoreResult {
result := StoreResult{}
if result.Err = preference.IsValid(); result.Err != nil {
@@ -139,9 +140,9 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode
}
if count == 1 {
- s.update(transaction, preference)
+ s.update(T, transaction, preference)
} else {
- s.insert(transaction, preference)
+ s.insert(T, transaction, preference)
}
} else {
result.Err = model.NewAppError("SqlPreferenceStore.save", "We encountered an error while updating preferences",
@@ -151,7 +152,7 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode
return result
}
-func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
+func (s SqlPreferenceStore) insert(T goi18n.TranslateFunc, transaction *gorp.Transaction, preference *model.Preference) StoreResult {
result := StoreResult{}
if err := transaction.Insert(preference); err != nil {
@@ -167,7 +168,7 @@ func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *mo
return result
}
-func (s SqlPreferenceStore) update(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
+func (s SqlPreferenceStore) update(T goi18n.TranslateFunc, transaction *gorp.Transaction, preference *model.Preference) StoreResult {
result := StoreResult{}
if _, err := transaction.Update(preference); err != nil {
@@ -178,7 +179,7 @@ func (s SqlPreferenceStore) update(transaction *gorp.Transaction, preference *mo
return result
}
-func (s SqlPreferenceStore) Get(userId string, category string, name string) StoreChannel {
+func (s SqlPreferenceStore) Get(T goi18n.TranslateFunc, userId string, category string, name string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -207,7 +208,7 @@ func (s SqlPreferenceStore) Get(userId string, category string, name string) Sto
return storeChannel
}
-func (s SqlPreferenceStore) GetCategory(userId string, category string) StoreChannel {
+func (s SqlPreferenceStore) GetCategory(T goi18n.TranslateFunc, userId string, category string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -235,7 +236,7 @@ func (s SqlPreferenceStore) GetCategory(userId string, category string) StoreCha
return storeChannel
}
-func (s SqlPreferenceStore) GetAll(userId string) StoreChannel {
+func (s SqlPreferenceStore) GetAll(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -262,7 +263,7 @@ func (s SqlPreferenceStore) GetAll(userId string) StoreChannel {
return storeChannel
}
-func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) StoreChannel {
+func (s SqlPreferenceStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -280,7 +281,7 @@ func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) StoreChannel {
return storeChannel
}
-func (s SqlPreferenceStore) IsFeatureEnabled(feature, userId string) StoreChannel {
+func (s SqlPreferenceStore) IsFeatureEnabled(T goi18n.TranslateFunc, feature, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
diff --git a/store/sql_preference_store_test.go b/store/sql_preference_store_test.go
index ec9d1df6c..c93831b37 100644
--- a/store/sql_preference_store_test.go
+++ b/store/sql_preference_store_test.go
@@ -5,6 +5,7 @@ package store
import (
"github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
"testing"
)
@@ -27,24 +28,24 @@ func TestPreferenceSave(t *testing.T) {
Value: "value1b",
},
}
- if count := Must(store.Preference().Save(&preferences)); count != 2 {
+ if count := Must(store.Preference().Save(utils.T, &preferences)); count != 2 {
t.Fatal("got incorrect number of rows saved")
}
for _, preference := range preferences {
- if data := Must(store.Preference().Get(preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data {
+ if data := Must(store.Preference().Get(utils.T, preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data {
t.Fatal("got incorrect preference after first Save")
}
}
preferences[0].Value = "value2a"
preferences[1].Value = "value2b"
- if count := Must(store.Preference().Save(&preferences)); count != 2 {
+ if count := Must(store.Preference().Save(utils.T, &preferences)); count != 2 {
t.Fatal("got incorrect number of rows saved")
}
for _, preference := range preferences {
- if data := Must(store.Preference().Get(preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data {
+ if data := Must(store.Preference().Get(utils.T, preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data {
t.Fatal("got incorrect preference after second Save")
}
}
@@ -80,16 +81,16 @@ func TestPreferenceGet(t *testing.T) {
},
}
- Must(store.Preference().Save(&preferences))
+ Must(store.Preference().Save(utils.T, &preferences))
- if result := <-store.Preference().Get(userId, category, name); result.Err != nil {
+ if result := <-store.Preference().Get(utils.T, userId, category, name); result.Err != nil {
t.Fatal(result.Err)
} else if data := result.Data.(model.Preference); data != preferences[0] {
t.Fatal("got incorrect preference")
}
// make sure getting a missing preference fails
- if result := <-store.Preference().Get(model.NewId(), model.NewId(), model.NewId()); result.Err == nil {
+ if result := <-store.Preference().Get(utils.T, model.NewId(), model.NewId(), model.NewId()); result.Err == nil {
t.Fatal("no error on getting a missing preference")
}
}
@@ -127,9 +128,9 @@ func TestPreferenceGetCategory(t *testing.T) {
},
}
- Must(store.Preference().Save(&preferences))
+ Must(store.Preference().Save(utils.T, &preferences))
- if result := <-store.Preference().GetCategory(userId, category); result.Err != nil {
+ if result := <-store.Preference().GetCategory(utils.T, userId, category); result.Err != nil {
t.Fatal(result.Err)
} else if data := result.Data.(model.Preferences); len(data) != 2 {
t.Fatal("got the wrong number of preferences")
@@ -138,7 +139,7 @@ func TestPreferenceGetCategory(t *testing.T) {
}
// make sure getting a missing preference category doesn't fail
- if result := <-store.Preference().GetCategory(model.NewId(), model.NewId()); result.Err != nil {
+ if result := <-store.Preference().GetCategory(utils.T, model.NewId(), model.NewId()); result.Err != nil {
t.Fatal(result.Err)
} else if data := result.Data.(model.Preferences); len(data) != 0 {
t.Fatal("shouldn't have got any preferences")
@@ -178,9 +179,9 @@ func TestPreferenceGetAll(t *testing.T) {
},
}
- Must(store.Preference().Save(&preferences))
+ Must(store.Preference().Save(utils.T, &preferences))
- if result := <-store.Preference().GetAll(userId); result.Err != nil {
+ if result := <-store.Preference().GetAll(utils.T, userId); result.Err != nil {
t.Fatal(result.Err)
} else if data := result.Data.(model.Preferences); len(data) != 3 {
t.Fatal("got the wrong number of preferences")
@@ -226,9 +227,9 @@ func TestPreferenceDelete(t *testing.T) {
},
}
- Must(store.Preference().Save(&preferences))
+ Must(store.Preference().Save(utils.T, &preferences))
- if result := <-store.Preference().PermanentDeleteByUser(userId); result.Err != nil {
+ if result := <-store.Preference().PermanentDeleteByUser(utils.T, userId); result.Err != nil {
t.Fatal(result.Err)
}
}
@@ -276,29 +277,29 @@ func TestIsFeatureEnabled(t *testing.T) {
},
}
- Must(store.Preference().Save(&features))
+ Must(store.Preference().Save(utils.T, &features))
- if result := <-store.Preference().IsFeatureEnabled(feature1, userId); result.Err != nil {
+ if result := <-store.Preference().IsFeatureEnabled(utils.T, feature1, userId); result.Err != nil {
t.Fatal(result.Err)
} else if data := result.Data.(bool); data != true {
t.Fatalf("got incorrect setting for feature1, %v=%v", true, data)
}
- if result := <-store.Preference().IsFeatureEnabled(feature2, userId); result.Err != nil {
+ if result := <-store.Preference().IsFeatureEnabled(utils.T, feature2, userId); result.Err != nil {
t.Fatal(result.Err)
} else if data := result.Data.(bool); data != false {
t.Fatalf("got incorrect setting for feature2, %v=%v", false, data)
}
// make sure we get false if something different than "true" or "false" has been saved to database
- if result := <-store.Preference().IsFeatureEnabled(feature3, userId); result.Err != nil {
+ if result := <-store.Preference().IsFeatureEnabled(utils.T, feature3, userId); result.Err != nil {
t.Fatal(result.Err)
} else if data := result.Data.(bool); data != false {
t.Fatalf("got incorrect setting for feature3, %v=%v", false, data)
}
// make sure false is returned if a non-existent feature is queried
- if result := <-store.Preference().IsFeatureEnabled("someOtherFeature", userId); result.Err != nil {
+ if result := <-store.Preference().IsFeatureEnabled(utils.T, "someOtherFeature", userId); result.Err != nil {
t.Fatal(result.Err)
} else if data := result.Data.(bool); data != false {
t.Fatalf("got incorrect setting for non-existent feature 'someOtherFeature', %v=%v", false, data)
@@ -341,9 +342,9 @@ func TestDeleteUnusedFeatures(t *testing.T) {
},
}
- Must(store.Preference().Save(&features))
+ Must(store.Preference().Save(utils.T, &features))
- store.(*SqlStore).preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
+ store.(*SqlStore).preference.(*SqlPreferenceStore).DeleteUnusedFeatures(utils.T)
//make sure features with value "false" have actually been deleted from the database
if val, err := store.(*SqlStore).preference.(*SqlPreferenceStore).GetReplica().SelectInt(`SELECT COUNT(*)
diff --git a/store/sql_store.go b/store/sql_store.go
index d0471fa1e..92776cd23 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -15,7 +15,6 @@ import (
"encoding/json"
"errors"
"fmt"
- l4g "github.com/alecthomas/log4go"
"io"
sqltrace "log"
"math/rand"
@@ -23,6 +22,7 @@ import (
"strings"
"time"
+ l4g "github.com/alecthomas/log4go"
"github.com/go-gorp/gorp"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
@@ -148,7 +148,7 @@ func NewSqlStore() Store {
sqlStore.webhook.(*SqlWebhookStore).CreateIndexesIfNotExists()
sqlStore.preference.(*SqlPreferenceStore).CreateIndexesIfNotExists()
- sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
+ sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures(utils.T)
if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 {
sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion})
diff --git a/store/store.go b/store/store.go
index 179cfecd7..be35c6d59 100644
--- a/store/store.go
+++ b/store/store.go
@@ -4,9 +4,11 @@
package store
import (
+ "time"
+
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
- "time"
+ goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type StoreResult struct {
@@ -139,9 +141,9 @@ type SessionStore interface {
}
type AuditStore interface {
- Save(audit *model.Audit) StoreChannel
- Get(user_id string, limit int) StoreChannel
- PermanentDeleteByUser(userId string) StoreChannel
+ Save(T goi18n.TranslateFunc, audit *model.Audit) StoreChannel
+ Get(T goi18n.TranslateFunc, user_id string, limit int) StoreChannel
+ PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel
}
type OAuthStore interface {
@@ -183,10 +185,10 @@ type WebhookStore interface {
}
type PreferenceStore interface {
- Save(preferences *model.Preferences) StoreChannel
- Get(userId string, category string, name string) StoreChannel
- GetCategory(userId string, category string) StoreChannel
- GetAll(userId string) StoreChannel
- PermanentDeleteByUser(userId string) StoreChannel
- IsFeatureEnabled(feature, userId string) StoreChannel
+ Save(T goi18n.TranslateFunc, preferences *model.Preferences) StoreChannel
+ Get(T goi18n.TranslateFunc, userId string, category string, name string) StoreChannel
+ GetCategory(T goi18n.TranslateFunc, userId string, category string) StoreChannel
+ GetAll(T goi18n.TranslateFunc, userId string) StoreChannel
+ PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel
+ IsFeatureEnabled(T goi18n.TranslateFunc, feature, userId string) StoreChannel
}
diff --git a/web/web.go b/web/web.go
index 016e0c147..ee75a92e6 100644
--- a/web/web.go
+++ b/web/web.go
@@ -5,6 +5,12 @@ package web
import (
"fmt"
+ "html/template"
+ "net/http"
+ "net/url"
+ "strconv"
+ "strings"
+
l4g "github.com/alecthomas/log4go"
"github.com/gorilla/mux"
"github.com/mattermost/platform/api"
@@ -13,11 +19,6 @@ import (
"github.com/mattermost/platform/utils"
"github.com/mssola/user_agent"
"gopkg.in/fsnotify.v1"
- "html/template"
- "net/http"
- "net/url"
- "strconv"
- "strings"
)
var Templates *template.Template
@@ -241,7 +242,7 @@ func login(c *api.Context, w http.ResponseWriter, r *http.Request) {
if session != nil {
w.Header().Set(model.HEADER_TOKEN, session.Token)
lastViewChannelName := "town-square"
- if lastViewResult := <-api.Srv.Store.Preference().Get(session.UserId, model.PREFERENCE_CATEGORY_LAST, model.PREFERENCE_NAME_LAST_CHANNEL); lastViewResult.Err == nil {
+ if lastViewResult := <-api.Srv.Store.Preference().Get(c.T, session.UserId, model.PREFERENCE_CATEGORY_LAST, model.PREFERENCE_NAME_LAST_CHANNEL); lastViewResult.Err == nil {
if lastViewChannelResult := <-api.Srv.Store.Channel().Get(lastViewResult.Data.(model.Preference).Value); lastViewChannelResult.Err == nil {
lastViewChannelName = lastViewChannelResult.Data.(*model.Channel).Name
}