diff options
author | =Corey Hulen <corey@hulen.com> | 2016-01-20 10:18:11 -0600 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2016-01-20 10:18:11 -0600 |
commit | 3ac5ecf0e98823cab22c77d3a56393cbe6bbc19a (patch) | |
tree | cc580dd16ec079650fb58f3f48c559d11659579a /store | |
parent | 11c035aef45fbc6dfbc360123611108a199eca79 (diff) | |
download | chat-3ac5ecf0e98823cab22c77d3a56393cbe6bbc19a.tar.gz chat-3ac5ecf0e98823cab22c77d3a56393cbe6bbc19a.tar.bz2 chat-3ac5ecf0e98823cab22c77d3a56393cbe6bbc19a.zip |
PLT-7 adding loc db calls for session table
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_session_store.go | 23 | ||||
-rw-r--r-- | store/sql_session_store_test.go | 53 | ||||
-rw-r--r-- | store/sql_user_store_test.go | 5 | ||||
-rw-r--r-- | store/store.go | 16 |
4 files changed, 50 insertions, 47 deletions
diff --git a/store/sql_session_store.go b/store/sql_session_store.go index 6b0a31443..e66b8529a 100644 --- a/store/sql_session_store.go +++ b/store/sql_session_store.go @@ -6,6 +6,7 @@ package store import ( l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/model" + goi18n "github.com/nicksnyder/go-i18n/i18n" ) type SqlSessionStore struct { @@ -37,7 +38,7 @@ func (me SqlSessionStore) CreateIndexesIfNotExists() { me.CreateIndexIfNotExists("idx_sessions_token", "Sessions", "Token") } -func (me SqlSessionStore) Save(session *model.Session) StoreChannel { +func (me SqlSessionStore) Save(T goi18n.TranslateFunc, session *model.Session) StoreChannel { storeChannel := make(StoreChannel) @@ -53,7 +54,7 @@ func (me SqlSessionStore) Save(session *model.Session) StoreChannel { session.PreSave() - if cur := <-me.CleanUpExpiredSessions(session.UserId); cur.Err != nil { + if cur := <-me.CleanUpExpiredSessions(T, session.UserId); cur.Err != nil { l4g.Error("Failed to cleanup sessions in Save err=%v", cur.Err) } @@ -70,7 +71,7 @@ func (me SqlSessionStore) Save(session *model.Session) StoreChannel { return storeChannel } -func (me SqlSessionStore) Get(sessionIdOrToken string) StoreChannel { +func (me SqlSessionStore) Get(T goi18n.TranslateFunc, sessionIdOrToken string) StoreChannel { storeChannel := make(StoreChannel) @@ -95,12 +96,12 @@ func (me SqlSessionStore) Get(sessionIdOrToken string) StoreChannel { return storeChannel } -func (me SqlSessionStore) GetSessions(userId string) StoreChannel { +func (me SqlSessionStore) GetSessions(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { - if cur := <-me.CleanUpExpiredSessions(userId); cur.Err != nil { + if cur := <-me.CleanUpExpiredSessions(T, userId); cur.Err != nil { l4g.Error("Failed to cleanup sessions in getSessions err=%v", cur.Err) } @@ -122,7 +123,7 @@ func (me SqlSessionStore) GetSessions(userId string) StoreChannel { return storeChannel } -func (me SqlSessionStore) Remove(sessionIdOrToken string) StoreChannel { +func (me SqlSessionStore) Remove(T goi18n.TranslateFunc, sessionIdOrToken string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -140,7 +141,7 @@ func (me SqlSessionStore) Remove(sessionIdOrToken string) StoreChannel { return storeChannel } -func (me SqlSessionStore) RemoveAllSessionsForTeam(teamId string) StoreChannel { +func (me SqlSessionStore) RemoveAllSessionsForTeam(T goi18n.TranslateFunc, teamId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -158,7 +159,7 @@ func (me SqlSessionStore) RemoveAllSessionsForTeam(teamId string) StoreChannel { return storeChannel } -func (me SqlSessionStore) PermanentDeleteSessionsByUser(userId string) StoreChannel { +func (me SqlSessionStore) PermanentDeleteSessionsByUser(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -176,7 +177,7 @@ func (me SqlSessionStore) PermanentDeleteSessionsByUser(userId string) StoreChan return storeChannel } -func (me SqlSessionStore) CleanUpExpiredSessions(userId string) StoreChannel { +func (me SqlSessionStore) CleanUpExpiredSessions(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -195,7 +196,7 @@ func (me SqlSessionStore) CleanUpExpiredSessions(userId string) StoreChannel { return storeChannel } -func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) StoreChannel { +func (me SqlSessionStore) UpdateLastActivityAt(T goi18n.TranslateFunc, sessionId string, time int64) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -214,7 +215,7 @@ func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) Sto return storeChannel } -func (me SqlSessionStore) UpdateRoles(userId, roles string) StoreChannel { +func (me SqlSessionStore) UpdateRoles(T goi18n.TranslateFunc, userId, roles string) StoreChannel { storeChannel := make(StoreChannel) go func() { diff --git a/store/sql_session_store_test.go b/store/sql_session_store_test.go index cec8e93b0..73ec59fb0 100644 --- a/store/sql_session_store_test.go +++ b/store/sql_session_store_test.go @@ -5,6 +5,7 @@ package store import ( "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" "testing" ) @@ -15,7 +16,7 @@ func TestSessionStoreSave(t *testing.T) { s1.UserId = model.NewId() s1.TeamId = model.NewId() - if err := (<-store.Session().Save(&s1)).Err; err != nil { + if err := (<-store.Session().Save(utils.T, &s1)).Err; err != nil { t.Fatal(err) } } @@ -26,20 +27,20 @@ func TestSessionGet(t *testing.T) { s1 := model.Session{} s1.UserId = model.NewId() s1.TeamId = model.NewId() - Must(store.Session().Save(&s1)) + Must(store.Session().Save(utils.T, &s1)) s2 := model.Session{} s2.UserId = s1.UserId s2.TeamId = s1.TeamId - Must(store.Session().Save(&s2)) + Must(store.Session().Save(utils.T, &s2)) s3 := model.Session{} s3.UserId = s1.UserId s3.TeamId = s1.TeamId s3.ExpiresAt = 1 - Must(store.Session().Save(&s3)) + Must(store.Session().Save(utils.T, &s3)) - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { + if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil { t.Fatal(rs1.Err) } else { if rs1.Data.(*model.Session).Id != s1.Id { @@ -47,7 +48,7 @@ func TestSessionGet(t *testing.T) { } } - if rs2 := (<-store.Session().GetSessions(s1.UserId)); rs2.Err != nil { + if rs2 := (<-store.Session().GetSessions(utils.T, s1.UserId)); rs2.Err != nil { t.Fatal(rs2.Err) } else { if len(rs2.Data.([]*model.Session)) != 2 { @@ -63,9 +64,9 @@ func TestSessionRemove(t *testing.T) { s1 := model.Session{} s1.UserId = model.NewId() s1.TeamId = model.NewId() - Must(store.Session().Save(&s1)) + Must(store.Session().Save(utils.T, &s1)) - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { + if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil { t.Fatal(rs1.Err) } else { if rs1.Data.(*model.Session).Id != s1.Id { @@ -73,9 +74,9 @@ func TestSessionRemove(t *testing.T) { } } - Must(store.Session().Remove(s1.Id)) + Must(store.Session().Remove(utils.T, s1.Id)) - if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil { + if rs2 := (<-store.Session().Get(utils.T, s1.Id)); rs2.Err == nil { t.Fatal("should have been removed") } } @@ -86,9 +87,9 @@ func TestSessionRemoveAll(t *testing.T) { s1 := model.Session{} s1.UserId = model.NewId() s1.TeamId = model.NewId() - Must(store.Session().Save(&s1)) + Must(store.Session().Save(utils.T, &s1)) - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { + if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil { t.Fatal(rs1.Err) } else { if rs1.Data.(*model.Session).Id != s1.Id { @@ -96,9 +97,9 @@ func TestSessionRemoveAll(t *testing.T) { } } - Must(store.Session().RemoveAllSessionsForTeam(s1.TeamId)) + Must(store.Session().RemoveAllSessionsForTeam(utils.T, s1.TeamId)) - if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil { + if rs2 := (<-store.Session().Get(utils.T, s1.Id)); rs2.Err == nil { t.Fatal("should have been removed") } } @@ -109,9 +110,9 @@ func TestSessionRemoveByUser(t *testing.T) { s1 := model.Session{} s1.UserId = model.NewId() s1.TeamId = model.NewId() - Must(store.Session().Save(&s1)) + Must(store.Session().Save(utils.T, &s1)) - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { + if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil { t.Fatal(rs1.Err) } else { if rs1.Data.(*model.Session).Id != s1.Id { @@ -119,9 +120,9 @@ func TestSessionRemoveByUser(t *testing.T) { } } - Must(store.Session().PermanentDeleteSessionsByUser(s1.UserId)) + Must(store.Session().PermanentDeleteSessionsByUser(utils.T, s1.UserId)) - if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil { + if rs2 := (<-store.Session().Get(utils.T, s1.Id)); rs2.Err == nil { t.Fatal("should have been removed") } } @@ -132,9 +133,9 @@ func TestSessionRemoveToken(t *testing.T) { s1 := model.Session{} s1.UserId = model.NewId() s1.TeamId = model.NewId() - Must(store.Session().Save(&s1)) + Must(store.Session().Save(utils.T, &s1)) - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { + if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil { t.Fatal(rs1.Err) } else { if rs1.Data.(*model.Session).Id != s1.Id { @@ -142,13 +143,13 @@ func TestSessionRemoveToken(t *testing.T) { } } - Must(store.Session().Remove(s1.Token)) + Must(store.Session().Remove(utils.T, s1.Token)) - if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil { + if rs2 := (<-store.Session().Get(utils.T, s1.Id)); rs2.Err == nil { t.Fatal("should have been removed") } - if rs3 := (<-store.Session().GetSessions(s1.UserId)); rs3.Err != nil { + if rs3 := (<-store.Session().GetSessions(utils.T, s1.UserId)); rs3.Err != nil { t.Fatal(rs3.Err) } else { if len(rs3.Data.([]*model.Session)) != 0 { @@ -163,13 +164,13 @@ func TestSessionStoreUpdateLastActivityAt(t *testing.T) { s1 := model.Session{} s1.UserId = model.NewId() s1.TeamId = model.NewId() - Must(store.Session().Save(&s1)) + Must(store.Session().Save(utils.T, &s1)) - if err := (<-store.Session().UpdateLastActivityAt(s1.Id, 1234567890)).Err; err != nil { + if err := (<-store.Session().UpdateLastActivityAt(utils.T, s1.Id, 1234567890)).Err; err != nil { t.Fatal(err) } - if r1 := <-store.Session().Get(s1.Id); r1.Err != nil { + if r1 := <-store.Session().Get(utils.T, s1.Id); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.Session).LastActivityAt != 1234567890 { diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go index d1ee5e647..12bc6d172 100644 --- a/store/sql_user_store_test.go +++ b/store/sql_user_store_test.go @@ -5,6 +5,7 @@ package store import ( "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" "strings" "testing" "time" @@ -161,7 +162,7 @@ func TestUserStoreUpdateUserAndSessionActivity(t *testing.T) { s1 := model.Session{} s1.UserId = u1.Id s1.TeamId = u1.TeamId - Must(store.Session().Save(&s1)) + Must(store.Session().Save(utils.T, &s1)) if err := (<-store.User().UpdateUserAndSessionActivity(u1.Id, s1.Id, 1234567890)).Err; err != nil { t.Fatal(err) @@ -175,7 +176,7 @@ func TestUserStoreUpdateUserAndSessionActivity(t *testing.T) { } } - if r2 := <-store.Session().Get(s1.Id); r2.Err != nil { + if r2 := <-store.Session().Get(utils.T, s1.Id); r2.Err != nil { t.Fatal(r2.Err) } else { if r2.Data.(*model.Session).LastActivityAt != 1234567890 { diff --git a/store/store.go b/store/store.go index a6162fb07..c6e3d1273 100644 --- a/store/store.go +++ b/store/store.go @@ -130,14 +130,14 @@ type UserStore interface { } type SessionStore interface { - Save(session *model.Session) StoreChannel - Get(sessionIdOrToken string) StoreChannel - GetSessions(userId string) StoreChannel - Remove(sessionIdOrToken string) StoreChannel - RemoveAllSessionsForTeam(teamId string) StoreChannel - PermanentDeleteSessionsByUser(teamId string) StoreChannel - UpdateLastActivityAt(sessionId string, time int64) StoreChannel - UpdateRoles(userId string, roles string) StoreChannel + Save(T goi18n.TranslateFunc, session *model.Session) StoreChannel + Get(T goi18n.TranslateFunc, sessionIdOrToken string) StoreChannel + GetSessions(T goi18n.TranslateFunc, userId string) StoreChannel + Remove(T goi18n.TranslateFunc, sessionIdOrToken string) StoreChannel + RemoveAllSessionsForTeam(T goi18n.TranslateFunc, teamId string) StoreChannel + PermanentDeleteSessionsByUser(T goi18n.TranslateFunc, teamId string) StoreChannel + UpdateLastActivityAt(T goi18n.TranslateFunc, sessionId string, time int64) StoreChannel + UpdateRoles(T goi18n.TranslateFunc, userId string, roles string) StoreChannel } type AuditStore interface { |