Commit aefbb541 authored by Corey Hulen's avatar Corey Hulen

Revert " PLT-7 adding loc for db calls"

parent 0b1aff3b
...@@ -128,7 +128,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -128,7 +128,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if result := <-Srv.Store.User().Get(c.T, c.Session.UserId); result.Err != nil { if result := <-Srv.Store.User().Get(c.Session.UserId); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
...@@ -157,9 +157,9 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -157,9 +157,9 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
rows[0] = &model.AnalyticsRow{"channel_open_count", 0} rows[0] = &model.AnalyticsRow{"channel_open_count", 0}
rows[1] = &model.AnalyticsRow{"channel_private_count", 0} rows[1] = &model.AnalyticsRow{"channel_private_count", 0}
rows[2] = &model.AnalyticsRow{"post_count", 0} rows[2] = &model.AnalyticsRow{"post_count", 0}
openChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_OPEN) openChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
privateChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_PRIVATE) privateChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
postChan := Srv.Store.Post().AnalyticsPostCount(c.T, teamId) postChan := Srv.Store.Post().AnalyticsPostCount(teamId)
if r := <-openChan; r.Err != nil { if r := <-openChan; r.Err != nil {
c.Err = r.Err c.Err = r.Err
...@@ -184,14 +184,14 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -184,14 +184,14 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(rows.ToJson())) w.Write([]byte(rows.ToJson()))
} else if name == "post_counts_day" { } else if name == "post_counts_day" {
if r := <-Srv.Store.Post().AnalyticsPostCountsByDay(c.T, teamId); r.Err != nil { if r := <-Srv.Store.Post().AnalyticsPostCountsByDay(teamId); r.Err != nil {
c.Err = r.Err c.Err = r.Err
return return
} else { } else {
w.Write([]byte(r.Data.(model.AnalyticsRows).ToJson())) w.Write([]byte(r.Data.(model.AnalyticsRows).ToJson()))
} }
} else if name == "user_counts_with_posts_day" { } else if name == "user_counts_with_posts_day" {
if r := <-Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(c.T, teamId); r.Err != nil { if r := <-Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId); r.Err != nil {
c.Err = r.Err c.Err = r.Err
return return
} else { } else {
......
...@@ -19,7 +19,7 @@ func TestGetLogs(t *testing.T) { ...@@ -19,7 +19,7 @@ func TestGetLogs(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
...@@ -63,7 +63,7 @@ func TestGetConfig(t *testing.T) { ...@@ -63,7 +63,7 @@ func TestGetConfig(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
...@@ -97,7 +97,7 @@ func TestSaveConfig(t *testing.T) { ...@@ -97,7 +97,7 @@ func TestSaveConfig(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
...@@ -131,7 +131,7 @@ func TestEmailTest(t *testing.T) { ...@@ -131,7 +131,7 @@ func TestEmailTest(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
...@@ -159,7 +159,7 @@ func TestGetAnalyticsStandard(t *testing.T) { ...@@ -159,7 +159,7 @@ func TestGetAnalyticsStandard(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
...@@ -225,7 +225,7 @@ func TestGetPostCount(t *testing.T) { ...@@ -225,7 +225,7 @@ func TestGetPostCount(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
...@@ -270,7 +270,7 @@ func TestUserCountsWithPostsByDay(t *testing.T) { ...@@ -270,7 +270,7 @@ func TestUserCountsWithPostsByDay(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
......
...@@ -31,7 +31,7 @@ func SetupBenchmark() (*model.Team, *model.User, *model.Channel) { ...@@ -31,7 +31,7 @@ func SetupBenchmark() (*model.Team, *model.User, *model.Channel) {
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
user := &model.User{TeamId: team.Id, Email: model.NewId() + "benchmark@test.com", Nickname: "Mr. Benchmarker", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "benchmark@test.com", Nickname: "Mr. Benchmarker", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
channel := &model.Channel{DisplayName: "Benchmark Channel", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} channel := &model.Channel{DisplayName: "Benchmark Channel", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel = Client.Must(Client.CreateChannel(channel)).Data.(*model.Channel) channel = Client.Must(Client.CreateChannel(channel)).Data.(*model.Channel)
......
...@@ -46,7 +46,7 @@ func CreateBasicUser(client *model.Client) *model.AppError { ...@@ -46,7 +46,7 @@ func CreateBasicUser(client *model.Client) *model.AppError {
if err != nil { if err != nil {
return err return err
} }
store.Must(Srv.Store.User().VerifyEmail(utils.T, result.Data.(*model.User).Id)) store.Must(Srv.Store.User().VerifyEmail(result.Data.(*model.User).Id))
} }
return nil return nil
} }
...@@ -73,7 +73,7 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) { ...@@ -73,7 +73,7 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
return nil, false return nil, false
} }
// We need to cheat to verify the user's email // We need to cheat to verify the user's email
store.Must(Srv.Store.User().VerifyEmail(utils.T, result.Data.(*model.User).Id)) store.Must(Srv.Store.User().VerifyEmail(result.Data.(*model.User).Id))
return result.Data.(*model.User), true return result.Data.(*model.User), true
} }
......
This diff is collapsed.
...@@ -140,7 +140,7 @@ func BenchmarkJoinChannel(b *testing.B) { ...@@ -140,7 +140,7 @@ func BenchmarkJoinChannel(b *testing.B) {
// Secondary test user to join channels created by primary test user // Secondary test user to join channels created by primary test user
user := &model.User{TeamId: team.Id, Email: model.NewId() + "random@test.com", Nickname: "That Guy", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "random@test.com", Nickname: "That Guy", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
// Benchmark Start // Benchmark Start
......
This diff is collapsed.
...@@ -79,7 +79,7 @@ func checkCommand(c *Context, command *model.Command) bool { ...@@ -79,7 +79,7 @@ func checkCommand(c *Context, command *model.Command) bool {
} }
if len(command.ChannelId) > 0 { if len(command.ChannelId) > 0 {
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, command.ChannelId, c.Session.UserId) cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, command.ChannelId, c.Session.UserId)
if !c.HasPermissionsToChannel(cchan, "checkCommand") { if !c.HasPermissionsToChannel(cchan, "checkCommand") {
return true return true
...@@ -269,7 +269,7 @@ func joinCommand(c *Context, command *model.Command) bool { ...@@ -269,7 +269,7 @@ func joinCommand(c *Context, command *model.Command) bool {
startsWith = parts[1] startsWith = parts[1]
} }
if result := <-Srv.Store.Channel().GetMoreChannels(c.T, c.Session.TeamId, c.Session.UserId); result.Err != nil { if result := <-Srv.Store.Channel().GetMoreChannels(c.Session.TeamId, c.Session.UserId); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return false return false
} else { } else {
...@@ -544,7 +544,7 @@ func loadTestPostsCommand(c *Context, command *model.Command) bool { ...@@ -544,7 +544,7 @@ func loadTestPostsCommand(c *Context, command *model.Command) bool {
} }
var usernames []string var usernames []string
if result := <-Srv.Store.User().GetProfiles(c.T, c.Session.TeamId); result.Err == nil { if result := <-Srv.Store.User().GetProfiles(c.Session.TeamId); result.Err == nil {
profileUsers := result.Data.(map[string]*model.User) profileUsers := result.Data.(map[string]*model.User)
usernames = make([]string, len(profileUsers)) usernames = make([]string, len(profileUsers))
i := 0 i := 0
......
...@@ -21,7 +21,7 @@ func TestSuggestRootCommands(t *testing.T) { ...@@ -21,7 +21,7 @@ func TestSuggestRootCommands(t *testing.T) {
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id)) store.Must(Srv.Store.User().VerifyEmail(user1.Id))
Client.LoginByEmail(team.Name, user1.Email, "pwd") Client.LoginByEmail(team.Name, user1.Email, "pwd")
...@@ -70,7 +70,7 @@ func TestLogoutCommands(t *testing.T) { ...@@ -70,7 +70,7 @@ func TestLogoutCommands(t *testing.T) {
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id)) store.Must(Srv.Store.User().VerifyEmail(user1.Id))
Client.LoginByEmail(team.Name, user1.Email, "pwd") Client.LoginByEmail(team.Name, user1.Email, "pwd")
...@@ -88,7 +88,7 @@ func TestJoinCommands(t *testing.T) { ...@@ -88,7 +88,7 @@ func TestJoinCommands(t *testing.T) {
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id)) store.Must(Srv.Store.User().VerifyEmail(user1.Id))
Client.LoginByEmail(team.Name, user1.Email, "pwd") Client.LoginByEmail(team.Name, user1.Email, "pwd")
...@@ -102,7 +102,7 @@ func TestJoinCommands(t *testing.T) { ...@@ -102,7 +102,7 @@ func TestJoinCommands(t *testing.T) {
user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id)) store.Must(Srv.Store.User().VerifyEmail(user1.Id))
data := make(map[string]string) data := make(map[string]string)
data["user_id"] = user2.Id data["user_id"] = user2.Id
...@@ -164,7 +164,7 @@ func TestEchoCommand(t *testing.T) { ...@@ -164,7 +164,7 @@ func TestEchoCommand(t *testing.T) {
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id)) store.Must(Srv.Store.User().VerifyEmail(user1.Id))
Client.LoginByEmail(team.Name, user1.Email, "pwd") Client.LoginByEmail(team.Name, user1.Email, "pwd")
...@@ -202,7 +202,7 @@ func TestLoadTestUrlCommand(t *testing.T) { ...@@ -202,7 +202,7 @@ func TestLoadTestUrlCommand(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id)) store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd") Client.LoginByEmail(team.Name, user.Email, "pwd")
......
...@@ -162,7 +162,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -162,7 +162,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
if len(token) != 0 { if len(token) != 0 {
session := GetSession(c.T, token) session := GetSession(token)
if session == nil || session.IsExpired() { if session == nil || session.IsExpired() {
c.RemoveSessionCookie(w, r) c.RemoveSessionCookie(w, r)
...@@ -195,7 +195,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -195,7 +195,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if c.Err == nil && h.isUserActivity && token != "" && len(c.Session.UserId) > 0 { if c.Err == nil && h.isUserActivity && token != "" && len(c.Session.UserId) > 0 {
go func() { go func() {
if err := (<-Srv.Store.User().UpdateUserAndSessionActivity(c.T, c.Session.UserId, c.Session.Id, model.GetMillis())).Err; err != nil { if err := (<-Srv.Store.User().UpdateUserAndSessionActivity(c.Session.UserId, c.Session.Id, model.GetMillis())).Err; err != nil {
l4g.Error("Failed to update LastActivityAt for user_id=%v and session_id=%v, err=%v", c.Session.UserId, c.Session.Id, err) l4g.Error("Failed to update LastActivityAt for user_id=%v and session_id=%v, err=%v", c.Session.UserId, c.Session.Id, err)
} }
}() }()
...@@ -233,7 +233,7 @@ func GetProtocol(r *http.Request) string { ...@@ -233,7 +233,7 @@ func GetProtocol(r *http.Request) string {
func (c *Context) LogAudit(extraInfo 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} 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(c.T, audit); r.Err != nil { if r := <-Srv.Store.Audit().Save(audit); r.Err != nil {
c.LogError(r.Err) c.LogError(r.Err)
} }
} }
...@@ -245,7 +245,7 @@ func (c *Context) LogAuditWithUserId(userId, extraInfo string) { ...@@ -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} audit := &model.Audit{UserId: userId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id}
if r := <-Srv.Store.Audit().Save(c.T, audit); r.Err != nil { if r := <-Srv.Store.Audit().Save(audit); r.Err != nil {
c.LogError(r.Err) c.LogError(r.Err)
} }
} }
...@@ -387,7 +387,7 @@ func (c *Context) setTeamURL(url string, valid bool) { ...@@ -387,7 +387,7 @@ func (c *Context) setTeamURL(url string, valid bool) {
} }
func (c *Context) SetTeamURLFromSession() { func (c *Context) SetTeamURLFromSession() {
if result := <-Srv.Store.Team().Get(c.T, c.Session.TeamId); result.Err == nil { if result := <-Srv.Store.Team().Get(c.Session.TeamId); result.Err == nil {
c.setTeamURL(c.GetSiteURL()+"/"+result.Data.(*model.Team).Name, true) c.setTeamURL(c.GetSiteURL()+"/"+result.Data.(*model.Team).Name, true)
} }
} }
...@@ -515,14 +515,14 @@ func Handle404(w http.ResponseWriter, r *http.Request) { ...@@ -515,14 +515,14 @@ func Handle404(w http.ResponseWriter, r *http.Request) {
RenderWebError(err, w, r) RenderWebError(err, w, r)
} }
func GetSession(T goi18n.TranslateFunc, token string) *model.Session { func GetSession(token string) *model.Session {
var session *model.Session var session *model.Session
if ts, ok := sessionCache.Get(token); ok { if ts, ok := sessionCache.Get(token); ok {
session = ts.(*model.Session) session = ts.(*model.Session)
} }
if session == nil { if session == nil {
if sessionResult := <-Srv.Store.Session().Get(T, token); sessionResult.Err != nil { if sessionResult := <-Srv.Store.Session().Get(token); sessionResult.Err != nil {
l4g.Error("Invalid session token=" + token + ", err=" + sessionResult.Err.DetailedError) l4g.Error("Invalid session token=" + token + ", err=" + sessionResult.Err.DetailedError)
} else { } else {
session = sessionResult.Data.(*model.Session) session = sessionResult.Data.(*model.Session)
...@@ -551,9 +551,9 @@ func GetMultiSessionCookieTokens(r *http.Request) []string { ...@@ -551,9 +551,9 @@ func GetMultiSessionCookieTokens(r *http.Request) []string {
return []string{} return []string{}
} }
func FindMultiSessionForTeamId(T goi18n.TranslateFunc, r *http.Request, teamId string) (int64, *model.Session) { func FindMultiSessionForTeamId(r *http.Request, teamId string) (int64, *model.Session) {
for index, token := range GetMultiSessionCookieTokens(r) { for index, token := range GetMultiSessionCookieTokens(r) {
s := GetSession(T, token) s := GetSession(token)
if s != nil && !s.IsExpired() && s.TeamId == teamId { if s != nil && !s.IsExpired() && s.TeamId == teamId {
return int64(index), s return int64(index), s
} }
......
...@@ -6,12 +6,10 @@ package api ...@@ -6,12 +6,10 @@ package api
import ( import (
"archive/zip" "archive/zip"
"encoding/json" "encoding/json"
"io"
"os"
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils" "github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n" "io"
"os"
) )
const ( const (
...@@ -53,19 +51,19 @@ func ExportOptionsFromJson(data io.Reader) *ExportOptions { ...@@ -53,19 +51,19 @@ func ExportOptionsFromJson(data io.Reader) *ExportOptions {
return &o return &o
} }
func ExportToFile(T goi18n.TranslateFunc, options *ExportOptions) (link string, err *model.AppError) { func ExportToFile(options *ExportOptions) (link string, err *model.AppError) {
// Open file for export // Open file for export
if file, err := openFileWriteStream(EXPORT_PATH + EXPORT_FILENAME); err != nil { if file, err := openFileWriteStream(EXPORT_PATH + EXPORT_FILENAME); err != nil {
return "", err return "", err
} else { } else {
defer closeFileWriteStream(file) defer closeFileWriteStream(file)
ExportToWriter(T, file, options) ExportToWriter(file, options)
} }
return "/api/v1/files/get_export", nil return "/api/v1/files/get_export", nil
} }
func ExportToWriter(T goi18n.TranslateFunc, w io.Writer, options *ExportOptions) *model.AppError { func ExportToWriter(w io.Writer, options *ExportOptions) *model.AppError {
// Open a writer to write to zip file // Open a writer to write to zip file
zipWriter := zip.NewWriter(w) zipWriter := zip.NewWriter(w)
defer zipWriter.Close() defer zipWriter.Close()
...@@ -80,23 +78,23 @@ func ExportToWriter(T goi18n.TranslateFunc, w io.Writer, options *ExportOptions) ...@@ -80,23 +78,23 @@ func ExportToWriter(T goi18n.TranslateFunc, w io.Writer, options *ExportOptions)
} }
// Export Teams // Export Teams
ExportTeams(T, zipWriter, options) ExportTeams(zipWriter, options)
return nil return nil
} }
func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOptions) *model.AppError { func ExportTeams(writer ExportWriter, options *ExportOptions) *model.AppError {
// Get the teams // Get the teams
var teams []*model.Team var teams []*model.Team
if len(options.TeamsToExport) == 0 { if len(options.TeamsToExport) == 0 {
if result := <-Srv.Store.Team().GetAll(T); result.Err != nil { if result := <-Srv.Store.Team().GetAll(); result.Err != nil {
return result.Err return result.Err
} else { } else {
teams = result.Data.([]*model.Team) teams = result.Data.([]*model.Team)
} }
} else { } else {
for _, teamId := range options.TeamsToExport { for _, teamId := range options.TeamsToExport {
if result := <-Srv.Store.Team().Get(T, teamId); result.Err != nil { if result := <-Srv.Store.Team().Get(teamId); result.Err != nil {
return result.Err return result.Err
} else { } else {
team := result.Data.(*model.Team) team := result.Data.(*model.Team)
...@@ -122,10 +120,10 @@ func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOpt ...@@ -122,10 +120,10 @@ func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOpt
// Export the channels, local storage and users // Export the channels, local storage and users
for _, team := range teams { for _, team := range teams {
if err := ExportChannels(T, writer, options, team.Id); err != nil { if err := ExportChannels(writer, options, team.Id); err != nil {
return err return err
} }
if err := ExportUsers(T, writer, options, team.Id); err != nil { if err := ExportUsers(writer, options, team.Id); err != nil {
return err return err
} }
if err := ExportLocalStorage(writer, options, team.Id); err != nil { if err := ExportLocalStorage(writer, options, team.Id); err != nil {
...@@ -136,18 +134,18 @@ func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOpt ...@@ -136,18 +134,18 @@ func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOpt
return nil return nil
} }
func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOptions, teamId string) *model.AppError { func ExportChannels(writer ExportWriter, options *ExportOptions, teamId string) *model.AppError {
// Get the channels // Get the channels
var channels []*model.Channel var channels []*model.Channel
if len(options.ChannelsToExport) == 0 { if len(options.ChannelsToExport) == 0 {
if result := <-Srv.Store.Channel().GetForExport(T, teamId); result.Err != nil { if result := <-Srv.Store.Channel().GetForExport(teamId); result.Err != nil {
return result.Err return result.Err
} else { } else {
channels = result.Data.([]*model.Channel) channels = result.Data.([]*model.Channel)
} }
} else { } else {
for _, channelId := range options.ChannelsToExport { for _, channelId := range options.ChannelsToExport {
if result := <-Srv.Store.Channel().Get(T, channelId); result.Err != nil { if result := <-Srv.Store.Channel().Get(channelId); result.Err != nil {
return result.Err return result.Err
} else { } else {
channel := result.Data.(*model.Channel) channel := result.Data.(*model.Channel)
...@@ -158,7 +156,7 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export ...@@ -158,7 +156,7 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
for i := range channels { for i := range channels {
// Get members // Get members
mchan := Srv.Store.Channel().GetMembers(T, channels[i].Id) mchan := Srv.Store.Channel().GetMembers(channels[i].Id)
// Sanitize // Sanitize
channels[i].PreExport() channels[i].PreExport()
...@@ -192,7 +190,7 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export ...@@ -192,7 +190,7 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
} }
for _, channel := range channels { for _, channel := range channels {
if err := ExportPosts(T, writer, options, channel.Id); err != nil { if err := ExportPosts(writer, options, channel.Id); err != nil {
return err return err
} }
} }
...@@ -200,10 +198,10 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export ...@@ -200,10 +198,10 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
return nil return nil
} }
func ExportPosts(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOptions, channelId string) *model.AppError { func ExportPosts(writer ExportWriter, options *ExportOptions, channelId string) *model.AppError {
// Get the posts // Get the posts