Revert " PLT-7 adding loc for db calls"

This commit is contained in:
Corey Hulen
2016-01-20 13:36:16 -06:00
parent 0b1aff3b24
commit aefbb541d0
56 changed files with 1254 additions and 1296 deletions

View File

@@ -128,7 +128,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
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
return
} else {
@@ -157,9 +157,9 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
rows[0] = &model.AnalyticsRow{"channel_open_count", 0}
rows[1] = &model.AnalyticsRow{"channel_private_count", 0}
rows[2] = &model.AnalyticsRow{"post_count", 0}
openChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_OPEN)
privateChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_PRIVATE)
postChan := Srv.Store.Post().AnalyticsPostCount(c.T, teamId)
openChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
privateChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
postChan := Srv.Store.Post().AnalyticsPostCount(teamId)
if r := <-openChan; r.Err != nil {
c.Err = r.Err
@@ -184,14 +184,14 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(rows.ToJson()))
} 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
return
} else {
w.Write([]byte(r.Data.(model.AnalyticsRows).ToJson()))
}
} 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
return
} else {

View File

@@ -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 = 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")
@@ -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 = 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")
@@ -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 = 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")
@@ -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 = 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")
@@ -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 = 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")
@@ -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 = 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")
@@ -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 = 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")

View File

@@ -31,7 +31,7 @@ func SetupBenchmark() (*model.Team, *model.User, *model.Channel) {
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 = 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")
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)

View File

@@ -46,7 +46,7 @@ func CreateBasicUser(client *model.Client) *model.AppError {
if err != nil {
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
}
@@ -73,7 +73,7 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
return nil, false
}
// 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
}

View File

@@ -5,14 +5,12 @@ package api
import (
"fmt"
"net/http"
"strconv"
"strings"
l4g "github.com/alecthomas/log4go"
"github.com/gorilla/mux"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
"net/http"
"strconv"
"strings"
)
const (
@@ -78,7 +76,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
func CreateChannel(c *Context, channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) {
if result := <-Srv.Store.Channel().Save(c.T, channel); result.Err != nil {
if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
return nil, result.Err
} else {
sc := result.Data.(*model.Channel)
@@ -87,7 +85,7 @@ func CreateChannel(c *Context, channel *model.Channel, addMember bool) (*model.C
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: c.Session.UserId,
Roles: model.CHANNEL_ROLE_ADMIN, NotifyProps: model.GetDefaultChannelNotifyProps()}
if cmresult := <-Srv.Store.Channel().SaveMember(c.T, cm); cmresult.Err != nil {
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
return nil, cmresult.Err
}
}
@@ -125,7 +123,7 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
return nil, model.NewAppError("CreateDirectChannel", "Invalid other user id ", otherUserId)
}
uc := Srv.Store.User().Get(c.T, otherUserId)
uc := Srv.Store.User().Get(otherUserId)
channel := new(model.Channel)
@@ -151,7 +149,7 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
NotifyProps: model.GetDefaultChannelNotifyProps(),
}
if result := <-Srv.Store.Channel().SaveDirectChannel(c.T, channel, cm1, cm2); result.Err != nil {
if result := <-Srv.Store.Channel().SaveDirectChannel(channel, cm1, cm2); result.Err != nil {
return nil, result.Err
} else {
return result.Data.(*model.Channel), nil
@@ -184,8 +182,8 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
sc := Srv.Store.Channel().Get(c.T, channel.Id)
cmc := Srv.Store.Channel().GetMember(c.T, channel.Id, c.Session.UserId)
sc := Srv.Store.Channel().Get(channel.Id)
cmc := Srv.Store.Channel().GetMember(channel.Id, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -235,7 +233,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannel.Type = channel.Type
}
if ucresult := <-Srv.Store.Channel().Update(c.T, oldChannel); ucresult.Err != nil {
if ucresult := <-Srv.Store.Channel().Update(oldChannel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -260,8 +258,8 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
sc := Srv.Store.Channel().Get(c.T, channelId)
cmc := Srv.Store.Channel().GetMember(c.T, channelId, c.Session.UserId)
sc := Srv.Store.Channel().Get(channelId)
cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -279,7 +277,7 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelHeader := channel.Header
channel.Header = channelHeader
if ucresult := <-Srv.Store.Channel().Update(c.T, channel); ucresult.Err != nil {
if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -292,7 +290,7 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
func PostUpdateChannelHeaderMessageAndForget(c *Context, channelId string, oldChannelHeader, newChannelHeader string) {
go func() {
uc := Srv.Store.User().Get(c.T, c.Session.UserId)
uc := Srv.Store.User().Get(c.Session.UserId)
if uresult := <-uc; uresult.Err != nil {
l4g.Error("Failed to retrieve user while trying to save update channel header message %v", uresult.Err)
@@ -335,8 +333,8 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
sc := Srv.Store.Channel().Get(c.T, channelId)
cmc := Srv.Store.Channel().GetMember(c.T, channelId, c.Session.UserId)
sc := Srv.Store.Channel().Get(channelId)
cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -354,7 +352,7 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
channel.Purpose = channelPurpose
if ucresult := <-Srv.Store.Channel().Update(c.T, channel); ucresult.Err != nil {
if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -368,10 +366,10 @@ func getChannels(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
if result := <-Srv.Store.Channel().GetChannels(c.T, c.Session.TeamId, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Channel().GetChannels(c.Session.TeamId, c.Session.UserId); result.Err != nil {
if result.Err.Message == "No channels were found" {
// lets make sure the user is valid
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.RemoveSessionCookie(w, r)
l4g.Error("Error in getting users profile for id=%v forcing logout", c.Session.UserId)
@@ -393,7 +391,7 @@ func getMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
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
return
} else if HandleEtag(result.Data.(*model.ChannelList).Etag(), w, r) {
@@ -409,7 +407,7 @@ func getChannelCounts(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
if result := <-Srv.Store.Channel().GetChannelCounts(c.T, c.Session.TeamId, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Channel().GetChannelCounts(c.Session.TeamId, c.Session.UserId); result.Err != nil {
c.Err = model.NewAppError("getChannelCounts", "Unable to get channel counts from the database", result.Err.Message)
return
} else if HandleEtag(result.Data.(*model.ChannelCounts).Etag(), w, r) {
@@ -439,8 +437,8 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
func JoinChannel(c *Context, channelId string, role string) {
sc := Srv.Store.Channel().Get(c.T, channelId)
uc := Srv.Store.User().Get(c.T, c.Session.UserId)
sc := Srv.Store.Channel().Get(channelId)
uc := Srv.Store.User().Get(c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -457,7 +455,7 @@ func JoinChannel(c *Context, channelId string, role string) {
}
if channel.Type == model.CHANNEL_OPEN {
if _, err := AddUserToChannel(c.T, user, channel); err != nil {
if _, err := AddUserToChannel(user, channel); err != nil {
c.Err = err
return
}
@@ -483,7 +481,7 @@ func PostUserAddRemoveMessageAndForget(c *Context, channelId string, message str
}()
}
func AddUserToChannel(T goi18n.TranslateFunc, user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
if channel.DeleteAt > 0 {
return nil, model.NewAppError("AddUserToChannel", "The channel has been archived or deleted", "")
}
@@ -493,7 +491,7 @@ func AddUserToChannel(T goi18n.TranslateFunc, user *model.User, channel *model.C
}
newMember := &model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, NotifyProps: model.GetDefaultChannelNotifyProps()}
if cmresult := <-Srv.Store.Channel().SaveMember(T, newMember); cmresult.Err != nil {
if cmresult := <-Srv.Store.Channel().SaveMember(newMember); cmresult.Err != nil {
l4g.Error("Failed to add member user_id=%v channel_id=%v err=%v", user.Id, channel.Id, cmresult.Err)
return nil, model.NewAppError("AddUserToChannel", "Failed to add user to channel", "")
}
@@ -508,29 +506,29 @@ func AddUserToChannel(T goi18n.TranslateFunc, user *model.User, channel *model.C
return newMember, nil
}
func JoinDefaultChannels(T goi18n.TranslateFunc, user *model.User, channelRole string) *model.AppError {
func JoinDefaultChannels(user *model.User, channelRole string) *model.AppError {
// We don't call JoinChannel here since c.Session is not populated on user creation
var err *model.AppError = nil
if result := <-Srv.Store.Channel().GetByName(T, user.TeamId, "town-square"); result.Err != nil {
if result := <-Srv.Store.Channel().GetByName(user.TeamId, "town-square"); result.Err != nil {
err = result.Err
} else {
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id,
Roles: channelRole, NotifyProps: model.GetDefaultChannelNotifyProps()}
if cmResult := <-Srv.Store.Channel().SaveMember(T, cm); cmResult.Err != nil {
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
err = cmResult.Err
}
}
if result := <-Srv.Store.Channel().GetByName(T, user.TeamId, "off-topic"); result.Err != nil {
if result := <-Srv.Store.Channel().GetByName(user.TeamId, "off-topic"); result.Err != nil {
err = result.Err
} else {
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id,
Roles: channelRole, NotifyProps: model.GetDefaultChannelNotifyProps()}
if cmResult := <-Srv.Store.Channel().SaveMember(T, cm); cmResult.Err != nil {
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
err = cmResult.Err
}
}
@@ -543,8 +541,8 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
sc := Srv.Store.Channel().Get(c.T, id)
uc := Srv.Store.User().Get(c.T, c.Session.UserId)
sc := Srv.Store.Channel().Get(id)
uc := Srv.Store.User().Get(c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -572,12 +570,12 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if cmresult := <-Srv.Store.Channel().RemoveMember(c.T, channel.Id, c.Session.UserId); cmresult.Err != nil {
if cmresult := <-Srv.Store.Channel().RemoveMember(channel.Id, c.Session.UserId); cmresult.Err != nil {
c.Err = cmresult.Err
return
}
RemoveUserFromChannel(c.T, c.Session.UserId, c.Session.UserId, channel)
RemoveUserFromChannel(c.Session.UserId, c.Session.UserId, channel)
PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(`%v has left the channel.`, user.Username))
@@ -592,11 +590,11 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
sc := Srv.Store.Channel().Get(c.T, id)
scm := Srv.Store.Channel().GetMember(c.T, id, c.Session.UserId)
uc := Srv.Store.User().Get(c.T, c.Session.UserId)
ihc := Srv.Store.Webhook().GetIncomingByChannel(c.T, id)
ohc := Srv.Store.Webhook().GetOutgoingByChannel(c.T, id)
sc := Srv.Store.Channel().Get(id)
scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
uc := Srv.Store.User().Get(c.Session.UserId)
ihc := Srv.Store.Webhook().GetIncomingByChannel(id)
ohc := Srv.Store.Webhook().GetOutgoingByChannel(id)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -645,7 +643,7 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
now := model.GetMillis()
for _, hook := range incomingHooks {
go func() {
if result := <-Srv.Store.Webhook().DeleteIncoming(c.T, hook.Id, now); result.Err != nil {
if result := <-Srv.Store.Webhook().DeleteIncoming(hook.Id, now); result.Err != nil {
l4g.Error("Encountered error deleting incoming webhook, id=" + hook.Id)
}
}()
@@ -653,13 +651,13 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
for _, hook := range outgoingHooks {
go func() {
if result := <-Srv.Store.Webhook().DeleteOutgoing(c.T, hook.Id, now); result.Err != nil {
if result := <-Srv.Store.Webhook().DeleteOutgoing(hook.Id, now); result.Err != nil {
l4g.Error("Encountered error deleting outgoing webhook, id=" + hook.Id)
}
}()
}
if dresult := <-Srv.Store.Channel().Delete(c.T, channel.Id, model.GetMillis()); dresult.Err != nil {
if dresult := <-Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); dresult.Err != nil {
c.Err = dresult.Err
return
}
@@ -685,7 +683,7 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
Srv.Store.Channel().UpdateLastViewedAt(c.T, id, c.Session.UserId)
Srv.Store.Channel().UpdateLastViewedAt(id, c.Session.UserId)
preference := model.Preference{
UserId: c.Session.UserId,
@@ -694,7 +692,7 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) {
Value: id,
}
Srv.Store.Preference().Save(c.T, &model.Preferences{preference})
Srv.Store.Preference().Save(&model.Preferences{preference})
message := model.NewMessage(c.Session.TeamId, id, c.Session.UserId, model.ACTION_CHANNEL_VIEWED)
message.Add("channel_id", id)
@@ -711,8 +709,8 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
id := params["id"]
//pchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
cchan := Srv.Store.Channel().Get(c.T, id)
cmchan := Srv.Store.Channel().GetMember(c.T, id, c.Session.UserId)
cchan := Srv.Store.Channel().Get(id)
cmchan := Srv.Store.Channel().GetMember(id, c.Session.UserId)
if cresult := <-cchan; cresult.Err != nil {
c.Err = cresult.Err
@@ -751,7 +749,7 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) {
memberLimit = int(memberLimitInt64)
}
sc := Srv.Store.Channel().Get(c.T, id)
sc := Srv.Store.Channel().Get(id)
var channel *model.Channel
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -765,9 +763,9 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
scm := Srv.Store.Channel().GetMember(c.T, id, c.Session.UserId)
ecm := Srv.Store.Channel().GetExtraMembers(c.T, id, memberLimit)
ccm := Srv.Store.Channel().GetMemberCount(c.T, id)
scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
ecm := Srv.Store.Channel().GetExtraMembers(id, memberLimit)
ccm := Srv.Store.Channel().GetMemberCount(id)
if cmresult := <-scm; cmresult.Err != nil {
c.Err = cmresult.Err
@@ -816,10 +814,10 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
sc := Srv.Store.Channel().Get(c.T, id)
ouc := Srv.Store.User().Get(c.T, c.Session.UserId)
nuc := Srv.Store.User().Get(c.T, userId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
sc := Srv.Store.Channel().Get(id)
ouc := Srv.Store.User().Get(c.Session.UserId)
nuc := Srv.Store.User().Get(userId)
// Only need to be a member of the channel to add a new member
if !c.HasPermissionsToChannel(cchan, "addMember") {
@@ -842,7 +840,7 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
oUser := oresult.Data.(*model.User)
cm, err := AddUserToChannel(c.T, nUser, channel)
cm, err := AddUserToChannel(nUser, channel)
if err != nil {
c.Err = err
return
@@ -852,7 +850,7 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(`%v added to the channel by %v`, nUser.Username, oUser.Username))
<-Srv.Store.Channel().UpdateLastViewedAt(c.T, id, oUser.Id)
<-Srv.Store.Channel().UpdateLastViewedAt(id, oUser.Id)
w.Write([]byte(cm.ToJson()))
}
}
@@ -870,8 +868,8 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
sc := Srv.Store.Channel().Get(c.T, channelId)
cmc := Srv.Store.Channel().GetMember(c.T, channelId, c.Session.UserId)
sc := Srv.Store.Channel().Get(channelId)
cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -893,7 +891,7 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := RemoveUserFromChannel(c.T, userIdToRemove, c.Session.UserId, channel); err != nil {
if err := RemoveUserFromChannel(userIdToRemove, c.Session.UserId, channel); err != nil {
c.Err = model.NewAppError("updateChannel", "Unable to remove user.", err.Message)
return
}
@@ -908,12 +906,12 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
func RemoveUserFromChannel(T goi18n.TranslateFunc, userIdToRemove string, removerUserId string, channel *model.Channel) *model.AppError {
func RemoveUserFromChannel(userIdToRemove string, removerUserId string, channel *model.Channel) *model.AppError {
if channel.DeleteAt > 0 {
return model.NewAppError("updateChannel", "The channel has been archived or deleted", "")
}
if cmresult := <-Srv.Store.Channel().RemoveMember(T, channel.Id, userIdToRemove); cmresult.Err != nil {
if cmresult := <-Srv.Store.Channel().RemoveMember(channel.Id, userIdToRemove); cmresult.Err != nil {
return cmresult.Err
}
@@ -941,7 +939,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
if !c.HasPermissionsToUser(userId, "updateNotifyLevel") {
return
@@ -951,7 +949,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
result := <-Srv.Store.Channel().GetMember(c.T, channelId, userId)
result := <-Srv.Store.Channel().GetMember(channelId, userId)
if result.Err != nil {
c.Err = result.Err
return
@@ -968,7 +966,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
member.NotifyProps["desktop"] = desktop
}
if result := <-Srv.Store.Channel().UpdateMember(c.T, &member); result.Err != nil {
if result := <-Srv.Store.Channel().UpdateMember(&member); result.Err != nil {
c.Err = result.Err
return
} else {

View File

@@ -140,7 +140,7 @@ func BenchmarkJoinChannel(b *testing.B) {
// 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 = 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")
// Benchmark Start

View File

@@ -24,7 +24,7 @@ func TestCreateChannel(t *testing.T) {
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)
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")
@@ -101,11 +101,11 @@ func TestCreateDirectChannel(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id))
store.Must(Srv.Store.User().VerifyEmail(user.Id))
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd")
@@ -156,15 +156,15 @@ func TestUpdateChannel(t *testing.T) {
userTeamAdmin := &model.User{TeamId: team.Id, Email: team.Email, Nickname: "Corey Hulen", Password: "pwd"}
userTeamAdmin = Client.Must(Client.CreateUser(userTeamAdmin, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userTeamAdmin.Id))
store.Must(Srv.Store.User().VerifyEmail(userTeamAdmin.Id))
userChannelAdmin := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
userChannelAdmin = Client.Must(Client.CreateUser(userChannelAdmin, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userChannelAdmin.Id))
store.Must(Srv.Store.User().VerifyEmail(userChannelAdmin.Id))
userStd := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
userStd = Client.Must(Client.CreateUser(userStd, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userStd.Id))
store.Must(Srv.Store.User().VerifyEmail(userStd.Id))
userStd.Roles = ""
Client.LoginByEmail(team.Name, userChannelAdmin.Email, "pwd")
@@ -238,7 +238,7 @@ func TestUpdateChannelHeader(t *testing.T) {
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)
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")
@@ -278,7 +278,7 @@ func TestUpdateChannelHeader(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
@@ -297,7 +297,7 @@ func TestUpdateChannelPurpose(t *testing.T) {
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)
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")
@@ -337,7 +337,7 @@ func TestUpdateChannelPurpose(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
@@ -356,7 +356,7 @@ func TestGetChannel(t *testing.T) {
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)
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")
@@ -419,7 +419,7 @@ func TestGetMoreChannel(t *testing.T) {
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)
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")
@@ -431,7 +431,7 @@ func TestGetMoreChannel(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
@@ -463,7 +463,7 @@ func TestGetChannelCounts(t *testing.T) {
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)
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")
@@ -504,7 +504,7 @@ func TestJoinChannel(t *testing.T) {
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)
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")
@@ -516,7 +516,7 @@ func TestJoinChannel(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
@@ -548,7 +548,7 @@ func TestLeaveChannel(t *testing.T) {
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)
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")
@@ -560,7 +560,7 @@ func TestLeaveChannel(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
@@ -597,11 +597,11 @@ func TestDeleteChannel(t *testing.T) {
userTeamAdmin := &model.User{TeamId: team.Id, Email: team.Email, Nickname: "Corey Hulen", Password: "pwd"}
userTeamAdmin = Client.Must(Client.CreateUser(userTeamAdmin, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userTeamAdmin.Id))
store.Must(Srv.Store.User().VerifyEmail(userTeamAdmin.Id))
userChannelAdmin := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
userChannelAdmin = Client.Must(Client.CreateUser(userChannelAdmin, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userChannelAdmin.Id))
store.Must(Srv.Store.User().VerifyEmail(userChannelAdmin.Id))
Client.LoginByEmail(team.Name, userChannelAdmin.Email, "pwd")
@@ -633,7 +633,7 @@ func TestDeleteChannel(t *testing.T) {
userStd := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
userStd = Client.Must(Client.CreateUser(userStd, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userStd.Id))
store.Must(Srv.Store.User().VerifyEmail(userStd.Id))
Client.LoginByEmail(team.Name, userStd.Email, "pwd")
@@ -667,7 +667,7 @@ func TestGetChannelExtraInfo(t *testing.T) {
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)
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")
@@ -703,7 +703,7 @@ func TestGetChannelExtraInfo(t *testing.T) {
user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "tester2@test.com", Nickname: "Tester 2", Password: "pwd"}
user2 = Client2.Must(Client2.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client2.LoginByEmail(team.Name, user2.Email, "pwd")
Client2.Must(Client2.JoinChannel(channel1.Id))
@@ -791,7 +791,7 @@ func TestAddChannelMember(t *testing.T) {
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)
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")
@@ -800,7 +800,7 @@ func TestAddChannelMember(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
if _, err := Client.AddChannelMember(channel1.Id, user2.Id); err != nil {
t.Fatal(err)
@@ -849,11 +849,11 @@ func TestRemoveChannelMember(t *testing.T) {
userTeamAdmin := &model.User{TeamId: team.Id, Email: team.Email, Nickname: "Corey Hulen", Password: "pwd"}
userTeamAdmin = Client.Must(Client.CreateUser(userTeamAdmin, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userTeamAdmin.Id))
store.Must(Srv.Store.User().VerifyEmail(userTeamAdmin.Id))
userChannelAdmin := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
userChannelAdmin = Client.Must(Client.CreateUser(userChannelAdmin, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userChannelAdmin.Id))
store.Must(Srv.Store.User().VerifyEmail(userChannelAdmin.Id))
Client.LoginByEmail(team.Name, userChannelAdmin.Email, "pwd")
@@ -869,7 +869,7 @@ func TestRemoveChannelMember(t *testing.T) {
userStd := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
userStd = Client.Must(Client.CreateUser(userStd, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userStd.Id))
store.Must(Srv.Store.User().VerifyEmail(userStd.Id))
Client.Must(Client.AddChannelMember(channel1.Id, userStd.Id))
@@ -919,7 +919,7 @@ func TestUpdateNotifyProps(t *testing.T) {
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)
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")
@@ -1041,7 +1041,7 @@ func TestFuzzyChannel(t *testing.T) {
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)
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")

View File

@@ -79,7 +79,7 @@ func checkCommand(c *Context, command *model.Command) bool {
}
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") {
return true
@@ -269,7 +269,7 @@ func joinCommand(c *Context, command *model.Command) bool {
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
return false
} else {
@@ -544,7 +544,7 @@ func loadTestPostsCommand(c *Context, command *model.Command) bool {
}
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)
usernames = make([]string, len(profileUsers))
i := 0

View File

@@ -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 = 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")
@@ -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 = 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")
@@ -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 = 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")
@@ -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 = 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["user_id"] = user2.Id
@@ -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 = 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")
@@ -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 = 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")

View File

@@ -162,7 +162,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if len(token) != 0 {
session := GetSession(c.T, token)
session := GetSession(token)
if session == nil || session.IsExpired() {
c.RemoveSessionCookie(w, r)
@@ -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 {
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)
}
}()
@@ -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(c.T, audit); r.Err != nil {
if r := <-Srv.Store.Audit().Save(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(c.T, audit); r.Err != nil {
if r := <-Srv.Store.Audit().Save(audit); r.Err != nil {
c.LogError(r.Err)
}
}
@@ -387,7 +387,7 @@ func (c *Context) setTeamURL(url string, valid bool) {
}
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)
}
}
@@ -515,14 +515,14 @@ func Handle404(w http.ResponseWriter, r *http.Request) {
RenderWebError(err, w, r)
}
func GetSession(T goi18n.TranslateFunc, token string) *model.Session {
func GetSession(token string) *model.Session {
var session *model.Session
if ts, ok := sessionCache.Get(token); ok {
session = ts.(*model.Session)
}
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)
} else {
session = sessionResult.Data.(*model.Session)
@@ -551,9 +551,9 @@ func GetMultiSessionCookieTokens(r *http.Request) []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) {
s := GetSession(T, token)
s := GetSession(token)
if s != nil && !s.IsExpired() && s.TeamId == teamId {
return int64(index), s
}

View File

@@ -6,12 +6,10 @@ package api
import (
"archive/zip"
"encoding/json"
"io"
"os"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
"io"
"os"
)
const (
@@ -53,19 +51,19 @@ func ExportOptionsFromJson(data io.Reader) *ExportOptions {
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
if file, err := openFileWriteStream(EXPORT_PATH + EXPORT_FILENAME); err != nil {
return "", err
} else {
defer closeFileWriteStream(file)
ExportToWriter(T, file, options)
ExportToWriter(file, options)
}
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
zipWriter := zip.NewWriter(w)
defer zipWriter.Close()
@@ -80,23 +78,23 @@ func ExportToWriter(T goi18n.TranslateFunc, w io.Writer, options *ExportOptions)
}
// Export Teams
ExportTeams(T, zipWriter, options)
ExportTeams(zipWriter, options)
return nil
}
func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOptions) *model.AppError {
func ExportTeams(writer ExportWriter, options *ExportOptions) *model.AppError {
// Get the teams
var teams []*model.Team
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
} else {
teams = result.Data.([]*model.Team)
}
} else {
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
} else {
team := result.Data.(*model.Team)
@@ -122,10 +120,10 @@ func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOpt
// Export the channels, local storage and users
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
}
if err := ExportUsers(T, writer, options, team.Id); err != nil {
if err := ExportUsers(writer, options, team.Id); err != nil {
return err
}
if err := ExportLocalStorage(writer, options, team.Id); err != nil {
@@ -136,18 +134,18 @@ func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOpt
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
var channels []*model.Channel
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
} else {
channels = result.Data.([]*model.Channel)
}
} else {
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
} else {
channel := result.Data.(*model.Channel)
@@ -158,7 +156,7 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
for i := range channels {
// Get members
mchan := Srv.Store.Channel().GetMembers(T, channels[i].Id)
mchan := Srv.Store.Channel().GetMembers(channels[i].Id)
// Sanitize
channels[i].PreExport()
@@ -192,7 +190,7 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
}
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
}
}
@@ -200,10 +198,10 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
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
var posts []*model.Post
if result := <-Srv.Store.Post().GetForExport(T, channelId); result.Err != nil {
if result := <-Srv.Store.Post().GetForExport(channelId); result.Err != nil {
return result.Err
} else {
posts = result.Data.([]*model.Post)
@@ -225,10 +223,10 @@ func ExportPosts(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOpt
return nil
}
func ExportUsers(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOptions, teamId string) *model.AppError {
func ExportUsers(writer ExportWriter, options *ExportOptions, teamId string) *model.AppError {
// Get the users
var users []*model.User
if result := <-Srv.Store.User().GetForExport(T, teamId); result.Err != nil {
if result := <-Srv.Store.User().GetForExport(teamId); result.Err != nil {
return result.Err
} else {
users = result.Data.([]*model.User)

View File

@@ -101,7 +101,7 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
files := m.File["files"]
@@ -319,7 +319,7 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
path := "teams/" + c.Session.TeamId + "/channels/" + channelId + "/users/" + userId + "/" + filename
var info *model.FileInfo
@@ -380,7 +380,7 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) {
data := r.URL.Query().Get("d")
teamId := r.URL.Query().Get("t")
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
path := ""
if len(teamId) == 26 {
@@ -477,7 +477,7 @@ func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) {
userId := matches[0][2]
filename = matches[0][3]
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
newProps := make(map[string]string)
newProps["filename"] = filename

View File

@@ -29,7 +29,7 @@ func TestUploadFile(t *testing.T) {
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)
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")
@@ -144,7 +144,7 @@ func TestGetFile(t *testing.T) {
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)
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")
@@ -214,7 +214,7 @@ func TestGetFile(t *testing.T) {
user2 := &model.User{TeamId: team2.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
newProps := make(map[string]string)
newProps["filename"] = filenames[0]
@@ -322,11 +322,11 @@ func TestGetPublicLink(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id))
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user1.Email, "pwd")

View File

@@ -6,7 +6,6 @@ package api
import (
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
//
@@ -14,28 +13,28 @@ import (
// some of the usual checks. (IsValid is still run)
//
func ImportPost(T goi18n.TranslateFunc, post *model.Post) {
func ImportPost(post *model.Post) {
post.Hashtags, _ = model.ParseHashtags(post.Message)
if result := <-Srv.Store.Post().Save(T, post); result.Err != nil {
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
l4g.Debug("Error saving post. user=" + post.UserId + ", message=" + post.Message)
}
}
func ImportUser(T goi18n.TranslateFunc, user *model.User) *model.User {
func ImportUser(user *model.User) *model.User {
user.MakeNonNil()
if result := <-Srv.Store.User().Save(T, user); result.Err != nil {
if result := <-Srv.Store.User().Save(user); result.Err != nil {
l4g.Error("Error saving user. err=%v", result.Err)
return nil
} else {
ruser := result.Data.(*model.User)
if err := JoinDefaultChannels(T, ruser, ""); err != nil {
if err := JoinDefaultChannels(ruser, ""); err != nil {
l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, err)
}
if cresult := <-Srv.Store.User().VerifyEmail(T, ruser.Id); cresult.Err != nil {
if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
l4g.Error("Failed to set email verified err=%v", cresult.Err)
}
@@ -43,8 +42,8 @@ func ImportUser(T goi18n.TranslateFunc, user *model.User) *model.User {
}
}
func ImportChannel(T goi18n.TranslateFunc, channel *model.Channel) *model.Channel {
if result := <-Srv.Store.Channel().Save(T, channel); result.Err != nil {
func ImportChannel(channel *model.Channel) *model.Channel {
if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
return nil
} else {
sc := result.Data.(*model.Channel)

View File

@@ -5,14 +5,12 @@ package api
import (
"fmt"
"net/http"
"net/url"
l4g "github.com/alecthomas/log4go"
"github.com/gorilla/mux"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
"net/http"
"net/url"
)
func InitOAuth(r *mux.Router) {
@@ -43,7 +41,7 @@ func registerOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
app.ClientSecret = secret
app.CreatorId = c.Session.UserId
if result := <-Srv.Store.OAuth().SaveApp(c.T, app); result.Err != nil {
if result := <-Srv.Store.OAuth().SaveApp(app); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -92,7 +90,7 @@ func allowOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
state := r.URL.Query().Get("state")
var app *model.OAuthApp
if result := <-Srv.Store.OAuth().GetApp(c.T, clientId); result.Err != nil {
if result := <-Srv.Store.OAuth().GetApp(clientId); result.Err != nil {
c.Err = model.NewAppError("allowOAuth", "server_error: Error accessing the database", "")
return
} else {
@@ -114,7 +112,7 @@ func allowOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
authData := &model.AuthData{UserId: c.Session.UserId, ClientId: clientId, CreateAt: model.GetMillis(), RedirectUri: redirectUri, State: state, Scope: scope}
authData.Code = model.HashPassword(fmt.Sprintf("%v:%v:%v:%v", clientId, redirectUri, authData.CreateAt, c.Session.UserId))
if result := <-Srv.Store.OAuth().SaveAuthData(c.T, authData); result.Err != nil {
if result := <-Srv.Store.OAuth().SaveAuthData(authData); result.Err != nil {
responseData["redirect"] = redirectUri + "?error=server_error&state=" + state
w.Write([]byte(model.MapToJson(responseData)))
return
@@ -127,20 +125,20 @@ func allowOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(model.MapToJson(responseData)))
}
func RevokeAccessToken(T goi18n.TranslateFunc, token string) *model.AppError {
func RevokeAccessToken(token string) *model.AppError {
schan := Srv.Store.Session().Remove(T, token)
schan := Srv.Store.Session().Remove(token)
sessionCache.Remove(token)
var accessData *model.AccessData
if result := <-Srv.Store.OAuth().GetAccessData(T, token); result.Err != nil {
if result := <-Srv.Store.OAuth().GetAccessData(token); result.Err != nil {
return model.NewAppError("RevokeAccessToken", "Error getting access token from DB before deletion", "")
} else {
accessData = result.Data.(*model.AccessData)
}
tchan := Srv.Store.OAuth().RemoveAccessData(T, token)
cchan := Srv.Store.OAuth().RemoveAuthData(T, accessData.AuthCode)
tchan := Srv.Store.OAuth().RemoveAccessData(token)
cchan := Srv.Store.OAuth().RemoveAuthData(accessData.AuthCode)
if result := <-tchan; result.Err != nil {
return model.NewAppError("RevokeAccessToken", "Error deleting access token from DB", "")
@@ -157,8 +155,8 @@ func RevokeAccessToken(T goi18n.TranslateFunc, token string) *model.AppError {
return nil
}
func GetAuthData(T goi18n.TranslateFunc, code string) *model.AuthData {
if result := <-Srv.Store.OAuth().GetAuthData(T, code); result.Err != nil {
func GetAuthData(code string) *model.AuthData {
if result := <-Srv.Store.OAuth().GetAuthData(code); result.Err != nil {
l4g.Error("Couldn't find auth code for code=%s", code)
return nil
} else {

View File

@@ -20,7 +20,7 @@ func TestRegisterApp(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Password: "pwd"}
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
app := &model.OAuthApp{Name: "TestApp" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -77,7 +77,7 @@ func TestAllowOAuth(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Password: "pwd"}
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
app := &model.OAuthApp{Name: "TestApp" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}

View File

@@ -5,6 +5,11 @@ 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"
@@ -12,13 +17,6 @@ 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) {
@@ -46,7 +44,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
}
// Create and save post object to channel
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId)
if !c.HasPermissionsToChannel(cchan, "createPost") {
return
@@ -61,7 +59,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
} else {
if result := <-Srv.Store.Channel().UpdateLastViewedAt(c.T, post.ChannelId, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Channel().UpdateLastViewedAt(post.ChannelId, c.Session.UserId); result.Err != nil {
l4g.Error("Encountered error updating last viewed, channel_id=%s, user_id=%s, err=%v", post.ChannelId, c.Session.UserId, result.Err)
}
@@ -72,7 +70,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
var pchan store.StoreChannel
if len(post.RootId) > 0 {
pchan = Srv.Store.Post().Get(c.T, post.RootId)
pchan = Srv.Store.Post().Get(post.RootId)
}
// Verify the parent/child relationships are correct
@@ -138,7 +136,7 @@ func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post
}
var rpost *model.Post
if result := <-Srv.Store.Post().Save(c.T, post); result.Err != nil {
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
return nil, result.Err
} else {
rpost = result.Data.(*model.Post)
@@ -205,9 +203,9 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc
func handlePostEventsAndForget(c *Context, post *model.Post, triggerWebhooks bool) {
go func() {
tchan := Srv.Store.Team().Get(c.T, c.Session.TeamId)
cchan := Srv.Store.Channel().Get(c.T, post.ChannelId)
uchan := Srv.Store.User().Get(c.T, post.UserId)
tchan := Srv.Store.Team().Get(c.Session.TeamId)
cchan := Srv.Store.Channel().Get(post.ChannelId)
uchan := Srv.Store.User().Get(post.UserId)
var team *model.Team
if result := <-tchan; result.Err != nil {
@@ -240,14 +238,14 @@ func handlePostEventsAndForget(c *Context, post *model.Post, triggerWebhooks boo
}
if channel.Type == model.CHANNEL_DIRECT {
go makeDirectChannelVisible(c.T, c.Session.TeamId, post.ChannelId)
go makeDirectChannelVisible(c.Session.TeamId, post.ChannelId)
}
}()
}
func makeDirectChannelVisible(T goi18n.TranslateFunc, teamId string, channelId string) {
func makeDirectChannelVisible(teamId string, channelId string) {
var members []model.ChannelMember
if result := <-Srv.Store.Channel().GetMembers(T, channelId); result.Err != nil {
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)
return
} else {
@@ -263,7 +261,7 @@ func makeDirectChannelVisible(T goi18n.TranslateFunc, teamId string, channelId s
for i, member := range members {
otherUserId := members[1-i].UserId
if result := <-Srv.Store.Preference().Get(T, member.UserId, model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW, otherUserId); result.Err != nil {
if result := <-Srv.Store.Preference().Get(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,
@@ -272,7 +270,7 @@ func makeDirectChannelVisible(T goi18n.TranslateFunc, teamId string, channelId s
Value: "true",
}
if saveResult := <-Srv.Store.Preference().Save(T, &model.Preferences{*preference}); saveResult.Err != nil {
if saveResult := <-Srv.Store.Preference().Save(&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)
@@ -287,7 +285,7 @@ func makeDirectChannelVisible(T goi18n.TranslateFunc, teamId string, channelId s
// update the existing preference to make the channel visible
preference.Value = "true"
if updateResult := <-Srv.Store.Preference().Save(T, &model.Preferences{preference}); updateResult.Err != nil {
if updateResult := <-Srv.Store.Preference().Save(&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)
@@ -310,7 +308,7 @@ func handleWebhookEventsAndForget(c *Context, post *model.Post, team *model.Team
return
}
hchan := Srv.Store.Webhook().GetOutgoingByTeam(c.T, c.Session.TeamId)
hchan := Srv.Store.Webhook().GetOutgoingByTeam(c.Session.TeamId)
hooks := []*model.OutgoingWebhook{}
@@ -394,8 +392,8 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team,
go func() {
// Get a list of user names (to be used as keywords) and ids for the given team
uchan := Srv.Store.User().GetProfiles(c.T, c.Session.TeamId)
echan := Srv.Store.Channel().GetMembers(c.T, post.ChannelId)
uchan := Srv.Store.User().GetProfiles(c.Session.TeamId)
echan := Srv.Store.Channel().GetMembers(post.ChannelId)
var channelName string
var bodyText string
@@ -542,7 +540,7 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team,
}
for id := range toEmailMap {
updateMentionCountAndForget(c.T, post.ChannelId, id)
updateMentionCountAndForget(post.ChannelId, id)
}
}
@@ -626,7 +624,7 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team,
}
if *utils.Cfg.EmailSettings.SendPushNotifications {
sessionChan := Srv.Store.Session().GetSessions(c.T, id)
sessionChan := Srv.Store.Session().GetSessions(id)
if result := <-sessionChan; result.Err != nil {
l4g.Error("Failed to retrieve sessions in notifications id=%v, err=%v", id, result.Err)
} else {
@@ -694,9 +692,9 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team,
}()
}
func updateMentionCountAndForget(T goi18n.TranslateFunc, channelId, userId string) {
func updateMentionCountAndForget(channelId, userId string) {
go func() {
if result := <-Srv.Store.Channel().IncrementMentionCount(T, channelId, userId); result.Err != nil {
if result := <-Srv.Store.Channel().IncrementMentionCount(channelId, userId); result.Err != nil {
l4g.Error("Failed to update mention count for user_id=%v on channel_id=%v err=%v", userId, channelId, result.Err)
}
}()
@@ -710,8 +708,8 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(c.T, post.Id)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(post.Id)
if !c.HasPermissionsToChannel(cchan, "updatePost") {
return
@@ -745,7 +743,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
hashtags, _ := model.ParseHashtags(post.Message)
if result := <-Srv.Store.Post().Update(c.T, oldPost, post.Message, hashtags); result.Err != nil {
if result := <-Srv.Store.Post().Update(oldPost, post.Message, hashtags); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -781,8 +779,8 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
etagChan := Srv.Store.Post().GetEtag(c.T, id)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
etagChan := Srv.Store.Post().GetEtag(id)
if !c.HasPermissionsToChannel(cchan, "getPosts") {
return
@@ -794,7 +792,7 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
pchan := Srv.Store.Post().GetPosts(c.T, id, offset, limit)
pchan := Srv.Store.Post().GetPosts(id, offset, limit)
if result := <-pchan; result.Err != nil {
c.Err = result.Err
@@ -823,8 +821,8 @@ func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
pchan := Srv.Store.Post().GetPostsSince(c.T, id, time)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
pchan := Srv.Store.Post().GetPostsSince(id, time)
if !c.HasPermissionsToChannel(cchan, "getPostsSince") {
return
@@ -856,8 +854,8 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(c.T, postId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(postId)
if !c.HasPermissionsToChannel(cchan, "getPost") {
return
@@ -891,7 +889,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Post().Get(c.T, postId); result.Err != nil {
if result := <-Srv.Store.Post().Get(postId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -903,7 +901,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
}
post := list.Posts[list.Order[0]]
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId)
if !c.HasPermissionsToChannel(cchan, "getPostById") {
return
}
@@ -932,8 +930,8 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(c.T, postId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(postId)
if result := <-pchan; result.Err != nil {
c.Err = result.Err
@@ -963,7 +961,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if dresult := <-Srv.Store.Post().Delete(c.T, postId, model.GetMillis()); dresult.Err != nil {
if dresult := <-Srv.Store.Post().Delete(postId, model.GetMillis()); dresult.Err != nil {
c.Err = dresult.Err
return
}
@@ -1012,9 +1010,9 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
// We can do better than this etag in this situation
etagChan := Srv.Store.Post().GetEtag(c.T, id)
etagChan := Srv.Store.Post().GetEtag(id)
if !c.HasPermissionsToChannel(cchan, "getPostsBeforeOrAfter") {
return
@@ -1027,9 +1025,9 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
var pchan store.StoreChannel
if before {
pchan = Srv.Store.Post().GetPostsBefore(c.T, id, postId, numPosts, offset)
pchan = Srv.Store.Post().GetPostsBefore(id, postId, numPosts, offset)
} else {
pchan = Srv.Store.Post().GetPostsAfter(c.T, id, postId, numPosts, offset)
pchan = Srv.Store.Post().GetPostsAfter(id, postId, numPosts, offset)
}
if result := <-pchan; result.Err != nil {
@@ -1057,7 +1055,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
for _, params := range paramsList {
// don't allow users to search for everything
if params.Terms != "*" {
channels = append(channels, Srv.Store.Post().Search(c.T, c.Session.TeamId, c.Session.UserId, params))
channels = append(channels, Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, params))
}
}

View File

@@ -23,11 +23,11 @@ func TestCreatePost(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id))
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user1.Email, "pwd")
@@ -105,7 +105,7 @@ func TestCreatePost(t *testing.T) {
user3 := &model.User{TeamId: team2.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user3.Id))
store.Must(Srv.Store.User().VerifyEmail(user3.Id))
Client.LoginByEmail(team2.Name, user3.Email, "pwd")
@@ -134,11 +134,11 @@ func TestUpdatePost(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id))
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user1.Email, "pwd")
@@ -202,7 +202,7 @@ func TestGetPosts(t *testing.T) {
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)
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")
@@ -267,7 +267,7 @@ func TestGetPostsSince(t *testing.T) {
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)
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")
@@ -337,7 +337,7 @@ func TestGetPostsBeforeAfter(t *testing.T) {
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)
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")
@@ -414,7 +414,7 @@ func TestSearchPosts(t *testing.T) {
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)
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")
@@ -464,7 +464,7 @@ func TestSearchHashtagPosts(t *testing.T) {
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)
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")
@@ -495,7 +495,7 @@ func TestSearchPostsInChannel(t *testing.T) {
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)
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")
@@ -577,7 +577,7 @@ func TestSearchPostsFromUser(t *testing.T) {
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)
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")
@@ -592,7 +592,7 @@ func TestSearchPostsFromUser(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
Client.Must(Client.JoinChannel(channel1.Id))
@@ -621,7 +621,7 @@ func TestSearchPostsFromUser(t *testing.T) {
user3 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user3.Id))
store.Must(Srv.Store.User().VerifyEmail(user3.Id))
Client.LoginByEmail(team.Name, user3.Email, "pwd")
Client.Must(Client.JoinChannel(channel1.Id))
@@ -655,7 +655,7 @@ func TestGetPostsCache(t *testing.T) {
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)
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")
@@ -704,11 +704,11 @@ func TestDeletePosts(t *testing.T) {
userAdmin := &model.User{TeamId: team.Id, Email: team.Email, Nickname: "Corey Hulen", Password: "pwd"}
userAdmin = Client.Must(Client.CreateUser(userAdmin, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, userAdmin.Id))
store.Must(Srv.Store.User().VerifyEmail(userAdmin.Id))
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)
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")
@@ -765,7 +765,7 @@ func TestEmailMention(t *testing.T) {
user1 := &model.User{TeamId: team.Id, Email: "corey+test@test.com", Nickname: "Bob Bobby", Password: "pwd"}
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")
@@ -787,7 +787,7 @@ func TestFuzzyPosts(t *testing.T) {
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)
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")
@@ -814,11 +814,11 @@ func TestMakeDirectChannelVisible(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id))
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
// user2 will be created with prefs created to show user1 in the sidebar so set that to false to get rid of it
Client.LoginByEmail(team.Name, user2.Email, "pwd")
@@ -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(utils.T, team.Id, channel.Id)
makeDirectChannelVisible(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")

View File

@@ -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.T, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Preference().GetAll(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(c.T, &preferences); result.Err != nil {
if result := <-Srv.Store.Preference().Save(&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.T, c.Session.UserId, category); result.Err != nil {
if result := <-Srv.Store.Preference().GetCategory(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.T, c.Session.UserId, category, name); result.Err != nil {
if result := <-Srv.Store.Preference().Get(c.Session.UserId, category, name); result.Err != nil {
c.Err = result.Err
} else {
data := result.Data.(model.Preference)

View File

@@ -6,7 +6,6 @@ package api
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
"testing"
)
@@ -18,11 +17,11 @@ func TestGetAllPreferences(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id))
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
category := model.NewId()
@@ -71,7 +70,7 @@ func TestSetPreferences(t *testing.T) {
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)
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")
@@ -102,7 +101,7 @@ func TestSetPreferences(t *testing.T) {
// not able to update as a different user
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
@@ -119,11 +118,11 @@ func TestGetPreferenceCategory(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user1.Id))
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
category := model.NewId()
@@ -175,7 +174,7 @@ func TestGetPreference(t *testing.T) {
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)
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")

View File

@@ -7,14 +7,12 @@ import (
"archive/zip"
"bytes"
"encoding/json"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
"io"
"mime/multipart"
"strconv"
"strings"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SlackChannel struct {
@@ -91,7 +89,7 @@ func SlackParsePosts(data io.Reader) []SlackPost {
return posts
}
func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser, log *bytes.Buffer) map[string]*model.User {
func SlackAddUsers(teamId string, slackusers []SlackUser, log *bytes.Buffer) map[string]*model.User {
// Log header
log.WriteString("\r\n Users Created\r\n")
log.WriteString("===============\r\n\r\n")
@@ -118,7 +116,7 @@ func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser
Password: password,
}
if mUser := ImportUser(T, &newUser); mUser != nil {
if mUser := ImportUser(&newUser); mUser != nil {
addedUsers[sUser.Id] = mUser
log.WriteString("Email, Password: " + newUser.Email + ", " + password + "\r\n")
} else {
@@ -129,7 +127,7 @@ func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser
return addedUsers
}
func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []SlackPost, users map[string]*model.User) {
func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*model.User) {
for _, sPost := range posts {
switch {
case sPost.Type == "message" && (sPost.SubType == "" || sPost.SubType == "file_share"):
@@ -146,7 +144,7 @@ func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []Slack
Message: sPost.Text,
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
}
ImportPost(T, &newPost)
ImportPost(&newPost)
case sPost.Type == "message" && sPost.SubType == "file_comment":
if sPost.Comment["user"] == "" {
l4g.Debug("Message without user")
@@ -161,7 +159,7 @@ func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []Slack
Message: sPost.Comment["comment"],
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
}
ImportPost(T, &newPost)
ImportPost(&newPost)
case sPost.Type == "message" && sPost.SubType == "bot_message":
// In the future this will use the "Action Post" spec to post
// a message without using a username. For now we just warn that we don't handle this case
@@ -172,7 +170,7 @@ func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []Slack
}
}
func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []SlackChannel, posts map[string][]SlackPost, users map[string]*model.User, log *bytes.Buffer) map[string]*model.Channel {
func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[string][]SlackPost, users map[string]*model.User, log *bytes.Buffer) map[string]*model.Channel {
// Write Header
log.WriteString("\r\n Channels Added \r\n")
log.WriteString("=================\r\n\r\n")
@@ -186,10 +184,10 @@ func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []Sla
Name: SlackConvertChannelName(sChannel.Name),
Purpose: sChannel.Topic["value"],
}
mChannel := ImportChannel(T, &newChannel)
mChannel := ImportChannel(&newChannel)
if mChannel == nil {
// Maybe it already exists?
if result := <-Srv.Store.Channel().GetByName(T, teamId, sChannel.Name); result.Err != nil {
if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name); result.Err != nil {
l4g.Debug("Failed to import: %s", newChannel.DisplayName)
log.WriteString("Failed to import: " + newChannel.DisplayName + "\r\n")
continue
@@ -200,13 +198,13 @@ func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []Sla
}
log.WriteString(newChannel.DisplayName + "\r\n")
addedChannels[sChannel.Id] = mChannel
SlackAddPosts(T, mChannel, posts[sChannel.Name], users)
SlackAddPosts(mChannel, posts[sChannel.Name], users)
}
return addedChannels
}
func SlackImport(T goi18n.TranslateFunc, fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
func SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
zipreader, err := zip.NewReader(fileData, fileSize)
if err != nil || zipreader.File == nil {
return model.NewAppError("SlackImport", "Unable to open zip file", err.Error()), nil
@@ -242,8 +240,8 @@ func SlackImport(T goi18n.TranslateFunc, fileData multipart.File, fileSize int64
}
}
addedUsers := SlackAddUsers(T, teamID, users, log)
SlackAddChannels(T, teamID, channels, posts, addedUsers, log)
addedUsers := SlackAddUsers(teamID, users, log)
SlackAddChannels(teamID, channels, posts, addedUsers, log)
log.WriteString("\r\n Notes \r\n")
log.WriteString("=======\r\n\r\n")

View File

@@ -6,17 +6,16 @@ package api
import (
"bytes"
"fmt"
"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"
"net/http"
"net/url"
"strconv"
"strings"
"time"
)
func InitTeam(r *mux.Router) {
@@ -128,7 +127,7 @@ func createTeamFromSSO(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if result := <-Srv.Store.Team().Save(c.T, team); result.Err != nil {
if result := <-Srv.Store.Team().Save(team); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -209,7 +208,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Team().Save(c.T, &teamSignup.Team); result.Err != nil {
if result := <-Srv.Store.Team().Save(&teamSignup.Team); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -223,7 +222,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
teamSignup.User.TeamId = rteam.Id
teamSignup.User.EmailVerified = true
ruser, err := CreateUser(c.T, rteam, &teamSignup.User)
ruser, err := CreateUser(rteam, &teamSignup.User)
if err != nil {
c.Err = err
return
@@ -264,7 +263,7 @@ func CreateTeam(c *Context, team *model.Team) *model.Team {
return nil
}
if result := <-Srv.Store.Team().Save(c.T, team); result.Err != nil {
if result := <-Srv.Store.Team().Save(team); result.Err != nil {
c.Err = result.Err
return nil
} else {
@@ -313,7 +312,7 @@ func getAll(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Team().GetAll(c.T); result.Err != nil {
if result := <-Srv.Store.Team().GetAll(); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -331,7 +330,7 @@ func revokeAllSessions(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.MapFromJson(r.Body)
id := props["id"]
if result := <-Srv.Store.Session().Get(c.T, id); result.Err != nil {
if result := <-Srv.Store.Session().Get(id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -340,11 +339,11 @@ func revokeAllSessions(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("revoked_all=" + id)
if session.IsOAuth {
RevokeAccessToken(c.T, session.Token)
RevokeAccessToken(session.Token)
} else {
sessionCache.Remove(session.Token)
if result := <-Srv.Store.Session().Remove(c.T, session.Id); result.Err != nil {
if result := <-Srv.Store.Session().Remove(session.Id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -382,7 +381,7 @@ func FindTeamByName(c *Context, name string, all string) bool {
return false
}
if result := <-Srv.Store.Team().GetByName(c.T, name); result.Err != nil {
if result := <-Srv.Store.Team().GetByName(name); result.Err != nil {
return false
} else {
return true
@@ -402,7 +401,7 @@ func findTeams(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Team().GetTeamsForEmail(c.T, email); result.Err != nil {
if result := <-Srv.Store.Team().GetTeamsForEmail(email); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -433,7 +432,7 @@ func emailTeams(c *Context, w http.ResponseWriter, r *http.Request) {
bodyPage := NewServerTemplatePage("find_teams_body")
bodyPage.ClientCfg["SiteURL"] = c.GetSiteURL()
if result := <-Srv.Store.Team().GetTeamsForEmail(c.T, email); result.Err != nil {
if result := <-Srv.Store.Team().GetTeamsForEmail(email); result.Err != nil {
c.Err = result.Err
} else {
teams := result.Data.([]*model.Team)
@@ -461,8 +460,8 @@ func inviteMembers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
tchan := Srv.Store.Team().Get(c.T, c.Session.TeamId)
uchan := Srv.Store.User().Get(c.T, c.Session.UserId)
tchan := Srv.Store.Team().Get(c.Session.TeamId)
uchan := Srv.Store.User().Get(c.Session.UserId)
var team *model.Team
if result := <-tchan; result.Err != nil {
@@ -482,7 +481,7 @@ func inviteMembers(c *Context, w http.ResponseWriter, r *http.Request) {
var invNum int64 = 0
for i, invite := range invites.Invites {
if result := <-Srv.Store.User().GetByEmail(c.T, c.Session.TeamId, invite["email"]); result.Err == nil || result.Err.Message != store.MISSING_ACCOUNT_ERROR {
if result := <-Srv.Store.User().GetByEmail(c.Session.TeamId, invite["email"]); result.Err == nil || result.Err.Message != store.MISSING_ACCOUNT_ERROR {
invNum = int64(i)
c.Err = model.NewAppError("invite_members", "This person is already on your team", strconv.FormatInt(invNum, 10))
return
@@ -561,7 +560,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
}
var oldTeam *model.Team
if result := <-Srv.Store.Team().Get(c.T, team.Id); result.Err != nil {
if result := <-Srv.Store.Team().Get(team.Id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -576,7 +575,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
oldTeam.AllowedDomains = team.AllowedDomains
//oldTeam.Type = team.Type
if result := <-Srv.Store.Team().Update(c.T, oldTeam); result.Err != nil {
if result := <-Srv.Store.Team().Update(oldTeam); result.Err != nil {
c.Err = result.Err
return
}
@@ -592,11 +591,11 @@ func PermanentDeleteTeam(c *Context, team *model.Team) *model.AppError {
c.LogAuditWithUserId("", fmt.Sprintf("attempt teamId=%v", team.Id))
team.DeleteAt = model.GetMillis()
if result := <-Srv.Store.Team().Update(c.T, team); result.Err != nil {
if result := <-Srv.Store.Team().Update(team); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.User().GetForExport(c.T, team.Id); result.Err != nil {
if result := <-Srv.Store.User().GetForExport(team.Id); result.Err != nil {
return result.Err
} else {
users := result.Data.([]*model.User)
@@ -605,11 +604,11 @@ func PermanentDeleteTeam(c *Context, team *model.Team) *model.AppError {
}
}
if result := <-Srv.Store.Channel().PermanentDeleteByTeam(c.T, team.Id); result.Err != nil {
if result := <-Srv.Store.Channel().PermanentDeleteByTeam(team.Id); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.Team().PermanentDelete(c.T, team.Id); result.Err != nil {
if result := <-Srv.Store.Team().PermanentDelete(team.Id); result.Err != nil {
return result.Err
}
@@ -625,7 +624,7 @@ func getMyTeam(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
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.Err = result.Err
return
} else if HandleEtag(result.Data.(*model.Team).Etag(), w, r) {
@@ -694,7 +693,7 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
switch importFrom {
case "slack":
var err *model.AppError
if err, log = SlackImport(c.T, fileData, fileSize, c.Session.TeamId); err != nil {
if err, log = SlackImport(fileData, fileSize, c.Session.TeamId); err != nil {
c.Err = err
c.Err.StatusCode = http.StatusBadRequest
}
@@ -714,7 +713,7 @@ func exportTeam(c *Context, w http.ResponseWriter, r *http.Request) {
options := ExportOptionsFromJson(r.Body)
if link, err := ExportToFile(c.T, options); err != nil {
if link, err := ExportToFile(options); err != nil {
c.Err = err
return
} else {

View File

@@ -79,7 +79,7 @@ func TestCreateTeam(t *testing.T) {
user := &model.User{TeamId: rteam.Data.(*model.Team).Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
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")
@@ -116,7 +116,7 @@ func TestFindTeamByEmail(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id))
store.Must(Srv.Store.User().VerifyEmail(user.Id))
if r1, err := Client.FindTeams(user.Email); err != nil {
t.Fatal(err)
@@ -143,7 +143,7 @@ func TestGetAllTeams(t *testing.T) {
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)
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")
@@ -176,7 +176,7 @@ func TestTeamPermDelete(t *testing.T) {
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)
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")
@@ -219,7 +219,7 @@ func TestFindTeamByDomain(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user.Id))
store.Must(Srv.Store.User().VerifyEmail(user.Id))
if r1, err := Client.FindTeamByDomain(team.Name, false); err != nil {
t.Fatal(err)
@@ -259,7 +259,7 @@ func TestFindTeamByEmailSend(t *testing.T) {
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)
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")
if _, err := Client.FindTeamsSendEmail(user.Email); err != nil {
@@ -284,7 +284,7 @@ func TestInviteMembers(t *testing.T) {
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)
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")
@@ -313,11 +313,11 @@ func TestUpdateTeamDisplayName(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: "test@nowhere.com", Nickname: "Corey Hulen", Password: "pwd"}
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))
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
@@ -370,7 +370,7 @@ func TestGetMyTeam(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser, _ := Client.CreateUser(&user, "")
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Data.(*model.User).Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
Client.LoginByEmail(team.Name, user.Email, user.Password)

View File

@@ -7,6 +7,15 @@ 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"
@@ -20,17 +29,6 @@ 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) {
@@ -84,7 +82,7 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
var team *model.Team
if result := <-Srv.Store.Team().Get(c.T, user.TeamId); result.Err != nil {
if result := <-Srv.Store.Team().Get(user.TeamId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -129,14 +127,14 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
ruser, err := CreateUser(c.T, team, user)
ruser, err := CreateUser(team, user)
if err != nil {
c.Err = err
return
}
if sendWelcomeEmail {
sendWelcomeEmailAndForget(c.T, ruser.Id, ruser.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team), ruser.EmailVerified)
sendWelcomeEmailAndForget(ruser.Id, ruser.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team), ruser.EmailVerified)
}
w.Write([]byte(ruser.ToJson()))
@@ -185,7 +183,7 @@ func IsVerifyHashRequired(user *model.User, team *model.Team, hash string) bool
return shouldVerifyHash
}
func CreateUser(T goi18n.TranslateFunc, team *model.Team, user *model.User) (*model.User, *model.AppError) {
func CreateUser(team *model.Team, user *model.User) (*model.User, *model.AppError) {
channelRole := ""
if team.Email == user.Email {
@@ -194,7 +192,7 @@ func CreateUser(T goi18n.TranslateFunc, team *model.Team, user *model.User) (*mo
// Below is a speical case where the first user in the entire
// system is granted the system_admin role instead of admin
if result := <-Srv.Store.User().GetTotalUsersCount(T); result.Err != nil {
if result := <-Srv.Store.User().GetTotalUsersCount(); result.Err != nil {
return nil, result.Err
} else {
count := result.Data.(int64)
@@ -209,27 +207,27 @@ func CreateUser(T goi18n.TranslateFunc, team *model.Team, user *model.User) (*mo
user.MakeNonNil()
if result := <-Srv.Store.User().Save(T, user); result.Err != nil {
if result := <-Srv.Store.User().Save(user); result.Err != nil {
l4g.Error("Couldn't save the user err=%v", result.Err)
return nil, result.Err
} else {
ruser := result.Data.(*model.User)
// Soft error if there is an issue joining the default channels
if err := JoinDefaultChannels(T, ruser, channelRole); err != nil {
if err := JoinDefaultChannels(ruser, channelRole); err != nil {
l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, err)
}
addDirectChannelsAndForget(T, ruser)
addDirectChannelsAndForget(ruser)
if user.EmailVerified {
if cresult := <-Srv.Store.User().VerifyEmail(T, ruser.Id); cresult.Err != nil {
if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
l4g.Error("Failed to set email verified err=%v", cresult.Err)
}
}
pref := model.Preference{UserId: ruser.Id, Category: model.PREFERENCE_CATEGORY_TUTORIAL_STEPS, Name: ruser.Id, Value: "0"}
if presult := <-Srv.Store.Preference().Save(T, &model.Preferences{pref}); presult.Err != nil {
if presult := <-Srv.Store.Preference().Save(&model.Preferences{pref}); presult.Err != nil {
l4g.Error("Encountered error saving tutorial preference, err=%v", presult.Err.Message)
}
@@ -259,12 +257,12 @@ func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service
return nil
}
suchan := Srv.Store.User().GetByAuth(c.T, team.Id, user.AuthData, service)
euchan := Srv.Store.User().GetByEmail(c.T, team.Id, user.Email)
suchan := Srv.Store.User().GetByAuth(team.Id, user.AuthData, service)
euchan := Srv.Store.User().GetByEmail(team.Id, user.Email)
if team.Email == "" {
team.Email = user.Email
if result := <-Srv.Store.Team().Update(c.T, team); result.Err != nil {
if result := <-Srv.Store.Team().Update(team); result.Err != nil {
c.Err = result.Err
return nil
}
@@ -272,7 +270,7 @@ func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service
found := true
count := 0
for found {
if found = IsUsernameTaken(c.T, user.Username, team.Id); c.Err != nil {
if found = IsUsernameTaken(user.Username, team.Id); c.Err != nil {
return nil
} else if found {
user.Username = user.Username + strconv.Itoa(count)
@@ -294,7 +292,7 @@ func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service
user.TeamId = team.Id
user.EmailVerified = true
ruser, err := CreateUser(c.T, team, user)
ruser, err := CreateUser(team, user)
if err != nil {
c.Err = err
return nil
@@ -308,7 +306,7 @@ func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service
return ruser
}
func sendWelcomeEmailAndForget(T goi18n.TranslateFunc, userId, email, teamName, teamDisplayName, siteURL, teamURL string, verified bool) {
func sendWelcomeEmailAndForget(userId, email, teamName, teamDisplayName, siteURL, teamURL string, verified bool) {
go func() {
subjectPage := NewServerTemplatePage("welcome_subject")
@@ -328,10 +326,10 @@ func sendWelcomeEmailAndForget(T goi18n.TranslateFunc, userId, email, teamName,
}()
}
func addDirectChannelsAndForget(T goi18n.TranslateFunc, user *model.User) {
func addDirectChannelsAndForget(user *model.User) {
go func() {
var profiles map[string]*model.User
if result := <-Srv.Store.User().GetProfiles(T, user.TeamId); result.Err != nil {
if result := <-Srv.Store.User().GetProfiles(user.TeamId); result.Err != nil {
l4g.Error("Failed to add direct channel preferences for user user_id=%s, team_id=%s, err=%v", user.Id, user.TeamId, result.Err.Error())
return
} else {
@@ -361,7 +359,7 @@ func addDirectChannelsAndForget(T goi18n.TranslateFunc, user *model.User) {
}
}
if result := <-Srv.Store.Preference().Save(T, &preferences); result.Err != nil {
if result := <-Srv.Store.Preference().Save(&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())
}
}()
@@ -387,7 +385,7 @@ func SendVerifyEmailAndForget(userId, userEmail, teamName, teamDisplayName, site
}
func LoginById(c *Context, w http.ResponseWriter, r *http.Request, userId, password, deviceId string) *model.User {
if result := <-Srv.Store.User().Get(c.T, userId); result.Err != nil {
if result := <-Srv.Store.User().Get(userId); result.Err != nil {
c.Err = result.Err
return nil
} else {
@@ -404,14 +402,14 @@ func LoginById(c *Context, w http.ResponseWriter, r *http.Request, userId, passw
func LoginByEmail(c *Context, w http.ResponseWriter, r *http.Request, email, name, password, deviceId string) *model.User {
var team *model.Team
if result := <-Srv.Store.Team().GetByName(c.T, name); result.Err != nil {
if result := <-Srv.Store.Team().GetByName(name); result.Err != nil {
c.Err = result.Err
return nil
} else {
team = result.Data.(*model.Team)
}
if result := <-Srv.Store.User().GetByEmail(c.T, team.Id, email); result.Err != nil {
if result := <-Srv.Store.User().GetByEmail(team.Id, email); result.Err != nil {
c.Err = result.Err
c.Err.StatusCode = http.StatusForbidden
return nil
@@ -448,7 +446,7 @@ func LoginByOAuth(c *Context, w http.ResponseWriter, r *http.Request, service st
}
var user *model.User
if result := <-Srv.Store.User().GetByAuth(c.T, team.Id, authData, service); result.Err != nil {
if result := <-Srv.Store.User().GetByAuth(team.Id, authData, service); result.Err != nil {
c.Err = result.Err
return nil
} else {
@@ -476,13 +474,13 @@ func checkUserPassword(c *Context, user *model.User, password string) bool {
c.Err = model.NewAppError("checkUserPassword", "Login failed because of invalid password", "user_id="+user.Id)
c.Err.StatusCode = http.StatusForbidden
if result := <-Srv.Store.User().UpdateFailedPasswordAttempts(c.T, user.Id, user.FailedAttempts+1); result.Err != nil {
if result := <-Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); result.Err != nil {
c.LogError(result.Err)
}
return false
} else {
if result := <-Srv.Store.User().UpdateFailedPasswordAttempts(c.T, user.Id, 0); result.Err != nil {
if result := <-Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); result.Err != nil {
c.LogError(result.Err)
}
@@ -516,7 +514,7 @@ func Login(c *Context, w http.ResponseWriter, r *http.Request, user *model.User,
maxAge = *utils.Cfg.ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
// A special case where we logout of all other sessions with the same Id
if result := <-Srv.Store.Session().GetSessions(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.Session().GetSessions(user.Id); result.Err != nil {
c.Err = result.Err
c.Err.StatusCode = http.StatusForbidden
return
@@ -563,7 +561,7 @@ func Login(c *Context, w http.ResponseWriter, r *http.Request, user *model.User,
session.AddProp(model.SESSION_PROP_OS, os)
session.AddProp(model.SESSION_PROP_BROWSER, fmt.Sprintf("%v/%v", bname, bversion))
if result := <-Srv.Store.Session().Save(c.T, session); result.Err != nil {
if result := <-Srv.Store.Session().Save(session); result.Err != nil {
c.Err = result.Err
c.Err.StatusCode = http.StatusForbidden
return
@@ -579,7 +577,7 @@ func Login(c *Context, w http.ResponseWriter, r *http.Request, user *model.User,
seen := make(map[string]string)
seen[session.TeamId] = session.TeamId
for _, token := range tokens {
s := GetSession(c.T, token)
s := GetSession(token)
if s != nil && !s.IsExpired() && seen[s.TeamId] == "" {
multiToken += " " + token
seen[s.TeamId] = s.TeamId
@@ -659,7 +657,7 @@ func loginLdap(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
teamc := Srv.Store.Team().GetByName(c.T, teamName)
teamc := Srv.Store.Team().GetByName(teamName)
ldapInterface := einterfaces.GetLdapInterface()
if ldapInterface == nil {
@@ -706,18 +704,18 @@ func revokeSession(c *Context, w http.ResponseWriter, r *http.Request) {
}
func RevokeSessionById(c *Context, sessionId string) {
if result := <-Srv.Store.Session().Get(c.T, sessionId); result.Err != nil {
if result := <-Srv.Store.Session().Get(sessionId); result.Err != nil {
c.Err = result.Err
} else {
session := result.Data.(*model.Session)
c.LogAudit("session_id=" + session.Id)
if session.IsOAuth {
RevokeAccessToken(c.T, session.Token)
RevokeAccessToken(session.Token)
} else {
sessionCache.Remove(session.Token)
if result := <-Srv.Store.Session().Remove(c.T, session.Id); result.Err != nil {
if result := <-Srv.Store.Session().Remove(session.Id); result.Err != nil {
c.Err = result.Err
}
}
@@ -725,7 +723,7 @@ func RevokeSessionById(c *Context, sessionId string) {
}
func RevokeAllSession(c *Context, userId string) {
if result := <-Srv.Store.Session().GetSessions(c.T, userId); result.Err != nil {
if result := <-Srv.Store.Session().GetSessions(userId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -734,10 +732,10 @@ func RevokeAllSession(c *Context, userId string) {
for _, session := range sessions {
c.LogAuditWithUserId(userId, "session_id="+session.Id)
if session.IsOAuth {
RevokeAccessToken(c.T, session.Token)
RevokeAccessToken(session.Token)
} else {
sessionCache.Remove(session.Token)
if result := <-Srv.Store.Session().Remove(c.T, session.Id); result.Err != nil {
if result := <-Srv.Store.Session().Remove(session.Id); result.Err != nil {
c.Err = result.Err
return
}
@@ -755,7 +753,7 @@ func getSessions(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Session().GetSessions(c.T, id); result.Err != nil {
if result := <-Srv.Store.Session().GetSessions(id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -781,7 +779,7 @@ func logout(c *Context, w http.ResponseWriter, r *http.Request) {
func Logout(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
c.RemoveSessionCookie(w, r)
if result := <-Srv.Store.Session().Remove(c.T, c.Session.Id); result.Err != nil {
if result := <-Srv.Store.Session().Remove(c.Session.Id); result.Err != nil {
c.Err = result.Err
return
}
@@ -793,7 +791,7 @@ func getMe(c *Context, w http.ResponseWriter, r *http.Request) {
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.RemoveSessionCookie(w, r)
l4g.Error("Error in getting users profile for id=%v forcing logout", c.Session.UserId)
@@ -817,7 +815,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.User().Get(c.T, id); result.Err != nil {
if result := <-Srv.Store.User().Get(id); result.Err != nil {
c.Err = result.Err
return
} else if HandleEtag(result.Data.(*model.User).Etag(), w, r) {
@@ -845,12 +843,12 @@ func getProfiles(c *Context, w http.ResponseWriter, r *http.Request) {
id = c.Session.TeamId
}
etag := (<-Srv.Store.User().GetEtagForProfiles(c.T, id)).Data.(string)
etag := (<-Srv.Store.User().GetEtagForProfiles(id)).Data.(string)
if HandleEtag(etag, w, r) {
return
}
if result := <-Srv.Store.User().GetProfiles(c.T, id); result.Err != nil {
if result := <-Srv.Store.User().GetProfiles(id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -884,8 +882,8 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
userChan := Srv.Store.User().Get(c.T, id)
auditChan := Srv.Store.Audit().Get(c.T, id, 20)
userChan := Srv.Store.User().Get(id)
auditChan := Srv.Store.Audit().Get(id, 20)
if c.Err = (<-userChan).Err; c.Err != nil {
return
@@ -990,7 +988,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
if result := <-Srv.Store.User().Get(c.T, id); result.Err != nil {
if result := <-Srv.Store.User().Get(id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1105,7 +1103,7 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
Srv.Store.User().UpdateLastPictureUpdate(c.T, c.Session.UserId)
Srv.Store.User().UpdateLastPictureUpdate(c.Session.UserId)
c.LogAudit("")
@@ -1125,7 +1123,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.User().Update(c.T, user, false); result.Err != nil {
if result := <-Srv.Store.User().Update(user, false); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1134,7 +1132,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
rusers := result.Data.([2]*model.User)
if rusers[0].Email != rusers[1].Email {
if tresult := <-Srv.Store.Team().Get(c.T, rusers[1].TeamId); tresult.Err != nil {
if tresult := <-Srv.Store.Team().Get(rusers[1].TeamId); tresult.Err != nil {
l4g.Error(tresult.Err.Message)
} else {
team := tresult.Data.(*model.Team)
@@ -1182,7 +1180,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
var result store.StoreResult
if result = <-Srv.Store.User().Get(c.T, userId); result.Err != nil {
if result = <-Srv.Store.User().Get(userId); result.Err != nil {
c.Err = result.Err
return
}
@@ -1195,7 +1193,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
user := result.Data.(*model.User)
tchan := Srv.Store.Team().Get(c.T, user.TeamId)
tchan := Srv.Store.Team().Get(user.TeamId)
if user.AuthData != "" {
c.LogAudit("failed - tried to update user password who was logged in through oauth")
@@ -1210,7 +1208,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if uresult := <-Srv.Store.User().UpdatePassword(c.T, c.Session.UserId, model.HashPassword(newPassword)); uresult.Err != nil {
if uresult := <-Srv.Store.User().UpdatePassword(c.Session.UserId, model.HashPassword(newPassword)); uresult.Err != nil {
c.Err = model.NewAppError("updatePassword", "Update password failed", uresult.Err.Error())
c.Err.StatusCode = http.StatusForbidden
return
@@ -1252,7 +1250,7 @@ func updateRoles(c *Context, w http.ResponseWriter, r *http.Request) {
}
var user *model.User
if result := <-Srv.Store.User().Get(c.T, user_id); result.Err != nil {
if result := <-Srv.Store.User().Get(user_id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1280,8 +1278,8 @@ func updateRoles(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
uchan := Srv.Store.Session().UpdateRoles(c.T, user.Id, new_roles)
gchan := Srv.Store.Session().GetSessions(c.T, user.Id)
uchan := Srv.Store.Session().UpdateRoles(user.Id, new_roles)
gchan := Srv.Store.Session().GetSessions(user.Id)
if result := <-uchan; result.Err != nil {
// soft error since the user roles were still updated
@@ -1309,7 +1307,7 @@ func UpdateRoles(c *Context, user *model.User, roles string) *model.User {
if !model.IsInRole(roles, model.ROLE_SYSTEM_ADMIN) {
if model.IsInRole(user.Roles, model.ROLE_TEAM_ADMIN) && !model.IsInRole(roles, model.ROLE_TEAM_ADMIN) {
if result := <-Srv.Store.User().GetProfiles(c.T, user.TeamId); result.Err != nil {
if result := <-Srv.Store.User().GetProfiles(user.TeamId); result.Err != nil {
c.Err = result.Err
return nil
} else {
@@ -1332,7 +1330,7 @@ func UpdateRoles(c *Context, user *model.User, roles string) *model.User {
user.Roles = roles
var ruser *model.User
if result := <-Srv.Store.User().Update(c.T, user, true); result.Err != nil {
if result := <-Srv.Store.User().Update(user, true); result.Err != nil {
c.Err = result.Err
return nil
} else {
@@ -1355,7 +1353,7 @@ func updateActive(c *Context, w http.ResponseWriter, r *http.Request) {
active := props["active"] == "true"
var user *model.User
if result := <-Srv.Store.User().Get(c.T, user_id); result.Err != nil {
if result := <-Srv.Store.User().Get(user_id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1374,7 +1372,7 @@ func updateActive(c *Context, w http.ResponseWriter, r *http.Request) {
// make sure there is at least 1 other active admin
if !active && model.IsInRole(user.Roles, model.ROLE_TEAM_ADMIN) {
if result := <-Srv.Store.User().GetProfiles(c.T, user.TeamId); result.Err != nil {
if result := <-Srv.Store.User().GetProfiles(user.TeamId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1407,7 +1405,7 @@ func UpdateActive(c *Context, user *model.User, active bool) *model.User {
user.DeleteAt = model.GetMillis()
}
if result := <-Srv.Store.User().Update(c.T, user, true); result.Err != nil {
if result := <-Srv.Store.User().Update(user, true); result.Err != nil {
c.Err = result.Err
return nil
} else {
@@ -1436,39 +1434,39 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
UpdateActive(c, user, false)
if result := <-Srv.Store.Session().PermanentDeleteSessionsByUser(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.Session().PermanentDeleteSessionsByUser(user.Id); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.OAuth().PermanentDeleteAuthDataByUser(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.OAuth().PermanentDeleteAuthDataByUser(user.Id); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.Webhook().PermanentDeleteIncomingByUser(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.Webhook().PermanentDeleteIncomingByUser(user.Id); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.Webhook().PermanentDeleteOutgoingByUser(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.Webhook().PermanentDeleteOutgoingByUser(user.Id); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.Preference().PermanentDeleteByUser(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.Preference().PermanentDeleteByUser(user.Id); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.Channel().PermanentDeleteMembersByUser(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.Channel().PermanentDeleteMembersByUser(user.Id); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.Post().PermanentDeleteByUser(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.Post().PermanentDeleteByUser(user.Id); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.User().PermanentDelete(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.User().PermanentDelete(user.Id); result.Err != nil {
return result.Err
}
if result := <-Srv.Store.Audit().PermanentDeleteByUser(c.T, user.Id); result.Err != nil {
if result := <-Srv.Store.Audit().PermanentDeleteByUser(user.Id); result.Err != nil {
return result.Err
}
@@ -1494,7 +1492,7 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
}
var team *model.Team
if result := <-Srv.Store.Team().GetByName(c.T, name); result.Err != nil {
if result := <-Srv.Store.Team().GetByName(name); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1502,7 +1500,7 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
}
var user *model.User
if result := <-Srv.Store.User().GetByEmail(c.T, team.Id, email); result.Err != nil {
if result := <-Srv.Store.User().GetByEmail(team.Id, email); result.Err != nil {
c.Err = model.NewAppError("sendPasswordReset", "We couldnt find an account with that address.", "email="+email+" team_id="+team.Id)
return
} else {
@@ -1583,7 +1581,7 @@ func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAuditWithUserId(userId, "attempt")
var team *model.Team
if result := <-Srv.Store.Team().GetByName(c.T, name); result.Err != nil {
if result := <-Srv.Store.Team().GetByName(name); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1591,7 +1589,7 @@ func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
}
var user *model.User
if result := <-Srv.Store.User().Get(c.T, userId); result.Err != nil {
if result := <-Srv.Store.User().Get(userId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1622,7 +1620,7 @@ func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if result := <-Srv.Store.User().UpdatePassword(c.T, userId, model.HashPassword(newPassword)); result.Err != nil {
if result := <-Srv.Store.User().UpdatePassword(userId, model.HashPassword(newPassword)); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1701,7 +1699,7 @@ func updateUserNotify(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
uchan := Srv.Store.User().Get(c.T, user_id)
uchan := Srv.Store.User().Get(user_id)
if !c.HasPermissionsToUser(user_id, "updateUserNotify") {
return
@@ -1737,7 +1735,7 @@ func updateUserNotify(c *Context, w http.ResponseWriter, r *http.Request) {
user.NotifyProps = props
if result := <-Srv.Store.User().Update(c.T, user, false); result.Err != nil {
if result := <-Srv.Store.User().Update(user, false); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1758,7 +1756,7 @@ func getStatuses(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
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 {
c.Err = result.Err
return
} else {
@@ -1822,7 +1820,7 @@ func GetAuthorizationCode(c *Context, service, teamName string, props map[string
return authUrl, nil
}
func AuthorizeOAuthUser(T goi18n.TranslateFunc, service, code, state, redirectUri string) (io.ReadCloser, *model.Team, map[string]string, *model.AppError) {
func AuthorizeOAuthUser(service, code, state, redirectUri string) (io.ReadCloser, *model.Team, map[string]string, *model.AppError) {
sso := utils.Cfg.GetSSOService(service)
if sso == nil || !sso.Enable {
return nil, nil, nil, model.NewAppError("AuthorizeOAuthUser", "Unsupported OAuth service provider", "service="+service)
@@ -1847,7 +1845,7 @@ func AuthorizeOAuthUser(T goi18n.TranslateFunc, service, code, state, redirectUr
return nil, nil, nil, model.NewAppError("AuthorizeOAuthUser", "Invalid state; missing team name", "")
}
tchan := Srv.Store.Team().GetByName(T, teamName)
tchan := Srv.Store.Team().GetByName(teamName)
p := url.Values{}
p.Set("client_id", sso.Id)
@@ -1900,13 +1898,13 @@ func AuthorizeOAuthUser(T goi18n.TranslateFunc, service, code, state, redirectUr
}
func IsUsernameTaken(T goi18n.TranslateFunc, name string, teamId string) bool {
func IsUsernameTaken(name string, teamId string) bool {
if !model.IsValidUsername(name) {
return false
}
if result := <-Srv.Store.User().GetByUsername(T, teamId, name); result.Err != nil {
if result := <-Srv.Store.User().GetByUsername(teamId, name); result.Err != nil {
return false
} else {
return true
@@ -1945,7 +1943,7 @@ func switchToSSO(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt")
var team *model.Team
if result := <-Srv.Store.Team().GetByName(c.T, teamName); result.Err != nil {
if result := <-Srv.Store.Team().GetByName(teamName); result.Err != nil {
c.LogAudit("fail - couldn't get team")
c.Err = result.Err
return
@@ -1954,7 +1952,7 @@ func switchToSSO(c *Context, w http.ResponseWriter, r *http.Request) {
}
var user *model.User
if result := <-Srv.Store.User().GetByEmail(c.T, team.Id, email); result.Err != nil {
if result := <-Srv.Store.User().GetByEmail(team.Id, email); result.Err != nil {
c.LogAudit("fail - couldn't get user")
c.Err = result.Err
return
@@ -2005,7 +2003,7 @@ func CompleteSwitchWithOAuth(c *Context, w http.ResponseWriter, r *http.Request,
}
var user *model.User
if result := <-Srv.Store.User().GetByEmail(c.T, team.Id, email); result.Err != nil {
if result := <-Srv.Store.User().GetByEmail(team.Id, email); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -2017,7 +2015,7 @@ func CompleteSwitchWithOAuth(c *Context, w http.ResponseWriter, r *http.Request,
return
}
if result := <-Srv.Store.User().UpdateAuthData(c.T, user.Id, service, authData); result.Err != nil {
if result := <-Srv.Store.User().UpdateAuthData(user.Id, service, authData); result.Err != nil {
c.Err = result.Err
return
}
@@ -2049,7 +2047,7 @@ func switchToEmail(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt")
var team *model.Team
if result := <-Srv.Store.Team().GetByName(c.T, teamName); result.Err != nil {
if result := <-Srv.Store.Team().GetByName(teamName); result.Err != nil {
c.LogAudit("fail - couldn't get team")
c.Err = result.Err
return
@@ -2058,7 +2056,7 @@ func switchToEmail(c *Context, w http.ResponseWriter, r *http.Request) {
}
var user *model.User
if result := <-Srv.Store.User().GetByEmail(c.T, team.Id, email); result.Err != nil {
if result := <-Srv.Store.User().GetByEmail(team.Id, email); result.Err != nil {
c.LogAudit("fail - couldn't get user")
c.Err = result.Err
return
@@ -2073,7 +2071,7 @@ func switchToEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.User().UpdatePassword(c.T, c.Session.UserId, model.HashPassword(password)); result.Err != nil {
if result := <-Srv.Store.User().UpdatePassword(c.Session.UserId, model.HashPassword(password)); result.Err != nil {
c.LogAudit("fail - database issue")
c.Err = result.Err
return

View File

@@ -101,7 +101,7 @@ func TestLogin(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser, _ := Client.CreateUser(&user, "")
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Data.(*model.User).Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
if result, err := Client.LoginById(ruser.Data.(*model.User).Id, user.Password); err != nil {
t.Fatal(err)
@@ -170,7 +170,7 @@ func TestLoginWithDeviceId(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
deviceId := model.NewId()
if result, err := Client.LoginByEmailWithDevice(team.Name, user.Email, user.Password, deviceId); err != nil {
@@ -186,7 +186,7 @@ func TestLoginWithDeviceId(t *testing.T) {
t.Fatal(err)
}
if sresult := <-Srv.Store.Session().Get(utils.T, sessions[0].Id); sresult.Err == nil {
if sresult := <-Srv.Store.Session().Get(sessions[0].Id); sresult.Err == nil {
t.Fatal("session should have been removed")
}
}
@@ -201,7 +201,7 @@ func TestSessions(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
deviceId := model.NewId()
Client.LoginByEmailWithDevice(team.Name, user.Email, user.Password, deviceId)
@@ -253,18 +253,18 @@ func TestGetUser(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser, _ := Client.CreateUser(&user, "")
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Data.(*model.User).Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
user2 := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser2, _ := Client.CreateUser(&user2, "")
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser2.Data.(*model.User).Id))
store.Must(Srv.Store.User().VerifyEmail(ruser2.Data.(*model.User).Id))
team2 := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
rteam2, _ := Client.CreateTeam(&team2)
user3 := model.User{TeamId: rteam2.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser3, _ := Client.CreateUser(&user3, "")
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser3.Data.(*model.User).Id))
store.Must(Srv.Store.User().VerifyEmail(ruser3.Data.(*model.User).Id))
Client.LoginByEmail(team.Name, user.Email, user.Password)
@@ -345,7 +345,7 @@ func TestGetAudits(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser, _ := Client.CreateUser(&user, "")
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Data.(*model.User).Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
time.Sleep(100 * time.Millisecond)
@@ -398,7 +398,7 @@ func TestUserCreateImage(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
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")
@@ -432,7 +432,7 @@ func TestUserUploadProfileImage(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
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))
if utils.Cfg.FileSettings.DriverName != "" {
@@ -538,7 +538,7 @@ func TestUserUpdate(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd", LastActivityAt: time1, LastPingAt: time1, Roles: ""}
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))
if _, err := Client.UpdateUser(user); err == nil {
t.Fatal("Should have errored")
@@ -594,7 +594,7 @@ func TestUserUpdate(t *testing.T) {
user2 := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
@@ -613,7 +613,7 @@ func TestUserUpdatePassword(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
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))
if _, err := Client.UpdateUserPassword(user.Id, "pwd", "newpwd"); err == nil {
t.Fatal("Should have errored")
@@ -672,11 +672,11 @@ func TestUserUpdateRoles(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: "test@nowhere.com", Nickname: "Corey Hulen", Password: "pwd"}
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))
user2 := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
data := make(map[string]string)
data["user_id"] = user.Id
@@ -697,7 +697,7 @@ func TestUserUpdateRoles(t *testing.T) {
user3 := &model.User{TeamId: team2.Id, Email: "test@nowhere.com", Nickname: "Corey Hulen", Password: "pwd"}
user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user3.Id))
store.Must(Srv.Store.User().VerifyEmail(user3.Id))
Client.LoginByEmail(team2.Name, user3.Email, "pwd")
@@ -742,11 +742,11 @@ func TestUserUpdateActive(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: "test@nowhere.com", Nickname: "Corey Hulen", Password: "pwd"}
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))
user2 := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
if _, err := Client.UpdateActive(user.Id, false); err == nil {
t.Fatal("Should have errored, not logged in")
@@ -763,7 +763,7 @@ func TestUserUpdateActive(t *testing.T) {
user3 := &model.User{TeamId: team2.Id, Email: "test@nowhere.com", Nickname: "Corey Hulen", Password: "pwd"}
user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user3.Id))
store.Must(Srv.Store.User().VerifyEmail(user3.Id))
Client.LoginByEmail(team2.Name, user3.Email, "pwd")
@@ -806,7 +806,7 @@ func TestUserPermDelete(t *testing.T) {
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)
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")
@@ -845,7 +845,7 @@ func TestSendPasswordReset(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
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))
data := make(map[string]string)
data["email"] = user.Email
@@ -878,7 +878,7 @@ func TestSendPasswordReset(t *testing.T) {
user2 := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", AuthData: "1", AuthService: "random"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
data["email"] = user2.Email
data["name"] = team.Name
@@ -895,7 +895,7 @@ func TestResetPassword(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
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))
data := make(map[string]string)
data["new_password"] = "newpwd"
@@ -972,7 +972,7 @@ func TestResetPassword(t *testing.T) {
user2 := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", AuthData: "1", AuthService: "random"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
data["new_password"] = "newpwd"
props["user_id"] = user2.Id
@@ -993,7 +993,7 @@ func TestUserUpdateNotify(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd", Roles: ""}
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))
data := make(map[string]string)
data["user_id"] = user.Id
@@ -1088,11 +1088,11 @@ func TestStatuses(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
user2 := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser2 := Client.Must(Client.CreateUser(&user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser2.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser2.Id))
Client.LoginByEmail(team.Name, user.Email, user.Password)
@@ -1125,7 +1125,7 @@ func TestSwitchToSSO(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
m := map[string]string{}
if _, err := Client.SwitchToSSO(m); err == nil {
@@ -1174,11 +1174,11 @@ func TestSwitchToEmail(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
user2 := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
ruser2 := Client.Must(Client.CreateUser(&user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(utils.T, ruser2.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser2.Id))
m := map[string]string{}
if _, err := Client.SwitchToSSO(m); err == nil {

View File

@@ -8,7 +8,6 @@ import (
"github.com/gorilla/websocket"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
"time"
)
@@ -30,8 +29,8 @@ type WebConn struct {
func NewWebConn(ws *websocket.Conn, teamId string, userId string, sessionId string) *WebConn {
go func() {
achan := Srv.Store.User().UpdateUserAndSessionActivity(utils.T, userId, sessionId, model.GetMillis())
pchan := Srv.Store.User().UpdateLastPingAt(utils.T, userId, model.GetMillis())
achan := Srv.Store.User().UpdateUserAndSessionActivity(userId, sessionId, model.GetMillis())
pchan := Srv.Store.User().UpdateLastPingAt(userId, model.GetMillis())
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)
@@ -56,7 +55,7 @@ func (c *WebConn) readPump() {
c.WebSocket.SetReadDeadline(time.Now().Add(PONG_WAIT))
go func() {
if result := <-Srv.Store.User().UpdateLastPingAt(utils.T, 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)
}
}()
@@ -108,7 +107,7 @@ func (c *WebConn) writePump() {
}
func (c *WebConn) updateChannelAccessCache(channelId string) bool {
allowed := hasPermissionsToChannel(Srv.Store.Channel().CheckPermissionsTo(utils.T, c.TeamId, channelId, c.UserId))
allowed := hasPermissionsToChannel(Srv.Store.Channel().CheckPermissionsTo(c.TeamId, channelId, c.UserId))
c.ChannelAccessCache[channelId] = allowed
return allowed

View File

@@ -22,7 +22,7 @@ func TestSocket(t *testing.T) {
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)
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")
channel1 := &model.Channel{DisplayName: "Test Web Scoket 1", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
@@ -41,7 +41,7 @@ func TestSocket(t *testing.T) {
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)
store.Must(Srv.Store.User().VerifyEmail(utils.T, user2.Id))
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
header2 := http.Header{}

View File

@@ -41,8 +41,8 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().Get(c.T, hook.ChannelId)
pchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, hook.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().Get(hook.ChannelId)
pchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, hook.ChannelId, c.Session.UserId)
hook.UserId = c.Session.UserId
hook.TeamId = c.Session.TeamId
@@ -62,7 +62,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if result := <-Srv.Store.Webhook().SaveIncoming(c.T, hook); result.Err != nil {
if result := <-Srv.Store.Webhook().SaveIncoming(hook); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -89,7 +89,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Webhook().GetIncoming(c.T, id); result.Err != nil {
if result := <-Srv.Store.Webhook().GetIncoming(id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -100,7 +100,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if err := (<-Srv.Store.Webhook().DeleteIncoming(c.T, id, model.GetMillis())).Err; err != nil {
if err := (<-Srv.Store.Webhook().DeleteIncoming(id, model.GetMillis())).Err; err != nil {
c.Err = err
return
}
@@ -116,7 +116,7 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Webhook().GetIncomingByUser(c.T, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Webhook().GetIncomingByUser(c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -145,8 +145,8 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
hook.TeamId = c.Session.TeamId
if len(hook.ChannelId) != 0 {
cchan := Srv.Store.Channel().Get(c.T, hook.ChannelId)
pchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, hook.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().Get(hook.ChannelId)
pchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, hook.ChannelId, c.Session.UserId)
var channel *model.Channel
if result := <-cchan; result.Err != nil {
@@ -171,7 +171,7 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Webhook().SaveOutgoing(c.T, hook); result.Err != nil {
if result := <-Srv.Store.Webhook().SaveOutgoing(hook); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -188,7 +188,7 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Webhook().GetOutgoingByCreator(c.T, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Webhook().GetOutgoingByCreator(c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -214,7 +214,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if result := <-Srv.Store.Webhook().GetOutgoing(c.T, id); result.Err != nil {
if result := <-Srv.Store.Webhook().GetOutgoing(id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -225,7 +225,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if err := (<-Srv.Store.Webhook().DeleteOutgoing(c.T, id, model.GetMillis())).Err; err != nil {
if err := (<-Srv.Store.Webhook().DeleteOutgoing(id, model.GetMillis())).Err; err != nil {
c.Err = err
return
}
@@ -252,7 +252,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
}
var hook *model.OutgoingWebhook
if result := <-Srv.Store.Webhook().GetOutgoing(c.T, id); result.Err != nil {
if result := <-Srv.Store.Webhook().GetOutgoing(id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -267,7 +267,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
hook.Token = model.NewId()
if result := <-Srv.Store.Webhook().UpdateOutgoing(c.T, hook); result.Err != nil {
if result := <-Srv.Store.Webhook().UpdateOutgoing(hook); result.Err != nil {
c.Err = result.Err
return
} else {

View File

@@ -19,7 +19,7 @@ func TestCreateIncomingHook(t *testing.T) {
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)
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")
@@ -82,7 +82,7 @@ func TestListIncomingHooks(t *testing.T) {
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)
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")
@@ -120,7 +120,7 @@ func TestDeleteIncomingHook(t *testing.T) {
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)
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")
@@ -160,7 +160,7 @@ func TestCreateOutgoingHook(t *testing.T) {
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)
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")
@@ -223,7 +223,7 @@ func TestListOutgoingHooks(t *testing.T) {
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)
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")
@@ -261,7 +261,7 @@ func TestDeleteOutgoingHook(t *testing.T) {
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)
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")
@@ -301,7 +301,7 @@ func TestRegenOutgoingHookToken(t *testing.T) {
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)
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")

View File

@@ -4,18 +4,16 @@
package manualtesting
import (
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/api"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"hash/fnv"
"math/rand"
"net/http"
"net/url"
"strconv"
"time"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/api"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type TestEnvironment struct {
@@ -72,7 +70,7 @@ func manualTest(c *api.Context, w http.ResponseWriter, r *http.Request) {
Type: model.TEAM_OPEN,
}
if result := <-api.Srv.Store.Team().Save(c.T, team); result.Err != nil {
if result := <-api.Srv.Store.Team().Save(team); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -100,7 +98,7 @@ func manualTest(c *api.Context, w http.ResponseWriter, r *http.Request) {
c.Err = err
return
}
api.Srv.Store.User().VerifyEmail(c.T, result.Data.(*model.User).Id)
api.Srv.Store.User().VerifyEmail(result.Data.(*model.User).Id)
newuser := result.Data.(*model.User)
userID = newuser.Id
@@ -151,9 +149,9 @@ func manualTest(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
}
func getChannelID(T goi18n.TranslateFunc, channelname string, teamid string, userid string) (id string, err bool) {
func getChannelID(channelname string, teamid string, userid string) (id string, err bool) {
// Grab all the channels
result := <-api.Srv.Store.Channel().GetChannels(T, teamid, userid)
result := <-api.Srv.Store.Channel().GetChannels(teamid, userid)
if result.Err != nil {
l4g.Debug("Unable to get channels")
return "", false

View File

@@ -6,7 +6,6 @@ package manualtesting
import (
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
const LINK_POST_TEXT = `
@@ -22,7 +21,7 @@ https://medium.com/@slackhq/11-useful-tips-for-getting-the-most-of-slack-5dfb3d1
func testAutoLink(env TestEnvironment) *model.AppError {
l4g.Info("Manual Auto Link Test")
channelID, err := getChannelID(utils.T, model.DEFAULT_CHANNEL, env.CreatedTeamId, env.CreatedUserId)
channelID, err := getChannelID(model.DEFAULT_CHANNEL, env.CreatedTeamId, env.CreatedUserId)
if err != true {
return model.NewAppError("/manualtest", "Unable to get channels", "")
}

View File

@@ -92,14 +92,14 @@ func main() {
}
func setDiagnosticId() {
if result := <-api.Srv.Store.System().Get(utils.T); result.Err == nil {
if result := <-api.Srv.Store.System().Get(); result.Err == nil {
props := result.Data.(model.StringMap)
id := props[model.SYSTEM_DIAGNOSTIC_ID]
if len(id) == 0 {
id = model.NewId()
systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
<-api.Srv.Store.System().Save(utils.T, systemId)
<-api.Srv.Store.System().Save(systemId)
}
utils.CfgDiagnosticId = id
@@ -110,7 +110,7 @@ func runSecurityAndDiagnosticsJobAndForget() {
go func() {
for {
if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert {
if result := <-api.Srv.Store.System().Get(utils.T); result.Err == nil {
if result := <-api.Srv.Store.System().Get(); result.Err == nil {
props := result.Data.(model.StringMap)
lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0)
currentTime := model.GetMillis()
@@ -135,16 +135,16 @@ func runSecurityAndDiagnosticsJobAndForget() {
systemSecurityLastTime := &model.System{Name: model.SYSTEM_LAST_SECURITY_TIME, Value: strconv.FormatInt(currentTime, 10)}
if lastSecurityTime == 0 {
<-api.Srv.Store.System().Save(utils.T, systemSecurityLastTime)
<-api.Srv.Store.System().Save(systemSecurityLastTime)
} else {
<-api.Srv.Store.System().Update(utils.T, systemSecurityLastTime)
<-api.Srv.Store.System().Update(systemSecurityLastTime)
}
if ucr := <-api.Srv.Store.User().GetTotalUsersCount(utils.T); ucr.Err == nil {
if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
v.Set(utils.PROP_DIAGNOSTIC_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
}
if ucr := <-api.Srv.Store.User().GetTotalActiveUsersCount(utils.T); ucr.Err == nil {
if ucr := <-api.Srv.Store.User().GetTotalActiveUsersCount(); ucr.Err == nil {
v.Set(utils.PROP_DIAGNOSTIC_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
}
@@ -159,7 +159,7 @@ func runSecurityAndDiagnosticsJobAndForget() {
for _, bulletin := range bulletins {
if bulletin.AppliesToVersion == model.CurrentVersion {
if props["SecurityBulletin_"+bulletin.Id] == "" {
if results := <-api.Srv.Store.User().GetSystemAdminProfiles(utils.T); results.Err != nil {
if results := <-api.Srv.Store.User().GetSystemAdminProfiles(); results.Err != nil {
l4g.Error("Failed to get system admins for security update information from Mattermost.")
return
} else {
@@ -185,7 +185,7 @@ func runSecurityAndDiagnosticsJobAndForget() {
}
bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id}
<-api.Srv.Store.System().Save(utils.T, bulletinSeen)
<-api.Srv.Store.System().Save(bulletinSeen)
}
}
}
@@ -301,7 +301,7 @@ func cmdCreateUser() {
splits := strings.Split(strings.Replace(flagEmail, "@", " ", -1), " ")
user.Username = splits[0]
if result := <-api.Srv.Store.Team().GetByName(utils.T, flagTeamName); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
} else {
@@ -309,7 +309,7 @@ func cmdCreateUser() {
user.TeamId = team.Id
}
_, err := api.CreateUser(utils.T, team, user)
_, err := api.CreateUser(team, user)
if err != nil {
if err.Message != "An account with that email already exists." {
l4g.Error("%v", err)
@@ -358,7 +358,7 @@ func cmdAssignRole() {
c.IpAddress = "cmd_line"
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(utils.T, flagTeamName); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
} else {
@@ -366,7 +366,7 @@ func cmdAssignRole() {
}
var user *model.User
if result := <-api.Srv.Store.User().GetByEmail(utils.T, team.Id, flagEmail); result.Err != nil {
if result := <-api.Srv.Store.User().GetByEmail(team.Id, flagEmail); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
} else {
@@ -412,7 +412,7 @@ func cmdResetPassword() {
c.IpAddress = "cmd_line"
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(utils.T, flagTeamName); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
} else {
@@ -420,14 +420,14 @@ func cmdResetPassword() {
}
var user *model.User
if result := <-api.Srv.Store.User().GetByEmail(utils.T, team.Id, flagEmail); result.Err != nil {
if result := <-api.Srv.Store.User().GetByEmail(team.Id, flagEmail); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
} else {
user = result.Data.(*model.User)
}
if result := <-api.Srv.Store.User().UpdatePassword(utils.T, user.Id, model.HashPassword(flagPassword)); result.Err != nil {
if result := <-api.Srv.Store.User().UpdatePassword(user.Id, model.HashPassword(flagPassword)); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
}
@@ -455,7 +455,7 @@ func cmdPermDeleteUser() {
c.IpAddress = "cmd_line"
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(utils.T, flagTeamName); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
} else {
@@ -463,7 +463,7 @@ func cmdPermDeleteUser() {
}
var user *model.User
if result := <-api.Srv.Store.User().GetByEmail(utils.T, team.Id, flagEmail); result.Err != nil {
if result := <-api.Srv.Store.User().GetByEmail(team.Id, flagEmail); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
} else {
@@ -506,7 +506,7 @@ func cmdPermDeleteTeam() {
c.IpAddress = "cmd_line"
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(utils.T, flagTeamName); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
} else {

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlAuditStore struct {
@@ -35,7 +34,7 @@ func (s SqlAuditStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_audits_user_id", "Audits", "UserId")
}
func (s SqlAuditStore) Save(T goi18n.TranslateFunc, audit *model.Audit) StoreChannel {
func (s SqlAuditStore) Save(audit *model.Audit) StoreChannel {
storeChannel := make(StoreChannel)
@@ -58,7 +57,7 @@ func (s SqlAuditStore) Save(T goi18n.TranslateFunc, audit *model.Audit) StoreCha
return storeChannel
}
func (s SqlAuditStore) Get(T goi18n.TranslateFunc, user_id string, limit int) StoreChannel {
func (s SqlAuditStore) Get(user_id string, limit int) StoreChannel {
storeChannel := make(StoreChannel)
@@ -88,7 +87,7 @@ func (s SqlAuditStore) Get(T goi18n.TranslateFunc, user_id string, limit int) St
return storeChannel
}
func (s SqlAuditStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlAuditStore) PermanentDeleteByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing"
"time"
)
@@ -14,19 +13,19 @@ func TestSqlAuditStore(t *testing.T) {
Setup()
audit := &model.Audit{UserId: model.NewId(), IpAddress: "ipaddress", Action: "Action"}
Must(store.Audit().Save(utils.T, audit))
Must(store.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
Must(store.Audit().Save(utils.T, audit))
Must(store.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
Must(store.Audit().Save(utils.T, audit))
Must(store.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
audit.ExtraInfo = "extra"
time.Sleep(100 * time.Millisecond)
Must(store.Audit().Save(utils.T, audit))
Must(store.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
c := store.Audit().Get(utils.T, audit.UserId, 100)
c := store.Audit().Get(audit.UserId, 100)
result := <-c
audits := result.Data.(model.Audits)
@@ -38,7 +37,7 @@ func TestSqlAuditStore(t *testing.T) {
t.Fatal("Failed to save property for extra info")
}
c = store.Audit().Get(utils.T, "missing", 100)
c = store.Audit().Get("missing", 100)
result = <-c
audits = result.Data.(model.Audits)
@@ -46,7 +45,7 @@ func TestSqlAuditStore(t *testing.T) {
t.Fatal("Should have returned empty because user_id is missing")
}
if r2 := <-store.Audit().PermanentDeleteByUser(utils.T, audit.UserId); r2.Err != nil {
if r2 := <-store.Audit().PermanentDeleteByUser(audit.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
}

View File

@@ -7,7 +7,6 @@ import (
"github.com/go-gorp/gorp"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlChannelStore struct {
@@ -50,7 +49,7 @@ func (s SqlChannelStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_channelmembers_user_id", "ChannelMembers", "UserId")
}
func (s SqlChannelStore) Save(T goi18n.TranslateFunc, channel *model.Channel) StoreChannel {
func (s SqlChannelStore) Save(channel *model.Channel) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -61,7 +60,7 @@ func (s SqlChannelStore) Save(T goi18n.TranslateFunc, channel *model.Channel) St
if transaction, err := s.GetMaster().Begin(); err != nil {
result.Err = model.NewAppError("SqlChannelStore.Save", "Unable to open transaction", err.Error())
} else {
result = s.saveChannelT(T, transaction, channel)
result = s.saveChannelT(transaction, channel)
if result.Err != nil {
transaction.Rollback()
} else {
@@ -79,7 +78,7 @@ func (s SqlChannelStore) Save(T goi18n.TranslateFunc, channel *model.Channel) St
return storeChannel
}
func (s SqlChannelStore) SaveDirectChannel(T goi18n.TranslateFunc, directchannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel {
func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -91,7 +90,7 @@ func (s SqlChannelStore) SaveDirectChannel(T goi18n.TranslateFunc, directchannel
if transaction, err := s.GetMaster().Begin(); err != nil {
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "Unable to open transaction", err.Error())
} else {
channelResult := s.saveChannelT(T, transaction, directchannel)
channelResult := s.saveChannelT(transaction, directchannel)
if channelResult.Err != nil {
transaction.Rollback()
@@ -102,8 +101,8 @@ func (s SqlChannelStore) SaveDirectChannel(T goi18n.TranslateFunc, directchannel
member1.ChannelId = newChannel.Id
member2.ChannelId = newChannel.Id
member1Result := s.saveMemberT(T, transaction, member1, newChannel)
member2Result := s.saveMemberT(T, transaction, member2, newChannel)
member1Result := s.saveMemberT(transaction, member1, newChannel)
member2Result := s.saveMemberT(transaction, member2, newChannel)
if member1Result.Err != nil || member2Result.Err != nil {
transaction.Rollback()
@@ -133,7 +132,7 @@ func (s SqlChannelStore) SaveDirectChannel(T goi18n.TranslateFunc, directchannel
return storeChannel
}
func (s SqlChannelStore) saveChannelT(T goi18n.TranslateFunc, transaction *gorp.Transaction, channel *model.Channel) StoreResult {
func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *model.Channel) StoreResult {
result := StoreResult{}
if len(channel.Id) > 0 {
@@ -175,7 +174,7 @@ func (s SqlChannelStore) saveChannelT(T goi18n.TranslateFunc, transaction *gorp.
return result
}
func (s SqlChannelStore) Update(T goi18n.TranslateFunc, channel *model.Channel) StoreChannel {
func (s SqlChannelStore) Update(channel *model.Channel) StoreChannel {
storeChannel := make(StoreChannel)
@@ -215,7 +214,7 @@ func (s SqlChannelStore) Update(T goi18n.TranslateFunc, channel *model.Channel)
return storeChannel
}
func (s SqlChannelStore) extraUpdated(T goi18n.TranslateFunc, channel *model.Channel) StoreChannel {
func (s SqlChannelStore) extraUpdated(channel *model.Channel) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -243,15 +242,15 @@ func (s SqlChannelStore) extraUpdated(T goi18n.TranslateFunc, channel *model.Cha
return storeChannel
}
func (s SqlChannelStore) Get(T goi18n.TranslateFunc, id string) StoreChannel {
return s.get(T, id, false)
func (s SqlChannelStore) Get(id string) StoreChannel {
return s.get(id, false)
}
func (s SqlChannelStore) GetFromMaster(T goi18n.TranslateFunc, id string) StoreChannel {
return s.get(T, id, true)
func (s SqlChannelStore) GetFromMaster(id string) StoreChannel {
return s.get(id, true)
}
func (s SqlChannelStore) get(T goi18n.TranslateFunc, id string, master bool) StoreChannel {
func (s SqlChannelStore) get(id string, master bool) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -279,7 +278,7 @@ func (s SqlChannelStore) get(T goi18n.TranslateFunc, id string, master bool) Sto
return storeChannel
}
func (s SqlChannelStore) Delete(T goi18n.TranslateFunc, channelId string, time int64) StoreChannel {
func (s SqlChannelStore) Delete(channelId string, time int64) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -297,7 +296,7 @@ func (s SqlChannelStore) Delete(T goi18n.TranslateFunc, channelId string, time i
return storeChannel
}
func (s SqlChannelStore) PermanentDeleteByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -319,7 +318,7 @@ type channelWithMember struct {
model.ChannelMember
}
func (s SqlChannelStore) GetChannels(T goi18n.TranslateFunc, teamId string, userId string) StoreChannel {
func (s SqlChannelStore) GetChannels(teamId string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -352,7 +351,7 @@ func (s SqlChannelStore) GetChannels(T goi18n.TranslateFunc, teamId string, user
return storeChannel
}
func (s SqlChannelStore) GetMoreChannels(T goi18n.TranslateFunc, teamId string, userId string) StoreChannel {
func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -400,7 +399,7 @@ type channelIdWithCountAndUpdateAt struct {
UpdateAt int64
}
func (s SqlChannelStore) GetChannelCounts(T goi18n.TranslateFunc, teamId string, userId string) StoreChannel {
func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -429,7 +428,7 @@ func (s SqlChannelStore) GetChannelCounts(T goi18n.TranslateFunc, teamId string,
return storeChannel
}
func (s SqlChannelStore) GetByName(T goi18n.TranslateFunc, teamId string, name string) StoreChannel {
func (s SqlChannelStore) GetByName(teamId string, name string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -450,13 +449,13 @@ func (s SqlChannelStore) GetByName(T goi18n.TranslateFunc, teamId string, name s
return storeChannel
}
func (s SqlChannelStore) SaveMember(T goi18n.TranslateFunc, member *model.ChannelMember) StoreChannel {
func (s SqlChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
var result StoreResult
// Grab the channel we are saving this member to
if cr := <-s.GetFromMaster(T, member.ChannelId); cr.Err != nil {
if cr := <-s.GetFromMaster(member.ChannelId); cr.Err != nil {
result.Err = cr.Err
} else {
channel := cr.Data.(*model.Channel)
@@ -464,7 +463,7 @@ func (s SqlChannelStore) SaveMember(T goi18n.TranslateFunc, member *model.Channe
if transaction, err := s.GetMaster().Begin(); err != nil {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "Unable to open transaction", err.Error())
} else {
result = s.saveMemberT(T, transaction, member, channel)
result = s.saveMemberT(transaction, member, channel)
if result.Err != nil {
transaction.Rollback()
} else {
@@ -472,7 +471,7 @@ func (s SqlChannelStore) SaveMember(T goi18n.TranslateFunc, member *model.Channe
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "Unable to commit transaction", err.Error())
}
// If sucessfull record members have changed in channel
if mu := <-s.extraUpdated(T, channel); mu.Err != nil {
if mu := <-s.extraUpdated(channel); mu.Err != nil {
result.Err = mu.Err
}
}
@@ -486,7 +485,7 @@ func (s SqlChannelStore) SaveMember(T goi18n.TranslateFunc, member *model.Channe
return storeChannel
}
func (s SqlChannelStore) saveMemberT(T goi18n.TranslateFunc, transaction *gorp.Transaction, member *model.ChannelMember, channel *model.Channel) StoreResult {
func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *model.ChannelMember, channel *model.Channel) StoreResult {
result := StoreResult{}
member.PreSave()
@@ -507,7 +506,7 @@ func (s SqlChannelStore) saveMemberT(T goi18n.TranslateFunc, transaction *gorp.T
return result
}
func (s SqlChannelStore) UpdateMember(T goi18n.TranslateFunc, member *model.ChannelMember) StoreChannel {
func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -535,7 +534,7 @@ func (s SqlChannelStore) UpdateMember(T goi18n.TranslateFunc, member *model.Chan
return storeChannel
}
func (s SqlChannelStore) GetMembers(T goi18n.TranslateFunc, channelId string) StoreChannel {
func (s SqlChannelStore) GetMembers(channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -556,7 +555,7 @@ func (s SqlChannelStore) GetMembers(T goi18n.TranslateFunc, channelId string) St
return storeChannel
}
func (s SqlChannelStore) GetMember(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel {
func (s SqlChannelStore) GetMember(channelId string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -577,7 +576,7 @@ func (s SqlChannelStore) GetMember(T goi18n.TranslateFunc, channelId string, use
return storeChannel
}
func (s SqlChannelStore) GetMemberCount(T goi18n.TranslateFunc, channelId string) StoreChannel {
func (s SqlChannelStore) GetMemberCount(channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -597,7 +596,7 @@ func (s SqlChannelStore) GetMemberCount(T goi18n.TranslateFunc, channelId string
return storeChannel
}
func (s SqlChannelStore) GetExtraMembers(T goi18n.TranslateFunc, channelId string, limit int) StoreChannel {
func (s SqlChannelStore) GetExtraMembers(channelId string, limit int) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -628,14 +627,14 @@ func (s SqlChannelStore) GetExtraMembers(T goi18n.TranslateFunc, channelId strin
return storeChannel
}
func (s SqlChannelStore) RemoveMember(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel {
func (s SqlChannelStore) RemoveMember(channelId string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
// Grab the channel we are saving this member to
if cr := <-s.Get(T, channelId); cr.Err != nil {
if cr := <-s.Get(channelId); cr.Err != nil {
result.Err = cr.Err
} else {
channel := cr.Data.(*model.Channel)
@@ -645,7 +644,7 @@ func (s SqlChannelStore) RemoveMember(T goi18n.TranslateFunc, channelId string,
result.Err = model.NewAppError("SqlChannelStore.RemoveMember", "We couldn't remove the channel member", "channel_id="+channelId+", user_id="+userId+", "+err.Error())
} else {
// If sucessfull record members have changed in channel
if mu := <-s.extraUpdated(T, channel); mu.Err != nil {
if mu := <-s.extraUpdated(channel); mu.Err != nil {
result.Err = mu.Err
}
}
@@ -658,7 +657,7 @@ func (s SqlChannelStore) RemoveMember(T goi18n.TranslateFunc, channelId string,
return storeChannel
}
func (s SqlChannelStore) PermanentDeleteMembersByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -675,7 +674,7 @@ func (s SqlChannelStore) PermanentDeleteMembersByUser(T goi18n.TranslateFunc, us
return storeChannel
}
func (s SqlChannelStore) CheckPermissionsTo(T goi18n.TranslateFunc, teamId string, channelId string, userId string) StoreChannel {
func (s SqlChannelStore) CheckPermissionsTo(teamId string, channelId string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -707,7 +706,7 @@ func (s SqlChannelStore) CheckPermissionsTo(T goi18n.TranslateFunc, teamId strin
return storeChannel
}
func (s SqlChannelStore) CheckPermissionsToByName(T goi18n.TranslateFunc, teamId string, channelName string, userId string) StoreChannel {
func (s SqlChannelStore) CheckPermissionsToByName(teamId string, channelName string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -739,7 +738,7 @@ func (s SqlChannelStore) CheckPermissionsToByName(T goi18n.TranslateFunc, teamId
return storeChannel
}
func (s SqlChannelStore) CheckOpenChannelPermissions(T goi18n.TranslateFunc, teamId string, channelId string) StoreChannel {
func (s SqlChannelStore) CheckOpenChannelPermissions(teamId string, channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -768,7 +767,7 @@ func (s SqlChannelStore) CheckOpenChannelPermissions(T goi18n.TranslateFunc, tea
return storeChannel
}
func (s SqlChannelStore) UpdateLastViewedAt(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel {
func (s SqlChannelStore) UpdateLastViewedAt(channelId string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -816,7 +815,7 @@ func (s SqlChannelStore) UpdateLastViewedAt(T goi18n.TranslateFunc, channelId st
return storeChannel
}
func (s SqlChannelStore) IncrementMentionCount(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel {
func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -842,7 +841,7 @@ func (s SqlChannelStore) IncrementMentionCount(T goi18n.TranslateFunc, channelId
return storeChannel
}
func (s SqlChannelStore) GetForExport(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (s SqlChannelStore) GetForExport(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -864,7 +863,7 @@ func (s SqlChannelStore) GetForExport(T goi18n.TranslateFunc, teamId string) Sto
return storeChannel
}
func (s SqlChannelStore) AnalyticsTypeCount(T goi18n.TranslateFunc, teamId string, channelType string) StoreChannel {
func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing"
"time"
)
@@ -21,23 +20,23 @@ func TestChannelStoreSave(t *testing.T) {
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
if err := (<-store.Channel().Save(utils.T, &o1)).Err; err != nil {
if err := (<-store.Channel().Save(&o1)).Err; err != nil {
t.Fatal("couldn't save item", err)
}
if err := (<-store.Channel().Save(utils.T, &o1)).Err; err == nil {
if err := (<-store.Channel().Save(&o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
o1.Id = ""
if err := (<-store.Channel().Save(utils.T, &o1)).Err; err == nil {
if err := (<-store.Channel().Save(&o1)).Err; err == nil {
t.Fatal("should be unique name")
}
o1.Id = ""
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_DIRECT
if err := (<-store.Channel().Save(utils.T, &o1)).Err; err == nil {
if err := (<-store.Channel().Save(&o1)).Err; err == nil {
t.Fatal("Should not be able to save direct channel")
}
@@ -45,14 +44,14 @@ func TestChannelStoreSave(t *testing.T) {
for i := 0; i < 1000; i++ {
o1.Id = ""
o1.Name = "a" + model.NewId() + "b"
if err := (<-store.Channel().Save(utils.T, &o1)).Err; err != nil {
if err := (<-store.Channel().Save(&o1)).Err; err != nil {
t.Fatal("couldn't save item", err)
}
}
o1.Id = ""
o1.Name = "a" + model.NewId() + "b"
if err := (<-store.Channel().Save(utils.T, &o1)).Err; err == nil {
if err := (<-store.Channel().Save(&o1)).Err; err == nil {
t.Fatal("should be the limit")
}
}
@@ -72,13 +71,13 @@ func TestChannelStoreSaveDirectChannel(t *testing.T) {
u1.TeamId = model.NewId()
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
u2 := model.User{}
u2.TeamId = model.NewId()
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(utils.T, &u2))
Must(store.User().Save(&u2))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
@@ -90,23 +89,23 @@ func TestChannelStoreSaveDirectChannel(t *testing.T) {
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
if err := (<-store.Channel().SaveDirectChannel(utils.T, &o1, &m1, &m2)).Err; err != nil {
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err != nil {
t.Fatal("couldn't save direct channel", err)
}
members := (<-store.Channel().GetMembers(utils.T, o1.Id)).Data.([]model.ChannelMember)
members := (<-store.Channel().GetMembers(o1.Id)).Data.([]model.ChannelMember)
if len(members) != 2 {
t.Fatal("should have saved 2 members")
}
if err := (<-store.Channel().SaveDirectChannel(utils.T, &o1, &m1, &m2)).Err; err == nil {
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
o1.Id = ""
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
if err := (<-store.Channel().SaveDirectChannel(utils.T, &o1, &m1, &m2)).Err; err == nil {
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
t.Fatal("Should not be able to save non-direct channel")
}
@@ -121,23 +120,23 @@ func TestChannelStoreUpdate(t *testing.T) {
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
if err := (<-store.Channel().Save(utils.T, &o1)).Err; err != nil {
if err := (<-store.Channel().Save(&o1)).Err; err != nil {
t.Fatal(err)
}
time.Sleep(100 * time.Millisecond)
if err := (<-store.Channel().Update(utils.T, &o1)).Err; err != nil {
if err := (<-store.Channel().Update(&o1)).Err; err != nil {
t.Fatal(err)
}
o1.Id = "missing"
if err := (<-store.Channel().Update(utils.T, &o1)).Err; err == nil {
if err := (<-store.Channel().Update(&o1)).Err; err == nil {
t.Fatal("Update should have failed because of missing key")
}
o1.Id = model.NewId()
if err := (<-store.Channel().Update(utils.T, &o1)).Err; err == nil {
if err := (<-store.Channel().Update(&o1)).Err; err == nil {
t.Fatal("Update should have faile because id change")
}
}
@@ -150,9 +149,9 @@ func TestChannelStoreGet(t *testing.T) {
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
if r1 := <-store.Channel().Get(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Channel().Get(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Channel).ToJson() != o1.ToJson() {
@@ -160,7 +159,7 @@ func TestChannelStoreGet(t *testing.T) {
}
}
if err := (<-store.Channel().Get(utils.T, "")).Err; err == nil {
if err := (<-store.Channel().Get("")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
@@ -168,13 +167,13 @@ func TestChannelStoreGet(t *testing.T) {
u1.TeamId = model.NewId()
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
u2 := model.User{}
u2.TeamId = model.NewId()
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(utils.T, &u2))
Must(store.User().Save(&u2))
o2 := model.Channel{}
o2.TeamId = model.NewId()
@@ -192,9 +191,9 @@ func TestChannelStoreGet(t *testing.T) {
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveDirectChannel(utils.T, &o2, &m1, &m2))
Must(store.Channel().SaveDirectChannel(&o2, &m1, &m2))
if r2 := <-store.Channel().Get(utils.T, o2.Id); r2.Err != nil {
if r2 := <-store.Channel().Get(o2.Id); r2.Err != nil {
t.Fatal(r2.Err)
} else {
if r2.Data.(*model.Channel).ToJson() != o2.ToJson() {
@@ -211,61 +210,61 @@ func TestChannelStoreDelete(t *testing.T) {
o1.DisplayName = "Channel1"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
o2 := model.Channel{}
o2.TeamId = o1.TeamId
o2.DisplayName = "Channel2"
o2.Name = "a" + model.NewId() + "b"
o2.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o2))
Must(store.Channel().Save(&o2))
o3 := model.Channel{}
o3.TeamId = o1.TeamId
o3.DisplayName = "Channel3"
o3.Name = "a" + model.NewId() + "b"
o3.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o3))
Must(store.Channel().Save(&o3))
o4 := model.Channel{}
o4.TeamId = o1.TeamId
o4.DisplayName = "Channel4"
o4.Name = "a" + model.NewId() + "b"
o4.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o4))
Must(store.Channel().Save(&o4))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m1))
Must(store.Channel().SaveMember(&m1))
m2 := model.ChannelMember{}
m2.ChannelId = o2.Id
m2.UserId = m1.UserId
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m2))
Must(store.Channel().SaveMember(&m2))
if r := <-store.Channel().Delete(utils.T, o1.Id, model.GetMillis()); r.Err != nil {
if r := <-store.Channel().Delete(o1.Id, model.GetMillis()); r.Err != nil {
t.Fatal(r.Err)
}
if r := <-store.Channel().Get(utils.T, o1.Id); r.Data.(*model.Channel).DeleteAt == 0 {
if r := <-store.Channel().Get(o1.Id); r.Data.(*model.Channel).DeleteAt == 0 {
t.Fatal("should have been deleted")
}
if r := <-store.Channel().Delete(utils.T, o3.Id, model.GetMillis()); r.Err != nil {
if r := <-store.Channel().Delete(o3.Id, model.GetMillis()); r.Err != nil {
t.Fatal(r.Err)
}
cresult := <-store.Channel().GetChannels(utils.T, o1.TeamId, m1.UserId)
cresult := <-store.Channel().GetChannels(o1.TeamId, m1.UserId)
list := cresult.Data.(*model.ChannelList)
if len(list.Channels) != 1 {
t.Fatal("invalid number of channels")
}
cresult = <-store.Channel().GetMoreChannels(utils.T, o1.TeamId, m1.UserId)
cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId)
list = cresult.Data.(*model.ChannelList)
if len(list.Channels) != 1 {
@@ -281,9 +280,9 @@ func TestChannelStoreGetByName(t *testing.T) {
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
if r1 := <-store.Channel().GetByName(utils.T, o1.TeamId, o1.Name); r1.Err != nil {
if r1 := <-store.Channel().GetByName(o1.TeamId, o1.Name); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Channel).ToJson() != o1.ToJson() {
@@ -291,7 +290,7 @@ func TestChannelStoreGetByName(t *testing.T) {
}
}
if err := (<-store.Channel().GetByName(utils.T, o1.TeamId, "")).Err; err == nil {
if err := (<-store.Channel().GetByName(o1.TeamId, "")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
@@ -304,76 +303,76 @@ func TestChannelMemberStore(t *testing.T) {
c1.DisplayName = "NameName"
c1.Name = "a" + model.NewId() + "b"
c1.Type = model.CHANNEL_OPEN
c1 = *Must(store.Channel().Save(utils.T, &c1)).(*model.Channel)
c1 = *Must(store.Channel().Save(&c1)).(*model.Channel)
c1t1 := (<-store.Channel().Get(utils.T, c1.Id)).Data.(*model.Channel)
c1t1 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel)
t1 := c1t1.ExtraUpdateAt
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
u2 := model.User{}
u2.TeamId = model.NewId()
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(utils.T, &u2))
Must(store.User().Save(&u2))
o1 := model.ChannelMember{}
o1.ChannelId = c1.Id
o1.UserId = u1.Id
o1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &o1))
Must(store.Channel().SaveMember(&o1))
o2 := model.ChannelMember{}
o2.ChannelId = c1.Id
o2.UserId = u2.Id
o2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &o2))
Must(store.Channel().SaveMember(&o2))
c1t2 := (<-store.Channel().Get(utils.T, c1.Id)).Data.(*model.Channel)
c1t2 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel)
t2 := c1t2.ExtraUpdateAt
if t2 <= t1 {
t.Fatal("Member update time incorrect")
}
count := (<-store.Channel().GetMemberCount(utils.T, o1.ChannelId)).Data.(int64)
count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
if count != 2 {
t.Fatal("should have saved 2 members")
}
Must(store.Channel().RemoveMember(utils.T, o2.ChannelId, o2.UserId))
Must(store.Channel().RemoveMember(o2.ChannelId, o2.UserId))
count = (<-store.Channel().GetMemberCount(utils.T, o1.ChannelId)).Data.(int64)
count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
if count != 1 {
t.Fatal("should have removed 1 member")
}
c1t3 := (<-store.Channel().Get(utils.T, c1.Id)).Data.(*model.Channel)
c1t3 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel)
t3 := c1t3.ExtraUpdateAt
if t3 <= t2 || t3 <= t1 {
t.Fatal("Member update time incorrect on delete")
}
member := (<-store.Channel().GetMember(utils.T, o1.ChannelId, o1.UserId)).Data.(model.ChannelMember)
member := (<-store.Channel().GetMember(o1.ChannelId, o1.UserId)).Data.(model.ChannelMember)
if member.ChannelId != o1.ChannelId {
t.Fatal("should have go member")
}
extraMembers := (<-store.Channel().GetExtraMembers(utils.T, o1.ChannelId, 20)).Data.([]model.ExtraMember)
extraMembers := (<-store.Channel().GetExtraMembers(o1.ChannelId, 20)).Data.([]model.ExtraMember)
if len(extraMembers) != 1 {
t.Fatal("should have 1 extra members")
}
if err := (<-store.Channel().SaveMember(utils.T, &o1)).Err; err == nil {
if err := (<-store.Channel().SaveMember(&o1)).Err; err == nil {
t.Fatal("Should have been a duplicate")
}
c1t4 := (<-store.Channel().Get(utils.T, c1.Id)).Data.(*model.Channel)
c1t4 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel)
t4 := c1t4.ExtraUpdateAt
if t4 != t3 {
t.Fatal("Should not update time upon failure")
@@ -388,50 +387,50 @@ func TestChannelDeleteMemberStore(t *testing.T) {
c1.DisplayName = "NameName"
c1.Name = "a" + model.NewId() + "b"
c1.Type = model.CHANNEL_OPEN
c1 = *Must(store.Channel().Save(utils.T, &c1)).(*model.Channel)
c1 = *Must(store.Channel().Save(&c1)).(*model.Channel)
c1t1 := (<-store.Channel().Get(utils.T, c1.Id)).Data.(*model.Channel)
c1t1 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel)
t1 := c1t1.ExtraUpdateAt
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
u2 := model.User{}
u2.TeamId = model.NewId()
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(utils.T, &u2))
Must(store.User().Save(&u2))
o1 := model.ChannelMember{}
o1.ChannelId = c1.Id
o1.UserId = u1.Id
o1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &o1))
Must(store.Channel().SaveMember(&o1))
o2 := model.ChannelMember{}
o2.ChannelId = c1.Id
o2.UserId = u2.Id
o2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &o2))
Must(store.Channel().SaveMember(&o2))
c1t2 := (<-store.Channel().Get(utils.T, c1.Id)).Data.(*model.Channel)
c1t2 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel)
t2 := c1t2.ExtraUpdateAt
if t2 <= t1 {
t.Fatal("Member update time incorrect")
}
count := (<-store.Channel().GetMemberCount(utils.T, o1.ChannelId)).Data.(int64)
count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
if count != 2 {
t.Fatal("should have saved 2 members")
}
Must(store.Channel().PermanentDeleteMembersByUser(utils.T, o2.UserId))
Must(store.Channel().PermanentDeleteMembersByUser(o2.UserId))
count = (<-store.Channel().GetMemberCount(utils.T, o1.ChannelId)).Data.(int64)
count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
if count != 1 {
t.Fatal("should have removed 1 member")
}
@@ -445,40 +444,40 @@ func TestChannelStorePermissionsTo(t *testing.T) {
o1.DisplayName = "Channel1"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m1))
Must(store.Channel().SaveMember(&m1))
count := (<-store.Channel().CheckPermissionsTo(utils.T, o1.TeamId, o1.Id, m1.UserId)).Data.(int64)
count := (<-store.Channel().CheckPermissionsTo(o1.TeamId, o1.Id, m1.UserId)).Data.(int64)
if count != 1 {
t.Fatal("should have permissions")
}
count = (<-store.Channel().CheckPermissionsTo(utils.T, "junk", o1.Id, m1.UserId)).Data.(int64)
count = (<-store.Channel().CheckPermissionsTo("junk", o1.Id, m1.UserId)).Data.(int64)
if count != 0 {
t.Fatal("shouldn't have permissions")
}
count = (<-store.Channel().CheckPermissionsTo(utils.T, o1.TeamId, "junk", m1.UserId)).Data.(int64)
count = (<-store.Channel().CheckPermissionsTo(o1.TeamId, "junk", m1.UserId)).Data.(int64)
if count != 0 {
t.Fatal("shouldn't have permissions")
}
count = (<-store.Channel().CheckPermissionsTo(utils.T, o1.TeamId, o1.Id, "junk")).Data.(int64)
count = (<-store.Channel().CheckPermissionsTo(o1.TeamId, o1.Id, "junk")).Data.(int64)
if count != 0 {
t.Fatal("shouldn't have permissions")
}
channelId := (<-store.Channel().CheckPermissionsToByName(utils.T, o1.TeamId, o1.Name, m1.UserId)).Data.(string)
channelId := (<-store.Channel().CheckPermissionsToByName(o1.TeamId, o1.Name, m1.UserId)).Data.(string)
if channelId != o1.Id {
t.Fatal("should have permissions")
}
channelId = (<-store.Channel().CheckPermissionsToByName(utils.T, o1.TeamId, "missing", m1.UserId)).Data.(string)
channelId = (<-store.Channel().CheckPermissionsToByName(o1.TeamId, "missing", m1.UserId)).Data.(string)
if channelId != "" {
t.Fatal("should not have permissions")
}
@@ -492,19 +491,19 @@ func TestChannelStoreOpenChannelPermissionsTo(t *testing.T) {
o1.DisplayName = "Channel1"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
count := (<-store.Channel().CheckOpenChannelPermissions(utils.T, o1.TeamId, o1.Id)).Data.(int64)
count := (<-store.Channel().CheckOpenChannelPermissions(o1.TeamId, o1.Id)).Data.(int64)
if count != 1 {
t.Fatal("should have permissions")
}
count = (<-store.Channel().CheckOpenChannelPermissions(utils.T, "junk", o1.Id)).Data.(int64)
count = (<-store.Channel().CheckOpenChannelPermissions("junk", o1.Id)).Data.(int64)
if count != 0 {
t.Fatal("shouldn't have permissions")
}
count = (<-store.Channel().CheckOpenChannelPermissions(utils.T, o1.TeamId, "junk")).Data.(int64)
count = (<-store.Channel().CheckOpenChannelPermissions(o1.TeamId, "junk")).Data.(int64)
if count != 0 {
t.Fatal("shouldn't have permissions")
}
@@ -518,34 +517,34 @@ func TestChannelStoreGetChannels(t *testing.T) {
o2.DisplayName = "Channel2"
o2.Name = "a" + model.NewId() + "b"
o2.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o2))
Must(store.Channel().Save(&o2))
o1 := model.Channel{}
o1.TeamId = model.NewId()
o1.DisplayName = "Channel1"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m1))
Must(store.Channel().SaveMember(&m1))
m2 := model.ChannelMember{}
m2.ChannelId = o1.Id
m2.UserId = model.NewId()
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m2))
Must(store.Channel().SaveMember(&m2))
m3 := model.ChannelMember{}
m3.ChannelId = o2.Id
m3.UserId = model.NewId()
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m3))
Must(store.Channel().SaveMember(&m3))
cresult := <-store.Channel().GetChannels(utils.T, o1.TeamId, m1.UserId)
cresult := <-store.Channel().GetChannels(o1.TeamId, m1.UserId)
list := cresult.Data.(*model.ChannelList)
if list.Channels[0].Id != o1.Id {
@@ -561,55 +560,55 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
o1.DisplayName = "Channel1"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
o2 := model.Channel{}
o2.TeamId = model.NewId()
o2.DisplayName = "Channel2"
o2.Name = "a" + model.NewId() + "b"
o2.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o2))
Must(store.Channel().Save(&o2))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m1))
Must(store.Channel().SaveMember(&m1))
m2 := model.ChannelMember{}
m2.ChannelId = o1.Id
m2.UserId = model.NewId()
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m2))
Must(store.Channel().SaveMember(&m2))
m3 := model.ChannelMember{}
m3.ChannelId = o2.Id
m3.UserId = model.NewId()
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m3))
Must(store.Channel().SaveMember(&m3))
o3 := model.Channel{}
o3.TeamId = o1.TeamId
o3.DisplayName = "ChannelA"
o3.Name = "a" + model.NewId() + "b"
o3.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o3))
Must(store.Channel().Save(&o3))
o4 := model.Channel{}
o4.TeamId = o1.TeamId
o4.DisplayName = "ChannelB"
o4.Name = "a" + model.NewId() + "b"
o4.Type = model.CHANNEL_PRIVATE
Must(store.Channel().Save(utils.T, &o4))
Must(store.Channel().Save(&o4))
o5 := model.Channel{}
o5.TeamId = o1.TeamId
o5.DisplayName = "ChannelC"
o5.Name = "a" + model.NewId() + "b"
o5.Type = model.CHANNEL_PRIVATE
Must(store.Channel().Save(utils.T, &o5))
Must(store.Channel().Save(&o5))
cresult := <-store.Channel().GetMoreChannels(utils.T, o1.TeamId, m1.UserId)
cresult := <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId)
list := cresult.Data.(*model.ChannelList)
if len(list.Channels) != 1 {
@@ -620,7 +619,7 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
t.Fatal("missing channel")
}
if r1 := <-store.Channel().AnalyticsTypeCount(utils.T, o1.TeamId, model.CHANNEL_OPEN); r1.Err != nil {
if r1 := <-store.Channel().AnalyticsTypeCount(o1.TeamId, model.CHANNEL_OPEN); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(int64) != 2 {
@@ -629,7 +628,7 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
}
}
if r1 := <-store.Channel().AnalyticsTypeCount(utils.T, o1.TeamId, model.CHANNEL_PRIVATE); r1.Err != nil {
if r1 := <-store.Channel().AnalyticsTypeCount(o1.TeamId, model.CHANNEL_PRIVATE); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(int64) != 2 {
@@ -647,34 +646,34 @@ func TestChannelStoreGetChannelCounts(t *testing.T) {
o2.DisplayName = "Channel2"
o2.Name = "a" + model.NewId() + "b"
o2.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o2))
Must(store.Channel().Save(&o2))
o1 := model.Channel{}
o1.TeamId = model.NewId()
o1.DisplayName = "Channel1"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m1))
Must(store.Channel().SaveMember(&m1))
m2 := model.ChannelMember{}
m2.ChannelId = o1.Id
m2.UserId = model.NewId()
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m2))
Must(store.Channel().SaveMember(&m2))
m3 := model.ChannelMember{}
m3.ChannelId = o2.Id
m3.UserId = model.NewId()
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m3))
Must(store.Channel().SaveMember(&m3))
cresult := <-store.Channel().GetChannelCounts(utils.T, o1.TeamId, m1.UserId)
cresult := <-store.Channel().GetChannelCounts(o1.TeamId, m1.UserId)
counts := cresult.Data.(*model.ChannelCounts)
if len(counts.Counts) != 1 {
@@ -695,20 +694,20 @@ func TestChannelStoreUpdateLastViewedAt(t *testing.T) {
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
o1.TotalMsgCount = 25
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m1))
Must(store.Channel().SaveMember(&m1))
err := (<-store.Channel().UpdateLastViewedAt(utils.T, m1.ChannelId, m1.UserId)).Err
err := (<-store.Channel().UpdateLastViewedAt(m1.ChannelId, m1.UserId)).Err
if err != nil {
t.Fatal("failed to update", err)
}
err = (<-store.Channel().UpdateLastViewedAt(utils.T, m1.ChannelId, "missing id")).Err
err = (<-store.Channel().UpdateLastViewedAt(m1.ChannelId, "missing id")).Err
if err != nil {
t.Fatal("failed to update")
}
@@ -723,30 +722,30 @@ func TestChannelStoreIncrementMentionCount(t *testing.T) {
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
o1.TotalMsgCount = 25
Must(store.Channel().Save(utils.T, &o1))
Must(store.Channel().Save(&o1))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m1))
Must(store.Channel().SaveMember(&m1))
err := (<-store.Channel().IncrementMentionCount(utils.T, m1.ChannelId, m1.UserId)).Err
err := (<-store.Channel().IncrementMentionCount(m1.ChannelId, m1.UserId)).Err
if err != nil {
t.Fatal("failed to update")
}
err = (<-store.Channel().IncrementMentionCount(utils.T, m1.ChannelId, "missing id")).Err
err = (<-store.Channel().IncrementMentionCount(m1.ChannelId, "missing id")).Err
if err != nil {
t.Fatal("failed to update")
}
err = (<-store.Channel().IncrementMentionCount(utils.T, "missing id", m1.UserId)).Err
err = (<-store.Channel().IncrementMentionCount("missing id", m1.UserId)).Err
if err != nil {
t.Fatal("failed to update")
}
err = (<-store.Channel().IncrementMentionCount(utils.T, "missing id", "missing id")).Err
err = (<-store.Channel().IncrementMentionCount("missing id", "missing id")).Err
if err != nil {
t.Fatal("failed to update")
}

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
"strings"
)
@@ -53,7 +52,7 @@ func (as SqlOAuthStore) CreateIndexesIfNotExists() {
as.CreateIndexIfNotExists("idx_oauthauthdata_client_id", "OAuthAuthData", "Code")
}
func (as SqlOAuthStore) SaveApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel {
func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) StoreChannel {
storeChannel := make(StoreChannel)
@@ -87,7 +86,7 @@ func (as SqlOAuthStore) SaveApp(T goi18n.TranslateFunc, app *model.OAuthApp) Sto
return storeChannel
}
func (as SqlOAuthStore) UpdateApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel {
func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) StoreChannel {
storeChannel := make(StoreChannel)
@@ -128,7 +127,7 @@ func (as SqlOAuthStore) UpdateApp(T goi18n.TranslateFunc, app *model.OAuthApp) S
return storeChannel
}
func (as SqlOAuthStore) GetApp(T goi18n.TranslateFunc, id string) StoreChannel {
func (as SqlOAuthStore) GetApp(id string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -151,7 +150,7 @@ func (as SqlOAuthStore) GetApp(T goi18n.TranslateFunc, id string) StoreChannel {
return storeChannel
}
func (as SqlOAuthStore) GetAppByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (as SqlOAuthStore) GetAppByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -173,7 +172,7 @@ func (as SqlOAuthStore) GetAppByUser(T goi18n.TranslateFunc, userId string) Stor
return storeChannel
}
func (as SqlOAuthStore) SaveAccessData(T goi18n.TranslateFunc, accessData *model.AccessData) StoreChannel {
func (as SqlOAuthStore) SaveAccessData(accessData *model.AccessData) StoreChannel {
storeChannel := make(StoreChannel)
@@ -199,7 +198,7 @@ func (as SqlOAuthStore) SaveAccessData(T goi18n.TranslateFunc, accessData *model
return storeChannel
}
func (as SqlOAuthStore) GetAccessData(T goi18n.TranslateFunc, token string) StoreChannel {
func (as SqlOAuthStore) GetAccessData(token string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -222,7 +221,7 @@ func (as SqlOAuthStore) GetAccessData(T goi18n.TranslateFunc, token string) Stor
return storeChannel
}
func (as SqlOAuthStore) GetAccessDataByAuthCode(T goi18n.TranslateFunc, authCode string) StoreChannel {
func (as SqlOAuthStore) GetAccessDataByAuthCode(authCode string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -249,7 +248,7 @@ func (as SqlOAuthStore) GetAccessDataByAuthCode(T goi18n.TranslateFunc, authCode
return storeChannel
}
func (as SqlOAuthStore) RemoveAccessData(T goi18n.TranslateFunc, token string) StoreChannel {
func (as SqlOAuthStore) RemoveAccessData(token string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -266,7 +265,7 @@ func (as SqlOAuthStore) RemoveAccessData(T goi18n.TranslateFunc, token string) S
return storeChannel
}
func (as SqlOAuthStore) SaveAuthData(T goi18n.TranslateFunc, authData *model.AuthData) StoreChannel {
func (as SqlOAuthStore) SaveAuthData(authData *model.AuthData) StoreChannel {
storeChannel := make(StoreChannel)
@@ -293,7 +292,7 @@ func (as SqlOAuthStore) SaveAuthData(T goi18n.TranslateFunc, authData *model.Aut
return storeChannel
}
func (as SqlOAuthStore) GetAuthData(T goi18n.TranslateFunc, code string) StoreChannel {
func (as SqlOAuthStore) GetAuthData(code string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -316,7 +315,7 @@ func (as SqlOAuthStore) GetAuthData(T goi18n.TranslateFunc, code string) StoreCh
return storeChannel
}
func (as SqlOAuthStore) RemoveAuthData(T goi18n.TranslateFunc, code string) StoreChannel {
func (as SqlOAuthStore) RemoveAuthData(code string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -334,7 +333,7 @@ func (as SqlOAuthStore) RemoveAuthData(T goi18n.TranslateFunc, code string) Stor
return storeChannel
}
func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing"
)
@@ -18,7 +17,7 @@ func TestOAuthStoreSaveApp(t *testing.T) {
a1.CallbackUrls = []string{"https://nowhere.com"}
a1.Homepage = "https://nowhere.com"
if err := (<-store.OAuth().SaveApp(utils.T, &a1)).Err; err != nil {
if err := (<-store.OAuth().SaveApp(&a1)).Err; err != nil {
t.Fatal(err)
}
}
@@ -31,13 +30,13 @@ func TestOAuthStoreGetApp(t *testing.T) {
a1.Name = "TestApp" + model.NewId()
a1.CallbackUrls = []string{"https://nowhere.com"}
a1.Homepage = "https://nowhere.com"
Must(store.OAuth().SaveApp(utils.T, &a1))
Must(store.OAuth().SaveApp(&a1))
if err := (<-store.OAuth().GetApp(utils.T, a1.Id)).Err; err != nil {
if err := (<-store.OAuth().GetApp(a1.Id)).Err; err != nil {
t.Fatal(err)
}
if err := (<-store.OAuth().GetAppByUser(utils.T, a1.CreatorId)).Err; err != nil {
if err := (<-store.OAuth().GetAppByUser(a1.CreatorId)).Err; err != nil {
t.Fatal(err)
}
}
@@ -50,13 +49,13 @@ func TestOAuthStoreUpdateApp(t *testing.T) {
a1.Name = "TestApp" + model.NewId()
a1.CallbackUrls = []string{"https://nowhere.com"}
a1.Homepage = "https://nowhere.com"
Must(store.OAuth().SaveApp(utils.T, &a1))
Must(store.OAuth().SaveApp(&a1))
a1.CreateAt = 1
a1.ClientSecret = "pwd"
a1.CreatorId = "12345678901234567890123456"
a1.Name = "NewName"
if result := <-store.OAuth().UpdateApp(utils.T, &a1); result.Err != nil {
if result := <-store.OAuth().UpdateApp(&a1); result.Err != nil {
t.Fatal(result.Err)
} else {
ua1 := (result.Data.([2]*model.OAuthApp)[0])
@@ -83,7 +82,7 @@ func TestOAuthStoreSaveAccessData(t *testing.T) {
a1.Token = model.NewId()
a1.RefreshToken = model.NewId()
if err := (<-store.OAuth().SaveAccessData(utils.T, &a1)).Err; err != nil {
if err := (<-store.OAuth().SaveAccessData(&a1)).Err; err != nil {
t.Fatal(err)
}
}
@@ -95,9 +94,9 @@ func TestOAuthStoreGetAccessData(t *testing.T) {
a1.AuthCode = model.NewId()
a1.Token = model.NewId()
a1.RefreshToken = model.NewId()
Must(store.OAuth().SaveAccessData(utils.T, &a1))
Must(store.OAuth().SaveAccessData(&a1))
if result := <-store.OAuth().GetAccessData(utils.T, a1.Token); result.Err != nil {
if result := <-store.OAuth().GetAccessData(a1.Token); result.Err != nil {
t.Fatal(result.Err)
} else {
ra1 := result.Data.(*model.AccessData)
@@ -106,11 +105,11 @@ func TestOAuthStoreGetAccessData(t *testing.T) {
}
}
if err := (<-store.OAuth().GetAccessDataByAuthCode(utils.T, a1.AuthCode)).Err; err != nil {
if err := (<-store.OAuth().GetAccessDataByAuthCode(a1.AuthCode)).Err; err != nil {
t.Fatal(err)
}
if err := (<-store.OAuth().GetAccessDataByAuthCode(utils.T, "junk")).Err; err != nil {
if err := (<-store.OAuth().GetAccessDataByAuthCode("junk")).Err; err != nil {
t.Fatal(err)
}
}
@@ -122,13 +121,13 @@ func TestOAuthStoreRemoveAccessData(t *testing.T) {
a1.AuthCode = model.NewId()
a1.Token = model.NewId()
a1.RefreshToken = model.NewId()
Must(store.OAuth().SaveAccessData(utils.T, &a1))
Must(store.OAuth().SaveAccessData(&a1))
if err := (<-store.OAuth().RemoveAccessData(utils.T, a1.Token)).Err; err != nil {
if err := (<-store.OAuth().RemoveAccessData(a1.Token)).Err; err != nil {
t.Fatal(err)
}
if result := <-store.OAuth().GetAccessDataByAuthCode(utils.T, a1.AuthCode); result.Err != nil {
if result := <-store.OAuth().GetAccessDataByAuthCode(a1.AuthCode); result.Err != nil {
t.Fatal(result.Err)
} else {
if result.Data != nil {
@@ -145,7 +144,7 @@ func TestOAuthStoreSaveAuthData(t *testing.T) {
a1.UserId = model.NewId()
a1.Code = model.NewId()
if err := (<-store.OAuth().SaveAuthData(utils.T, &a1)).Err; err != nil {
if err := (<-store.OAuth().SaveAuthData(&a1)).Err; err != nil {
t.Fatal(err)
}
}
@@ -157,9 +156,9 @@ func TestOAuthStoreGetAuthData(t *testing.T) {
a1.ClientId = model.NewId()
a1.UserId = model.NewId()
a1.Code = model.NewId()
Must(store.OAuth().SaveAuthData(utils.T, &a1))
Must(store.OAuth().SaveAuthData(&a1))
if err := (<-store.OAuth().GetAuthData(utils.T, a1.Code)).Err; err != nil {
if err := (<-store.OAuth().GetAuthData(a1.Code)).Err; err != nil {
t.Fatal(err)
}
}
@@ -171,13 +170,13 @@ func TestOAuthStoreRemoveAuthData(t *testing.T) {
a1.ClientId = model.NewId()
a1.UserId = model.NewId()
a1.Code = model.NewId()
Must(store.OAuth().SaveAuthData(utils.T, &a1))
Must(store.OAuth().SaveAuthData(&a1))
if err := (<-store.OAuth().RemoveAuthData(utils.T, a1.Code)).Err; err != nil {
if err := (<-store.OAuth().RemoveAuthData(a1.Code)).Err; err != nil {
t.Fatal(err)
}
if err := (<-store.OAuth().GetAuthData(utils.T, a1.Code)).Err; err == nil {
if err := (<-store.OAuth().GetAuthData(a1.Code)).Err; err == nil {
t.Fatal("should have errored - auth code removed")
}
}
@@ -189,9 +188,9 @@ func TestOAuthStoreRemoveAuthDataByUser(t *testing.T) {
a1.ClientId = model.NewId()
a1.UserId = model.NewId()
a1.Code = model.NewId()
Must(store.OAuth().SaveAuthData(utils.T, &a1))
Must(store.OAuth().SaveAuthData(&a1))
if err := (<-store.OAuth().PermanentDeleteAuthDataByUser(utils.T, a1.UserId)).Err; err != nil {
if err := (<-store.OAuth().PermanentDeleteAuthDataByUser(a1.UserId)).Err; err != nil {
t.Fatal(err)
}
}

View File

@@ -11,7 +11,6 @@ import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlPostStore struct {
@@ -51,7 +50,7 @@ func (s SqlPostStore) CreateIndexesIfNotExists() {
s.CreateFullTextIndexIfNotExists("idx_posts_hashtags_txt", "Posts", "Hashtags")
}
func (s SqlPostStore) Save(T goi18n.TranslateFunc, post *model.Post) StoreChannel {
func (s SqlPostStore) Save(post *model.Post) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -98,7 +97,7 @@ func (s SqlPostStore) Save(T goi18n.TranslateFunc, post *model.Post) StoreChanne
return storeChannel
}
func (s SqlPostStore) Update(T goi18n.TranslateFunc, oldPost *model.Post, newMessage string, newHashtags string) StoreChannel {
func (s SqlPostStore) Update(oldPost *model.Post, newMessage string, newHashtags string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -143,7 +142,7 @@ func (s SqlPostStore) Update(T goi18n.TranslateFunc, oldPost *model.Post, newMes
return storeChannel
}
func (s SqlPostStore) Get(T goi18n.TranslateFunc, id string) StoreChannel {
func (s SqlPostStore) Get(id string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -189,7 +188,7 @@ type etagPosts struct {
UpdateAt int64
}
func (s SqlPostStore) GetEtag(T goi18n.TranslateFunc, channelId string) StoreChannel {
func (s SqlPostStore) GetEtag(channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -210,7 +209,7 @@ func (s SqlPostStore) GetEtag(T goi18n.TranslateFunc, channelId string) StoreCha
return storeChannel
}
func (s SqlPostStore) Delete(T goi18n.TranslateFunc, postId string, time int64) StoreChannel {
func (s SqlPostStore) Delete(postId string, time int64) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -228,7 +227,7 @@ func (s SqlPostStore) Delete(T goi18n.TranslateFunc, postId string, time int64)
return storeChannel
}
func (s SqlPostStore) permanentDelete(T goi18n.TranslateFunc, postId string) StoreChannel {
func (s SqlPostStore) permanentDelete(postId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -246,7 +245,7 @@ func (s SqlPostStore) permanentDelete(T goi18n.TranslateFunc, postId string) Sto
return storeChannel
}
func (s SqlPostStore) permanentDeleteAllCommentByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlPostStore) permanentDeleteAllCommentByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -264,14 +263,14 @@ func (s SqlPostStore) permanentDeleteAllCommentByUser(T goi18n.TranslateFunc, us
return storeChannel
}
func (s SqlPostStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
// First attempt to delete all the comments for a user
if r := <-s.permanentDeleteAllCommentByUser(T, userId); r.Err != nil {
if r := <-s.permanentDeleteAllCommentByUser(userId); r.Err != nil {
result.Err = r.Err
storeChannel <- result
close(storeChannel)
@@ -295,7 +294,7 @@ func (s SqlPostStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId strin
found = false
for _, id := range ids {
found = true
if r := <-s.permanentDelete(T, id); r.Err != nil {
if r := <-s.permanentDelete(id); r.Err != nil {
result.Err = r.Err
storeChannel <- result
close(storeChannel)
@@ -321,7 +320,7 @@ func (s SqlPostStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId strin
return storeChannel
}
func (s SqlPostStore) GetPosts(T goi18n.TranslateFunc, channelId string, offset int, limit int) StoreChannel {
func (s SqlPostStore) GetPosts(channelId string, offset int, limit int) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -334,8 +333,8 @@ func (s SqlPostStore) GetPosts(T goi18n.TranslateFunc, channelId string, offset
return
}
rpc := s.getRootPosts(T, channelId, offset, limit)
cpc := s.getParentsPosts(T, channelId, offset, limit)
rpc := s.getRootPosts(channelId, offset, limit)
cpc := s.getParentsPosts(channelId, offset, limit)
if rpr := <-rpc; rpr.Err != nil {
result.Err = rpr.Err
@@ -368,7 +367,7 @@ func (s SqlPostStore) GetPosts(T goi18n.TranslateFunc, channelId string, offset
return storeChannel
}
func (s SqlPostStore) GetPostsSince(T goi18n.TranslateFunc, channelId string, time int64) StoreChannel {
func (s SqlPostStore) GetPostsSince(channelId string, time int64) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -426,15 +425,15 @@ func (s SqlPostStore) GetPostsSince(T goi18n.TranslateFunc, channelId string, ti
return storeChannel
}
func (s SqlPostStore) GetPostsBefore(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel {
return s.getPostsAround(T, channelId, postId, numPosts, offset, true)
func (s SqlPostStore) GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel {
return s.getPostsAround(channelId, postId, numPosts, offset, true)
}
func (s SqlPostStore) GetPostsAfter(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel {
return s.getPostsAround(T, channelId, postId, numPosts, offset, false)
func (s SqlPostStore) GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel {
return s.getPostsAround(channelId, postId, numPosts, offset, false)
}
func (s SqlPostStore) getPostsAround(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int, before bool) StoreChannel {
func (s SqlPostStore) getPostsAround(channelId string, postId string, numPosts int, offset int, before bool) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -524,7 +523,7 @@ func (s SqlPostStore) getPostsAround(T goi18n.TranslateFunc, channelId string, p
return storeChannel
}
func (s SqlPostStore) getRootPosts(T goi18n.TranslateFunc, channelId string, offset int, limit int) StoreChannel {
func (s SqlPostStore) getRootPosts(channelId string, offset int, limit int) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -545,7 +544,7 @@ func (s SqlPostStore) getRootPosts(T goi18n.TranslateFunc, channelId string, off
return storeChannel
}
func (s SqlPostStore) getParentsPosts(T goi18n.TranslateFunc, channelId string, offset int, limit int) StoreChannel {
func (s SqlPostStore) getParentsPosts(channelId string, offset int, limit int) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -601,7 +600,7 @@ var specialSearchChar = []string{
"@",
}
func (s SqlPostStore) Search(T goi18n.TranslateFunc, teamId string, userId string, params *model.SearchParams) StoreChannel {
func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchParams) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -766,7 +765,7 @@ func (s SqlPostStore) Search(T goi18n.TranslateFunc, teamId string, userId strin
return storeChannel
}
func (s SqlPostStore) GetForExport(T goi18n.TranslateFunc, channelId string) StoreChannel {
func (s SqlPostStore) GetForExport(channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -790,7 +789,7 @@ func (s SqlPostStore) GetForExport(T goi18n.TranslateFunc, channelId string) Sto
return storeChannel
}
func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -854,7 +853,7 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(T goi18n.TranslateFunc,
return storeChannel
}
func (s SqlPostStore) AnalyticsPostCountsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -919,7 +918,7 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(T goi18n.TranslateFunc, teamId st
return storeChannel
}
func (s SqlPostStore) AnalyticsPostCount(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (s SqlPostStore) AnalyticsPostCount(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

View File

@@ -20,11 +20,11 @@ func TestPostStoreSave(t *testing.T) {
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
if err := (<-store.Post().Save(utils.T, &o1)).Err; err != nil {
if err := (<-store.Post().Save(&o1)).Err; err != nil {
t.Fatal("couldn't save item", err)
}
if err := (<-store.Post().Save(utils.T, &o1)).Err; err == nil {
if err := (<-store.Post().Save(&o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
}
@@ -37,19 +37,19 @@ func TestPostStoreGet(t *testing.T) {
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
etag1 := (<-store.Post().GetEtag(utils.T, o1.ChannelId)).Data.(string)
etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string)
if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
t.Fatal("Invalid Etag")
}
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
etag2 := (<-store.Post().GetEtag(utils.T, o1.ChannelId)).Data.(string)
etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string)
if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 {
t.Fatal("Invalid Etag")
}
if r1 := <-store.Post().Get(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Post().Get(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.PostList).Posts[o1.Id].CreateAt != o1.CreateAt {
@@ -57,7 +57,7 @@ func TestPostStoreGet(t *testing.T) {
}
}
if err := (<-store.Post().Get(utils.T, "123")).Err; err == nil {
if err := (<-store.Post().Get("123")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
@@ -69,7 +69,7 @@ func TestPostStoreUpdate(t *testing.T) {
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "AAAAAAAAAAA"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
@@ -77,50 +77,50 @@ func TestPostStoreUpdate(t *testing.T) {
o2.Message = "a" + model.NewId() + "CCCCCCCCC"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
o3 := &model.Post{}
o3.ChannelId = o1.ChannelId
o3.UserId = model.NewId()
o3.Message = "a" + model.NewId() + "QQQQQQQQQQ"
o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
ro1 := (<-store.Post().Get(utils.T, o1.Id)).Data.(*model.PostList).Posts[o1.Id]
ro2 := (<-store.Post().Get(utils.T, o1.Id)).Data.(*model.PostList).Posts[o2.Id]
ro6 := (<-store.Post().Get(utils.T, o3.Id)).Data.(*model.PostList).Posts[o3.Id]
ro1 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o1.Id]
ro2 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o2.Id]
ro6 := (<-store.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id]
if ro1.Message != o1.Message {
t.Fatal("Failed to save/get")
}
msg := o1.Message + "BBBBBBBBBB"
if result := <-store.Post().Update(utils.T, ro1, msg, ""); result.Err != nil {
if result := <-store.Post().Update(ro1, msg, ""); result.Err != nil {
t.Fatal(result.Err)
}
msg2 := o2.Message + "DDDDDDD"
if result := <-store.Post().Update(utils.T, ro2, msg2, ""); result.Err != nil {
if result := <-store.Post().Update(ro2, msg2, ""); result.Err != nil {
t.Fatal(result.Err)
}
msg3 := o3.Message + "WWWWWWW"
if result := <-store.Post().Update(utils.T, ro6, msg3, "#hashtag"); result.Err != nil {
if result := <-store.Post().Update(ro6, msg3, "#hashtag"); result.Err != nil {
t.Fatal(result.Err)
}
ro3 := (<-store.Post().Get(utils.T, o1.Id)).Data.(*model.PostList).Posts[o1.Id]
ro3 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o1.Id]
if ro3.Message != msg {
t.Fatal("Failed to update/get")
}
ro4 := (<-store.Post().Get(utils.T, o1.Id)).Data.(*model.PostList).Posts[o2.Id]
ro4 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o2.Id]
if ro4.Message != msg2 {
t.Fatal("Failed to update/get")
}
ro5 := (<-store.Post().Get(utils.T, o3.Id)).Data.(*model.PostList).Posts[o3.Id]
ro5 := (<-store.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id]
if ro5.Message != msg3 && ro5.Hashtags != "#hashtag" {
t.Fatal("Failed to update/get")
@@ -136,14 +136,14 @@ func TestPostStoreDelete(t *testing.T) {
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
etag1 := (<-store.Post().GetEtag(utils.T, o1.ChannelId)).Data.(string)
etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string)
if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
t.Fatal("Invalid Etag")
}
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
if r1 := <-store.Post().Get(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Post().Get(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.PostList).Posts[o1.Id].CreateAt != o1.CreateAt {
@@ -151,16 +151,16 @@ func TestPostStoreDelete(t *testing.T) {
}
}
if r2 := <-store.Post().Delete(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
if r2 := <-store.Post().Delete(o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err == nil {
if r3 := (<-store.Post().Get(o1.Id)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
}
etag2 := (<-store.Post().GetEtag(utils.T, o1.ChannelId)).Data.(string)
etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string)
if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 {
t.Fatal("Invalid Etag")
}
@@ -173,7 +173,7 @@ func TestPostStoreDelete1Level(t *testing.T) {
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
@@ -181,17 +181,17 @@ func TestPostStoreDelete1Level(t *testing.T) {
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
if r2 := <-store.Post().Delete(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
if r2 := <-store.Post().Delete(o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err == nil {
if r3 := (<-store.Post().Get(o1.Id)); r3.Err == nil {
t.Fatal("Deleted id should have failed")
}
if r4 := (<-store.Post().Get(utils.T, o2.Id)); r4.Err == nil {
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed")
}
}
@@ -203,7 +203,7 @@ func TestPostStoreDelete2Level(t *testing.T) {
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
@@ -211,7 +211,7 @@ func TestPostStoreDelete2Level(t *testing.T) {
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
o3 := &model.Post{}
o3.ChannelId = o1.ChannelId
@@ -219,31 +219,31 @@ func TestPostStoreDelete2Level(t *testing.T) {
o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o2.Id
o3.RootId = o1.Id
o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
o4 := &model.Post{}
o4.ChannelId = model.NewId()
o4.UserId = model.NewId()
o4.Message = "a" + model.NewId() + "b"
o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
o4 = (<-store.Post().Save(o4)).Data.(*model.Post)
if r2 := <-store.Post().Delete(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
if r2 := <-store.Post().Delete(o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err == nil {
if r3 := (<-store.Post().Get(o1.Id)); r3.Err == nil {
t.Fatal("Deleted id should have failed")
}
if r4 := (<-store.Post().Get(utils.T, o2.Id)); r4.Err == nil {
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed")
}
if r5 := (<-store.Post().Get(utils.T, o3.Id)); r5.Err == nil {
if r5 := (<-store.Post().Get(o3.Id)); r5.Err == nil {
t.Fatal("Deleted id should have failed")
}
if r6 := <-store.Post().Get(utils.T, o4.Id); r6.Err != nil {
if r6 := <-store.Post().Get(o4.Id); r6.Err != nil {
t.Fatal(r6.Err)
}
}
@@ -255,7 +255,7 @@ func TestPostStorePermDelete1Level(t *testing.T) {
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
@@ -263,17 +263,17 @@ func TestPostStorePermDelete1Level(t *testing.T) {
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
if r2 := <-store.Post().PermanentDeleteByUser(utils.T, o2.UserId); r2.Err != nil {
if r2 := <-store.Post().PermanentDeleteByUser(o2.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err != nil {
if r3 := (<-store.Post().Get(o1.Id)); r3.Err != nil {
t.Fatal("Deleted id shouldn't have failed")
}
if r4 := (<-store.Post().Get(utils.T, o2.Id)); r4.Err == nil {
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed")
}
}
@@ -285,7 +285,7 @@ func TestPostStorePermDelete1Level2(t *testing.T) {
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
@@ -293,27 +293,27 @@ func TestPostStorePermDelete1Level2(t *testing.T) {
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
o3 := &model.Post{}
o3.ChannelId = model.NewId()
o3.UserId = model.NewId()
o3.Message = "a" + model.NewId() + "b"
o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
if r2 := <-store.Post().PermanentDeleteByUser(utils.T, o1.UserId); r2.Err != nil {
if r2 := <-store.Post().PermanentDeleteByUser(o1.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err == nil {
if r3 := (<-store.Post().Get(o1.Id)); r3.Err == nil {
t.Fatal("Deleted id should have failed")
}
if r4 := (<-store.Post().Get(utils.T, o2.Id)); r4.Err == nil {
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed")
}
if r5 := (<-store.Post().Get(utils.T, o3.Id)); r5.Err != nil {
if r5 := (<-store.Post().Get(o3.Id)); r5.Err != nil {
t.Fatal("Deleted id shouldn't have failed")
}
}
@@ -325,7 +325,7 @@ func TestPostStoreGetWithChildren(t *testing.T) {
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
@@ -333,7 +333,7 @@ func TestPostStoreGetWithChildren(t *testing.T) {
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
o3 := &model.Post{}
o3.ChannelId = o1.ChannelId
@@ -341,9 +341,9 @@ func TestPostStoreGetWithChildren(t *testing.T) {
o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o2.Id
o3.RootId = o1.Id
o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
if r1 := <-store.Post().Get(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Post().Get(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
pl := r1.Data.(*model.PostList)
@@ -352,9 +352,9 @@ func TestPostStoreGetWithChildren(t *testing.T) {
}
}
Must(store.Post().Delete(utils.T, o3.Id, model.GetMillis()))
Must(store.Post().Delete(o3.Id, model.GetMillis()))
if r2 := <-store.Post().Get(utils.T, o1.Id); r2.Err != nil {
if r2 := <-store.Post().Get(o1.Id); r2.Err != nil {
t.Fatal(r2.Err)
} else {
pl := r2.Data.(*model.PostList)
@@ -363,9 +363,9 @@ func TestPostStoreGetWithChildren(t *testing.T) {
}
}
Must(store.Post().Delete(utils.T, o2.Id, model.GetMillis()))
Must(store.Post().Delete(o2.Id, model.GetMillis()))
if r3 := <-store.Post().Get(utils.T, o1.Id); r3.Err != nil {
if r3 := <-store.Post().Get(o1.Id); r3.Err != nil {
t.Fatal(r3.Err)
} else {
pl := r3.Data.(*model.PostList)
@@ -382,7 +382,7 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o2 := &model.Post{}
@@ -391,7 +391,7 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o2a := &model.Post{}
@@ -400,7 +400,7 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o2a.Message = "a" + model.NewId() + "b"
o2a.ParentId = o1.Id
o2a.RootId = o1.Id
o2a = (<-store.Post().Save(utils.T, o2a)).Data.(*model.Post)
o2a = (<-store.Post().Save(o2a)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o3 := &model.Post{}
@@ -409,14 +409,14 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o1.Id
o3.RootId = o1.Id
o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o4 := &model.Post{}
o4.ChannelId = o1.ChannelId
o4.UserId = model.NewId()
o4.Message = "a" + model.NewId() + "b"
o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
o4 = (<-store.Post().Save(o4)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o5 := &model.Post{}
@@ -425,9 +425,9 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o5.Message = "a" + model.NewId() + "b"
o5.ParentId = o4.Id
o5.RootId = o4.Id
o5 = (<-store.Post().Save(utils.T, o5)).Data.(*model.Post)
o5 = (<-store.Post().Save(o5)).Data.(*model.Post)
r1 := (<-store.Post().GetPosts(utils.T, o1.ChannelId, 0, 4)).Data.(*model.PostList)
r1 := (<-store.Post().GetPosts(o1.ChannelId, 0, 4)).Data.(*model.PostList)
if r1.Order[0] != o5.Id {
t.Fatal("invalid order")
@@ -460,14 +460,14 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o0.ChannelId = model.NewId()
o0.UserId = model.NewId()
o0.Message = "a" + model.NewId() + "b"
o0 = (<-store.Post().Save(utils.T, o0)).Data.(*model.Post)
o0 = (<-store.Post().Save(o0)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o1 := &model.Post{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o2 := &model.Post{}
@@ -476,7 +476,7 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o2a := &model.Post{}
@@ -485,7 +485,7 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o2a.Message = "a" + model.NewId() + "b"
o2a.ParentId = o1.Id
o2a.RootId = o1.Id
o2a = (<-store.Post().Save(utils.T, o2a)).Data.(*model.Post)
o2a = (<-store.Post().Save(o2a)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o3 := &model.Post{}
@@ -494,14 +494,14 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o1.Id
o3.RootId = o1.Id
o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o4 := &model.Post{}
o4.ChannelId = o1.ChannelId
o4.UserId = model.NewId()
o4.Message = "a" + model.NewId() + "b"
o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
o4 = (<-store.Post().Save(o4)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o5 := &model.Post{}
@@ -510,15 +510,15 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o5.Message = "a" + model.NewId() + "b"
o5.ParentId = o4.Id
o5.RootId = o4.Id
o5 = (<-store.Post().Save(utils.T, o5)).Data.(*model.Post)
o5 = (<-store.Post().Save(o5)).Data.(*model.Post)
r1 := (<-store.Post().GetPostsBefore(utils.T, o1.ChannelId, o1.Id, 4, 0)).Data.(*model.PostList)
r1 := (<-store.Post().GetPostsBefore(o1.ChannelId, o1.Id, 4, 0)).Data.(*model.PostList)
if len(r1.Posts) != 0 {
t.Fatal("Wrong size")
}
r2 := (<-store.Post().GetPostsAfter(utils.T, o1.ChannelId, o1.Id, 4, 0)).Data.(*model.PostList)
r2 := (<-store.Post().GetPostsAfter(o1.ChannelId, o1.Id, 4, 0)).Data.(*model.PostList)
if r2.Order[0] != o4.Id {
t.Fatal("invalid order")
@@ -540,7 +540,7 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
t.Fatal("wrong size")
}
r3 := (<-store.Post().GetPostsBefore(utils.T, o3.ChannelId, o3.Id, 2, 0)).Data.(*model.PostList)
r3 := (<-store.Post().GetPostsBefore(o3.ChannelId, o3.Id, 2, 0)).Data.(*model.PostList)
if r3.Order[0] != o2a.Id {
t.Fatal("invalid order")
@@ -565,14 +565,14 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o0.ChannelId = model.NewId()
o0.UserId = model.NewId()
o0.Message = "a" + model.NewId() + "b"
o0 = (<-store.Post().Save(utils.T, o0)).Data.(*model.Post)
o0 = (<-store.Post().Save(o0)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o1 := &model.Post{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o2 := &model.Post{}
@@ -581,7 +581,7 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o2a := &model.Post{}
@@ -590,7 +590,7 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o2a.Message = "a" + model.NewId() + "b"
o2a.ParentId = o1.Id
o2a.RootId = o1.Id
o2a = (<-store.Post().Save(utils.T, o2a)).Data.(*model.Post)
o2a = (<-store.Post().Save(o2a)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o3 := &model.Post{}
@@ -599,14 +599,14 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o1.Id
o3.RootId = o1.Id
o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o4 := &model.Post{}
o4.ChannelId = o1.ChannelId
o4.UserId = model.NewId()
o4.Message = "a" + model.NewId() + "b"
o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
o4 = (<-store.Post().Save(o4)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o5 := &model.Post{}
@@ -615,9 +615,9 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o5.Message = "a" + model.NewId() + "b"
o5.ParentId = o4.Id
o5.RootId = o4.Id
o5 = (<-store.Post().Save(utils.T, o5)).Data.(*model.Post)
o5 = (<-store.Post().Save(o5)).Data.(*model.Post)
r1 := (<-store.Post().GetPostsSince(utils.T, o1.ChannelId, o1.CreateAt)).Data.(*model.PostList)
r1 := (<-store.Post().GetPostsSince(o1.ChannelId, o1.CreateAt)).Data.(*model.PostList)
if r1.Order[0] != o5.Id {
t.Fatal("invalid order")
@@ -655,103 +655,103 @@ func TestPostStoreSearch(t *testing.T) {
c1.DisplayName = "Channel1"
c1.Name = "a" + model.NewId() + "b"
c1.Type = model.CHANNEL_OPEN
c1 = (<-store.Channel().Save(utils.T, c1)).Data.(*model.Channel)
c1 = (<-store.Channel().Save(c1)).Data.(*model.Channel)
m1 := model.ChannelMember{}
m1.ChannelId = c1.Id
m1.UserId = userId
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(utils.T, &m1))
Must(store.Channel().SaveMember(&m1))
c2 := &model.Channel{}
c2.TeamId = teamId
c2.DisplayName = "Channel1"
c2.Name = "a" + model.NewId() + "b"
c2.Type = model.CHANNEL_OPEN
c2 = (<-store.Channel().Save(utils.T, c2)).Data.(*model.Channel)
c2 = (<-store.Channel().Save(c2)).Data.(*model.Channel)
o1 := &model.Post{}
o1.ChannelId = c1.Id
o1.UserId = model.NewId()
o1.Message = "corey mattermost new york"
o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = c1.Id
o2.UserId = model.NewId()
o2.Message = "New Jersey is where John is from"
o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
o3 := &model.Post{}
o3.ChannelId = c2.Id
o3.UserId = model.NewId()
o3.Message = "New Jersey is where John is from corey new york"
o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
o4 := &model.Post{}
o4.ChannelId = c1.Id
o4.UserId = model.NewId()
o4.Hashtags = "#hashtag"
o4.Message = "(message)blargh"
o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
o4 = (<-store.Post().Save(o4)).Data.(*model.Post)
o5 := &model.Post{}
o5.ChannelId = c1.Id
o5.UserId = model.NewId()
o5.Hashtags = "#secret #howdy"
o5 = (<-store.Post().Save(utils.T, o5)).Data.(*model.Post)
o5 = (<-store.Post().Save(o5)).Data.(*model.Post)
r1 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "corey", IsHashtag: false})).Data.(*model.PostList)
r1 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "corey", IsHashtag: false})).Data.(*model.PostList)
if len(r1.Order) != 1 || r1.Order[0] != o1.Id {
t.Fatal("returned wrong search result")
}
r3 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "new", IsHashtag: false})).Data.(*model.PostList)
r3 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "new", IsHashtag: false})).Data.(*model.PostList)
if len(r3.Order) != 2 || (r3.Order[0] != o1.Id && r3.Order[1] != o1.Id) {
t.Fatal("returned wrong search result")
}
r4 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "john", IsHashtag: false})).Data.(*model.PostList)
r4 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "john", IsHashtag: false})).Data.(*model.PostList)
if len(r4.Order) != 1 || r4.Order[0] != o2.Id {
t.Fatal("returned wrong search result")
}
r5 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "matter*", IsHashtag: false})).Data.(*model.PostList)
r5 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "matter*", IsHashtag: false})).Data.(*model.PostList)
if len(r5.Order) != 1 || r5.Order[0] != o1.Id {
t.Fatal("returned wrong search result")
}
r6 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "#hashtag", IsHashtag: true})).Data.(*model.PostList)
r6 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "#hashtag", IsHashtag: true})).Data.(*model.PostList)
if len(r6.Order) != 1 || r6.Order[0] != o4.Id {
t.Fatal("returned wrong search result")
}
r7 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "#secret", IsHashtag: true})).Data.(*model.PostList)
r7 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "#secret", IsHashtag: true})).Data.(*model.PostList)
if len(r7.Order) != 1 || r7.Order[0] != o5.Id {
t.Fatal("returned wrong search result")
}
r8 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "@thisshouldmatchnothing", IsHashtag: true})).Data.(*model.PostList)
r8 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "@thisshouldmatchnothing", IsHashtag: true})).Data.(*model.PostList)
if len(r8.Order) != 0 {
t.Fatal("returned wrong search result")
}
r9 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "mattermost jersey", IsHashtag: false})).Data.(*model.PostList)
r9 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "mattermost jersey", IsHashtag: false})).Data.(*model.PostList)
if len(r9.Order) != 2 {
t.Fatal("returned wrong search result")
}
r10 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "matter* jer*", IsHashtag: false})).Data.(*model.PostList)
r10 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "matter* jer*", IsHashtag: false})).Data.(*model.PostList)
if len(r10.Order) != 2 {
t.Fatal("returned wrong search result")
}
r11 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "message blargh", IsHashtag: false})).Data.(*model.PostList)
r11 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "message blargh", IsHashtag: false})).Data.(*model.PostList)
if len(r11.Order) != 1 {
t.Fatal("returned wrong search result")
}
r12 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "blargh>", IsHashtag: false})).Data.(*model.PostList)
r12 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "blargh>", IsHashtag: false})).Data.(*model.PostList)
if len(r12.Order) != 1 {
t.Fatal("returned wrong search result")
}
@@ -765,44 +765,44 @@ func TestUserCountsWithPostsByDay(t *testing.T) {
t1.Name = "a" + model.NewId() + "b"
t1.Email = model.NewId() + "@nowhere.com"
t1.Type = model.TEAM_OPEN
t1 = Must(store.Team().Save(utils.T, t1)).(*model.Team)
t1 = Must(store.Team().Save(t1)).(*model.Team)
c1 := &model.Channel{}
c1.TeamId = t1.Id
c1.DisplayName = "Channel2"
c1.Name = "a" + model.NewId() + "b"
c1.Type = model.CHANNEL_OPEN
c1 = Must(store.Channel().Save(utils.T, c1)).(*model.Channel)
c1 = Must(store.Channel().Save(c1)).(*model.Channel)
o1 := &model.Post{}
o1.ChannelId = c1.Id
o1.UserId = model.NewId()
o1.CreateAt = utils.MillisFromTime(utils.Yesterday())
o1.Message = "a" + model.NewId() + "b"
o1 = Must(store.Post().Save(utils.T, o1)).(*model.Post)
o1 = Must(store.Post().Save(o1)).(*model.Post)
o1a := &model.Post{}
o1a.ChannelId = c1.Id
o1a.UserId = model.NewId()
o1a.CreateAt = o1.CreateAt
o1a.Message = "a" + model.NewId() + "b"
o1a = Must(store.Post().Save(utils.T, o1a)).(*model.Post)
o1a = Must(store.Post().Save(o1a)).(*model.Post)
o2 := &model.Post{}
o2.ChannelId = c1.Id
o2.UserId = model.NewId()
o2.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24)
o2.Message = "a" + model.NewId() + "b"
o2 = Must(store.Post().Save(utils.T, o2)).(*model.Post)
o2 = Must(store.Post().Save(o2)).(*model.Post)
o2a := &model.Post{}
o2a.ChannelId = c1.Id
o2a.UserId = o2.UserId
o2a.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24)
o2a.Message = "a" + model.NewId() + "b"
o2a = Must(store.Post().Save(utils.T, o2a)).(*model.Post)
o2a = Must(store.Post().Save(o2a)).(*model.Post)
if r1 := <-store.Post().AnalyticsUserCountsWithPostsByDay(utils.T, t1.Id); r1.Err != nil {
if r1 := <-store.Post().AnalyticsUserCountsWithPostsByDay(t1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
row1 := r1.Data.(model.AnalyticsRows)[0]
@@ -825,47 +825,47 @@ func TestPostCountsByDay(t *testing.T) {
t1.Name = "a" + model.NewId() + "b"
t1.Email = model.NewId() + "@nowhere.com"
t1.Type = model.TEAM_OPEN
t1 = Must(store.Team().Save(utils.T, t1)).(*model.Team)
t1 = Must(store.Team().Save(t1)).(*model.Team)
c1 := &model.Channel{}
c1.TeamId = t1.Id
c1.DisplayName = "Channel2"
c1.Name = "a" + model.NewId() + "b"
c1.Type = model.CHANNEL_OPEN
c1 = Must(store.Channel().Save(utils.T, c1)).(*model.Channel)
c1 = Must(store.Channel().Save(c1)).(*model.Channel)
o1 := &model.Post{}
o1.ChannelId = c1.Id
o1.UserId = model.NewId()
o1.CreateAt = utils.MillisFromTime(utils.Yesterday())
o1.Message = "a" + model.NewId() + "b"
o1 = Must(store.Post().Save(utils.T, o1)).(*model.Post)
o1 = Must(store.Post().Save(o1)).(*model.Post)
o1a := &model.Post{}
o1a.ChannelId = c1.Id
o1a.UserId = model.NewId()
o1a.CreateAt = o1.CreateAt
o1a.Message = "a" + model.NewId() + "b"
o1a = Must(store.Post().Save(utils.T, o1a)).(*model.Post)
o1a = Must(store.Post().Save(o1a)).(*model.Post)
o2 := &model.Post{}
o2.ChannelId = c1.Id
o2.UserId = model.NewId()
o2.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24 * 2)
o2.Message = "a" + model.NewId() + "b"
o2 = Must(store.Post().Save(utils.T, o2)).(*model.Post)
o2 = Must(store.Post().Save(o2)).(*model.Post)
o2a := &model.Post{}
o2a.ChannelId = c1.Id
o2a.UserId = o2.UserId
o2a.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24 * 2)
o2a.Message = "a" + model.NewId() + "b"
o2a = Must(store.Post().Save(utils.T, o2a)).(*model.Post)
o2a = Must(store.Post().Save(o2a)).(*model.Post)
time.Sleep(1 * time.Second)
t.Log(t1.Id)
if r1 := <-store.Post().AnalyticsPostCountsByDay(utils.T, t1.Id); r1.Err != nil {
if r1 := <-store.Post().AnalyticsPostCountsByDay(t1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
row1 := r1.Data.(model.AnalyticsRows)[0]
@@ -880,7 +880,7 @@ func TestPostCountsByDay(t *testing.T) {
}
}
if r1 := <-store.Post().AnalyticsPostCount(utils.T, t1.Id); r1.Err != nil {
if r1 := <-store.Post().AnalyticsPostCount(t1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(int64) != 4 {

View File

@@ -8,7 +8,6 @@ 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 {
@@ -42,7 +41,7 @@ func (s SqlPreferenceStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_preferences_name", "Preferences", "Name")
}
func (s SqlPreferenceStore) DeleteUnusedFeatures(T goi18n.TranslateFunc) {
func (s SqlPreferenceStore) DeleteUnusedFeatures() {
l4g.Debug("Deleting any unused pre-release features")
sql := `DELETE
@@ -59,7 +58,7 @@ func (s SqlPreferenceStore) DeleteUnusedFeatures(T goi18n.TranslateFunc) {
s.GetMaster().Exec(sql, queryParams)
}
func (s SqlPreferenceStore) Save(T goi18n.TranslateFunc, preferences *model.Preferences) StoreChannel {
func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -71,7 +70,7 @@ func (s SqlPreferenceStore) Save(T goi18n.TranslateFunc, preferences *model.Pref
result.Err = model.NewAppError("SqlPreferenceStore.Save", "Unable to open transaction to save preferences", err.Error())
} else {
for _, preference := range *preferences {
if upsertResult := s.save(T, transaction, &preference); upsertResult.Err != nil {
if upsertResult := s.save(transaction, &preference); upsertResult.Err != nil {
result = upsertResult
break
}
@@ -98,7 +97,7 @@ func (s SqlPreferenceStore) Save(T goi18n.TranslateFunc, preferences *model.Pref
return storeChannel
}
func (s SqlPreferenceStore) save(T goi18n.TranslateFunc, transaction *gorp.Transaction, preference *model.Preference) StoreResult {
func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
result := StoreResult{}
if result.Err = preference.IsValid(); result.Err != nil {
@@ -140,9 +139,9 @@ func (s SqlPreferenceStore) save(T goi18n.TranslateFunc, transaction *gorp.Trans
}
if count == 1 {
s.update(T, transaction, preference)
s.update(transaction, preference)
} else {
s.insert(T, transaction, preference)
s.insert(transaction, preference)
}
} else {
result.Err = model.NewAppError("SqlPreferenceStore.save", "We encountered an error while updating preferences",
@@ -152,7 +151,7 @@ func (s SqlPreferenceStore) save(T goi18n.TranslateFunc, transaction *gorp.Trans
return result
}
func (s SqlPreferenceStore) insert(T goi18n.TranslateFunc, transaction *gorp.Transaction, preference *model.Preference) StoreResult {
func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
result := StoreResult{}
if err := transaction.Insert(preference); err != nil {
@@ -168,7 +167,7 @@ func (s SqlPreferenceStore) insert(T goi18n.TranslateFunc, transaction *gorp.Tra
return result
}
func (s SqlPreferenceStore) update(T goi18n.TranslateFunc, transaction *gorp.Transaction, preference *model.Preference) StoreResult {
func (s SqlPreferenceStore) update(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
result := StoreResult{}
if _, err := transaction.Update(preference); err != nil {
@@ -179,7 +178,7 @@ func (s SqlPreferenceStore) update(T goi18n.TranslateFunc, transaction *gorp.Tra
return result
}
func (s SqlPreferenceStore) Get(T goi18n.TranslateFunc, userId string, category string, name string) StoreChannel {
func (s SqlPreferenceStore) Get(userId string, category string, name string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -208,7 +207,7 @@ func (s SqlPreferenceStore) Get(T goi18n.TranslateFunc, userId string, category
return storeChannel
}
func (s SqlPreferenceStore) GetCategory(T goi18n.TranslateFunc, userId string, category string) StoreChannel {
func (s SqlPreferenceStore) GetCategory(userId string, category string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -236,7 +235,7 @@ func (s SqlPreferenceStore) GetCategory(T goi18n.TranslateFunc, userId string, c
return storeChannel
}
func (s SqlPreferenceStore) GetAll(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlPreferenceStore) GetAll(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -263,7 +262,7 @@ func (s SqlPreferenceStore) GetAll(T goi18n.TranslateFunc, userId string) StoreC
return storeChannel
}
func (s SqlPreferenceStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -281,7 +280,7 @@ func (s SqlPreferenceStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId
return storeChannel
}
func (s SqlPreferenceStore) IsFeatureEnabled(T goi18n.TranslateFunc, feature, userId string) StoreChannel {
func (s SqlPreferenceStore) IsFeatureEnabled(feature, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing"
)
@@ -28,24 +27,24 @@ func TestPreferenceSave(t *testing.T) {
Value: "value1b",
},
}
if count := Must(store.Preference().Save(utils.T, &preferences)); count != 2 {
if count := Must(store.Preference().Save(&preferences)); count != 2 {
t.Fatal("got incorrect number of rows saved")
}
for _, preference := range preferences {
if data := Must(store.Preference().Get(utils.T, preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data {
if data := Must(store.Preference().Get(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(utils.T, &preferences)); count != 2 {
if count := Must(store.Preference().Save(&preferences)); count != 2 {
t.Fatal("got incorrect number of rows saved")
}
for _, preference := range preferences {
if data := Must(store.Preference().Get(utils.T, preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data {
if data := Must(store.Preference().Get(preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data {
t.Fatal("got incorrect preference after second Save")
}
}
@@ -81,16 +80,16 @@ func TestPreferenceGet(t *testing.T) {
},
}
Must(store.Preference().Save(utils.T, &preferences))
Must(store.Preference().Save(&preferences))
if result := <-store.Preference().Get(utils.T, userId, category, name); result.Err != nil {
if result := <-store.Preference().Get(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(utils.T, model.NewId(), model.NewId(), model.NewId()); result.Err == nil {
if result := <-store.Preference().Get(model.NewId(), model.NewId(), model.NewId()); result.Err == nil {
t.Fatal("no error on getting a missing preference")
}
}
@@ -128,9 +127,9 @@ func TestPreferenceGetCategory(t *testing.T) {
},
}
Must(store.Preference().Save(utils.T, &preferences))
Must(store.Preference().Save(&preferences))
if result := <-store.Preference().GetCategory(utils.T, userId, category); result.Err != nil {
if result := <-store.Preference().GetCategory(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")
@@ -139,7 +138,7 @@ func TestPreferenceGetCategory(t *testing.T) {
}
// make sure getting a missing preference category doesn't fail
if result := <-store.Preference().GetCategory(utils.T, model.NewId(), model.NewId()); result.Err != nil {
if result := <-store.Preference().GetCategory(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")
@@ -179,9 +178,9 @@ func TestPreferenceGetAll(t *testing.T) {
},
}
Must(store.Preference().Save(utils.T, &preferences))
Must(store.Preference().Save(&preferences))
if result := <-store.Preference().GetAll(utils.T, userId); result.Err != nil {
if result := <-store.Preference().GetAll(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")
@@ -227,9 +226,9 @@ func TestPreferenceDelete(t *testing.T) {
},
}
Must(store.Preference().Save(utils.T, &preferences))
Must(store.Preference().Save(&preferences))
if result := <-store.Preference().PermanentDeleteByUser(utils.T, userId); result.Err != nil {
if result := <-store.Preference().PermanentDeleteByUser(userId); result.Err != nil {
t.Fatal(result.Err)
}
}
@@ -277,29 +276,29 @@ func TestIsFeatureEnabled(t *testing.T) {
},
}
Must(store.Preference().Save(utils.T, &features))
Must(store.Preference().Save(&features))
if result := <-store.Preference().IsFeatureEnabled(utils.T, feature1, userId); result.Err != nil {
if result := <-store.Preference().IsFeatureEnabled(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(utils.T, feature2, userId); result.Err != nil {
if result := <-store.Preference().IsFeatureEnabled(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(utils.T, feature3, userId); result.Err != nil {
if result := <-store.Preference().IsFeatureEnabled(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(utils.T, "someOtherFeature", userId); result.Err != nil {
if result := <-store.Preference().IsFeatureEnabled("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)
@@ -342,9 +341,9 @@ func TestDeleteUnusedFeatures(t *testing.T) {
},
}
Must(store.Preference().Save(utils.T, &features))
Must(store.Preference().Save(&features))
store.(*SqlStore).preference.(*SqlPreferenceStore).DeleteUnusedFeatures(utils.T)
store.(*SqlStore).preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
//make sure features with value "false" have actually been deleted from the database
if val, err := store.(*SqlStore).preference.(*SqlPreferenceStore).GetReplica().SelectInt(`SELECT COUNT(*)

View File

@@ -6,7 +6,6 @@ package store
import (
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlSessionStore struct {
@@ -38,7 +37,7 @@ func (me SqlSessionStore) CreateIndexesIfNotExists() {
me.CreateIndexIfNotExists("idx_sessions_token", "Sessions", "Token")
}
func (me SqlSessionStore) Save(T goi18n.TranslateFunc, session *model.Session) StoreChannel {
func (me SqlSessionStore) Save(session *model.Session) StoreChannel {
storeChannel := make(StoreChannel)
@@ -54,7 +53,7 @@ func (me SqlSessionStore) Save(T goi18n.TranslateFunc, session *model.Session) S
session.PreSave()
if cur := <-me.CleanUpExpiredSessions(T, session.UserId); cur.Err != nil {
if cur := <-me.CleanUpExpiredSessions(session.UserId); cur.Err != nil {
l4g.Error("Failed to cleanup sessions in Save err=%v", cur.Err)
}
@@ -71,7 +70,7 @@ func (me SqlSessionStore) Save(T goi18n.TranslateFunc, session *model.Session) S
return storeChannel
}
func (me SqlSessionStore) Get(T goi18n.TranslateFunc, sessionIdOrToken string) StoreChannel {
func (me SqlSessionStore) Get(sessionIdOrToken string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -96,12 +95,12 @@ func (me SqlSessionStore) Get(T goi18n.TranslateFunc, sessionIdOrToken string) S
return storeChannel
}
func (me SqlSessionStore) GetSessions(T goi18n.TranslateFunc, userId string) StoreChannel {
func (me SqlSessionStore) GetSessions(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
if cur := <-me.CleanUpExpiredSessions(T, userId); cur.Err != nil {
if cur := <-me.CleanUpExpiredSessions(userId); cur.Err != nil {
l4g.Error("Failed to cleanup sessions in getSessions err=%v", cur.Err)
}
@@ -123,7 +122,7 @@ func (me SqlSessionStore) GetSessions(T goi18n.TranslateFunc, userId string) Sto
return storeChannel
}
func (me SqlSessionStore) Remove(T goi18n.TranslateFunc, sessionIdOrToken string) StoreChannel {
func (me SqlSessionStore) Remove(sessionIdOrToken string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -141,7 +140,7 @@ func (me SqlSessionStore) Remove(T goi18n.TranslateFunc, sessionIdOrToken string
return storeChannel
}
func (me SqlSessionStore) RemoveAllSessionsForTeam(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (me SqlSessionStore) RemoveAllSessionsForTeam(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -159,7 +158,7 @@ func (me SqlSessionStore) RemoveAllSessionsForTeam(T goi18n.TranslateFunc, teamI
return storeChannel
}
func (me SqlSessionStore) PermanentDeleteSessionsByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (me SqlSessionStore) PermanentDeleteSessionsByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -177,7 +176,7 @@ func (me SqlSessionStore) PermanentDeleteSessionsByUser(T goi18n.TranslateFunc,
return storeChannel
}
func (me SqlSessionStore) CleanUpExpiredSessions(T goi18n.TranslateFunc, userId string) StoreChannel {
func (me SqlSessionStore) CleanUpExpiredSessions(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -196,7 +195,7 @@ func (me SqlSessionStore) CleanUpExpiredSessions(T goi18n.TranslateFunc, userId
return storeChannel
}
func (me SqlSessionStore) UpdateLastActivityAt(T goi18n.TranslateFunc, sessionId string, time int64) StoreChannel {
func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -215,7 +214,7 @@ func (me SqlSessionStore) UpdateLastActivityAt(T goi18n.TranslateFunc, sessionId
return storeChannel
}
func (me SqlSessionStore) UpdateRoles(T goi18n.TranslateFunc, userId, roles string) StoreChannel {
func (me SqlSessionStore) UpdateRoles(userId, roles string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing"
)
@@ -16,7 +15,7 @@ func TestSessionStoreSave(t *testing.T) {
s1.UserId = model.NewId()
s1.TeamId = model.NewId()
if err := (<-store.Session().Save(utils.T, &s1)).Err; err != nil {
if err := (<-store.Session().Save(&s1)).Err; err != nil {
t.Fatal(err)
}
}
@@ -27,20 +26,20 @@ func TestSessionGet(t *testing.T) {
s1 := model.Session{}
s1.UserId = model.NewId()
s1.TeamId = model.NewId()
Must(store.Session().Save(utils.T, &s1))
Must(store.Session().Save(&s1))
s2 := model.Session{}
s2.UserId = s1.UserId
s2.TeamId = s1.TeamId
Must(store.Session().Save(utils.T, &s2))
Must(store.Session().Save(&s2))
s3 := model.Session{}
s3.UserId = s1.UserId
s3.TeamId = s1.TeamId
s3.ExpiresAt = 1
Must(store.Session().Save(utils.T, &s3))
Must(store.Session().Save(&s3))
if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil {
if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil {
t.Fatal(rs1.Err)
} else {
if rs1.Data.(*model.Session).Id != s1.Id {
@@ -48,7 +47,7 @@ func TestSessionGet(t *testing.T) {
}
}
if rs2 := (<-store.Session().GetSessions(utils.T, s1.UserId)); rs2.Err != nil {
if rs2 := (<-store.Session().GetSessions(s1.UserId)); rs2.Err != nil {
t.Fatal(rs2.Err)
} else {
if len(rs2.Data.([]*model.Session)) != 2 {
@@ -64,9 +63,9 @@ func TestSessionRemove(t *testing.T) {
s1 := model.Session{}
s1.UserId = model.NewId()
s1.TeamId = model.NewId()
Must(store.Session().Save(utils.T, &s1))
Must(store.Session().Save(&s1))
if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil {
if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil {
t.Fatal(rs1.Err)
} else {
if rs1.Data.(*model.Session).Id != s1.Id {
@@ -74,9 +73,9 @@ func TestSessionRemove(t *testing.T) {
}
}
Must(store.Session().Remove(utils.T, s1.Id))
Must(store.Session().Remove(s1.Id))
if rs2 := (<-store.Session().Get(utils.T, s1.Id)); rs2.Err == nil {
if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil {
t.Fatal("should have been removed")
}
}
@@ -87,9 +86,9 @@ func TestSessionRemoveAll(t *testing.T) {
s1 := model.Session{}
s1.UserId = model.NewId()
s1.TeamId = model.NewId()
Must(store.Session().Save(utils.T, &s1))
Must(store.Session().Save(&s1))
if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil {
if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil {
t.Fatal(rs1.Err)
} else {
if rs1.Data.(*model.Session).Id != s1.Id {
@@ -97,9 +96,9 @@ func TestSessionRemoveAll(t *testing.T) {
}
}
Must(store.Session().RemoveAllSessionsForTeam(utils.T, s1.TeamId))
Must(store.Session().RemoveAllSessionsForTeam(s1.TeamId))
if rs2 := (<-store.Session().Get(utils.T, s1.Id)); rs2.Err == nil {
if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil {
t.Fatal("should have been removed")
}
}
@@ -110,9 +109,9 @@ func TestSessionRemoveByUser(t *testing.T) {
s1 := model.Session{}
s1.UserId = model.NewId()
s1.TeamId = model.NewId()
Must(store.Session().Save(utils.T, &s1))
Must(store.Session().Save(&s1))
if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil {
if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil {
t.Fatal(rs1.Err)
} else {
if rs1.Data.(*model.Session).Id != s1.Id {
@@ -120,9 +119,9 @@ func TestSessionRemoveByUser(t *testing.T) {
}
}
Must(store.Session().PermanentDeleteSessionsByUser(utils.T, s1.UserId))
Must(store.Session().PermanentDeleteSessionsByUser(s1.UserId))
if rs2 := (<-store.Session().Get(utils.T, s1.Id)); rs2.Err == nil {
if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil {
t.Fatal("should have been removed")
}
}
@@ -133,9 +132,9 @@ func TestSessionRemoveToken(t *testing.T) {
s1 := model.Session{}
s1.UserId = model.NewId()
s1.TeamId = model.NewId()
Must(store.Session().Save(utils.T, &s1))
Must(store.Session().Save(&s1))
if rs1 := (<-store.Session().Get(utils.T, s1.Id)); rs1.Err != nil {
if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil {
t.Fatal(rs1.Err)
} else {
if rs1.Data.(*model.Session).Id != s1.Id {
@@ -143,13 +142,13 @@ func TestSessionRemoveToken(t *testing.T) {
}
}
Must(store.Session().Remove(utils.T, s1.Token))
Must(store.Session().Remove(s1.Token))
if rs2 := (<-store.Session().Get(utils.T, s1.Id)); rs2.Err == nil {
if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil {
t.Fatal("should have been removed")
}
if rs3 := (<-store.Session().GetSessions(utils.T, s1.UserId)); rs3.Err != nil {
if rs3 := (<-store.Session().GetSessions(s1.UserId)); rs3.Err != nil {
t.Fatal(rs3.Err)
} else {
if len(rs3.Data.([]*model.Session)) != 0 {
@@ -164,13 +163,13 @@ func TestSessionStoreUpdateLastActivityAt(t *testing.T) {
s1 := model.Session{}
s1.UserId = model.NewId()
s1.TeamId = model.NewId()
Must(store.Session().Save(utils.T, &s1))
Must(store.Session().Save(&s1))
if err := (<-store.Session().UpdateLastActivityAt(utils.T, s1.Id, 1234567890)).Err; err != nil {
if err := (<-store.Session().UpdateLastActivityAt(s1.Id, 1234567890)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.Session().Get(utils.T, s1.Id); r1.Err != nil {
if r1 := <-store.Session().Get(s1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Session).LastActivityAt != 1234567890 {

View File

@@ -15,6 +15,7 @@ import (
"encoding/json"
"errors"
"fmt"
l4g "github.com/alecthomas/log4go"
"io"
sqltrace "log"
"math/rand"
@@ -22,7 +23,6 @@ import (
"strings"
"time"
l4g "github.com/alecthomas/log4go"
"github.com/go-gorp/gorp"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
@@ -148,15 +148,15 @@ func NewSqlStore() Store {
sqlStore.webhook.(*SqlWebhookStore).CreateIndexesIfNotExists()
sqlStore.preference.(*SqlPreferenceStore).CreateIndexesIfNotExists()
sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures(utils.T)
sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 {
sqlStore.system.Update(utils.T, &model.System{Name: "Version", Value: model.CurrentVersion})
sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion})
l4g.Warn("The database schema has been upgraded to version " + model.CurrentVersion)
}
if schemaVersion == "" {
sqlStore.system.Save(utils.T, &model.System{Name: "Version", Value: model.CurrentVersion})
sqlStore.system.Save(&model.System{Name: "Version", Value: model.CurrentVersion})
l4g.Info("The database schema has been set to version " + model.CurrentVersion)
}
@@ -210,12 +210,12 @@ func (ss SqlStore) GetCurrentSchemaVersion() string {
}
func (ss SqlStore) MarkSystemRanUnitTests() {
if result := <-ss.System().Get(utils.T); result.Err == nil {
if result := <-ss.System().Get(); result.Err == nil {
props := result.Data.(model.StringMap)
unitTests := props[model.SYSTEM_RAN_UNIT_TESTS]
if len(unitTests) == 0 {
systemTests := &model.System{Name: model.SYSTEM_RAN_UNIT_TESTS, Value: "1"}
<-ss.System().Save(utils.T, systemTests)
<-ss.System().Save(systemTests)
}
}
}

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlSystemStore struct {
@@ -30,7 +29,7 @@ func (s SqlSystemStore) UpgradeSchemaIfNeeded() {
func (s SqlSystemStore) CreateIndexesIfNotExists() {
}
func (s SqlSystemStore) Save(T goi18n.TranslateFunc, system *model.System) StoreChannel {
func (s SqlSystemStore) Save(system *model.System) StoreChannel {
storeChannel := make(StoreChannel)
@@ -48,7 +47,7 @@ func (s SqlSystemStore) Save(T goi18n.TranslateFunc, system *model.System) Store
return storeChannel
}
func (s SqlSystemStore) Update(T goi18n.TranslateFunc, system *model.System) StoreChannel {
func (s SqlSystemStore) Update(system *model.System) StoreChannel {
storeChannel := make(StoreChannel)
@@ -66,7 +65,7 @@ func (s SqlSystemStore) Update(T goi18n.TranslateFunc, system *model.System) Sto
return storeChannel
}
func (s SqlSystemStore) Get(T goi18n.TranslateFunc) StoreChannel {
func (s SqlSystemStore) Get() StoreChannel {
storeChannel := make(StoreChannel)

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing"
)
@@ -13,9 +12,9 @@ func TestSqlSystemStore(t *testing.T) {
Setup()
system := &model.System{Name: model.NewId(), Value: "value"}
Must(store.System().Save(utils.T, system))
Must(store.System().Save(system))
result := <-store.System().Get(utils.T)
result := <-store.System().Get()
systems := result.Data.(model.StringMap)
if systems[system.Name] != system.Value {
@@ -23,9 +22,9 @@ func TestSqlSystemStore(t *testing.T) {
}
system.Value = "value2"
Must(store.System().Update(utils.T, system))
Must(store.System().Update(system))
result2 := <-store.System().Get(utils.T)
result2 := <-store.System().Get()
systems2 := result2.Data.(model.StringMap)
if systems2[system.Name] != system.Value {

View File

@@ -6,7 +6,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlTeamStore struct {
@@ -38,7 +37,7 @@ func (s SqlTeamStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_teams_invite_id", "Teams", "InviteId")
}
func (s SqlTeamStore) Save(T goi18n.TranslateFunc, team *model.Team) StoreChannel {
func (s SqlTeamStore) Save(team *model.Team) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -77,7 +76,7 @@ func (s SqlTeamStore) Save(T goi18n.TranslateFunc, team *model.Team) StoreChanne
return storeChannel
}
func (s SqlTeamStore) Update(T goi18n.TranslateFunc, team *model.Team) StoreChannel {
func (s SqlTeamStore) Update(team *model.Team) StoreChannel {
storeChannel := make(StoreChannel)
@@ -118,7 +117,7 @@ func (s SqlTeamStore) Update(T goi18n.TranslateFunc, team *model.Team) StoreChan
return storeChannel
}
func (s SqlTeamStore) UpdateDisplayName(T goi18n.TranslateFunc, name string, teamId string) StoreChannel {
func (s SqlTeamStore) UpdateDisplayName(name string, teamId string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -138,7 +137,7 @@ func (s SqlTeamStore) UpdateDisplayName(T goi18n.TranslateFunc, name string, tea
return storeChannel
}
func (s SqlTeamStore) Get(T goi18n.TranslateFunc, id string) StoreChannel {
func (s SqlTeamStore) Get(id string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -164,7 +163,7 @@ func (s SqlTeamStore) Get(T goi18n.TranslateFunc, id string) StoreChannel {
return storeChannel
}
func (s SqlTeamStore) GetByInviteId(T goi18n.TranslateFunc, inviteId string) StoreChannel {
func (s SqlTeamStore) GetByInviteId(inviteId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -193,7 +192,7 @@ func (s SqlTeamStore) GetByInviteId(T goi18n.TranslateFunc, inviteId string) Sto
return storeChannel
}
func (s SqlTeamStore) GetByName(T goi18n.TranslateFunc, name string) StoreChannel {
func (s SqlTeamStore) GetByName(name string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -218,7 +217,7 @@ func (s SqlTeamStore) GetByName(T goi18n.TranslateFunc, name string) StoreChanne
return storeChannel
}
func (s SqlTeamStore) GetTeamsForEmail(T goi18n.TranslateFunc, email string) StoreChannel {
func (s SqlTeamStore) GetTeamsForEmail(email string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -244,7 +243,7 @@ func (s SqlTeamStore) GetTeamsForEmail(T goi18n.TranslateFunc, email string) Sto
return storeChannel
}
func (s SqlTeamStore) GetAll(T goi18n.TranslateFunc) StoreChannel {
func (s SqlTeamStore) GetAll() StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -270,7 +269,7 @@ func (s SqlTeamStore) GetAll(T goi18n.TranslateFunc) StoreChannel {
return storeChannel
}
func (s SqlTeamStore) GetAllTeamListing(T goi18n.TranslateFunc) StoreChannel {
func (s SqlTeamStore) GetAllTeamListing() StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -302,7 +301,7 @@ func (s SqlTeamStore) GetAllTeamListing(T goi18n.TranslateFunc) StoreChannel {
return storeChannel
}
func (s SqlTeamStore) PermanentDelete(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (s SqlTeamStore) PermanentDelete(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing"
"time"
)
@@ -19,16 +18,16 @@ func TestTeamStoreSave(t *testing.T) {
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
if err := (<-store.Team().Save(utils.T, &o1)).Err; err != nil {
if err := (<-store.Team().Save(&o1)).Err; err != nil {
t.Fatal("couldn't save item", err)
}
if err := (<-store.Team().Save(utils.T, &o1)).Err; err == nil {
if err := (<-store.Team().Save(&o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
o1.Id = ""
if err := (<-store.Team().Save(utils.T, &o1)).Err; err == nil {
if err := (<-store.Team().Save(&o1)).Err; err == nil {
t.Fatal("should be unique domain")
}
}
@@ -41,23 +40,23 @@ func TestTeamStoreUpdate(t *testing.T) {
o1.Name = "a" + model.NewId() + "b"
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
if err := (<-store.Team().Save(utils.T, &o1)).Err; err != nil {
if err := (<-store.Team().Save(&o1)).Err; err != nil {
t.Fatal(err)
}
time.Sleep(100 * time.Millisecond)
if err := (<-store.Team().Update(utils.T, &o1)).Err; err != nil {
if err := (<-store.Team().Update(&o1)).Err; err != nil {
t.Fatal(err)
}
o1.Id = "missing"
if err := (<-store.Team().Update(utils.T, &o1)).Err; err == nil {
if err := (<-store.Team().Update(&o1)).Err; err == nil {
t.Fatal("Update should have failed because of missing key")
}
o1.Id = model.NewId()
if err := (<-store.Team().Update(utils.T, &o1)).Err; err == nil {
if err := (<-store.Team().Update(&o1)).Err; err == nil {
t.Fatal("Update should have faile because id change")
}
}
@@ -70,15 +69,15 @@ func TestTeamStoreUpdateDisplayName(t *testing.T) {
o1.Name = "a" + model.NewId() + "b"
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
o1 = (<-store.Team().Save(utils.T, o1)).Data.(*model.Team)
o1 = (<-store.Team().Save(o1)).Data.(*model.Team)
newDisplayName := "NewDisplayName"
if err := (<-store.Team().UpdateDisplayName(utils.T, newDisplayName, o1.Id)).Err; err != nil {
if err := (<-store.Team().UpdateDisplayName(newDisplayName, o1.Id)).Err; err != nil {
t.Fatal(err)
}
ro1 := (<-store.Team().Get(utils.T, o1.Id)).Data.(*model.Team)
ro1 := (<-store.Team().Get(o1.Id)).Data.(*model.Team)
if ro1.DisplayName != newDisplayName {
t.Fatal("DisplayName not updated")
}
@@ -92,9 +91,9 @@ func TestTeamStoreGet(t *testing.T) {
o1.Name = "a" + model.NewId() + "b"
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
Must(store.Team().Save(utils.T, &o1))
Must(store.Team().Save(&o1))
if r1 := <-store.Team().Get(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Team().Get(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Team).ToJson() != o1.ToJson() {
@@ -102,7 +101,7 @@ func TestTeamStoreGet(t *testing.T) {
}
}
if err := (<-store.Team().Get(utils.T, "")).Err; err == nil {
if err := (<-store.Team().Get("")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
@@ -116,11 +115,11 @@ func TestTeamStoreGetByName(t *testing.T) {
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
if err := (<-store.Team().Save(utils.T, &o1)).Err; err != nil {
if err := (<-store.Team().Save(&o1)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.Team().GetByName(utils.T, o1.Name); r1.Err != nil {
if r1 := <-store.Team().GetByName(o1.Name); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Team).ToJson() != o1.ToJson() {
@@ -128,7 +127,7 @@ func TestTeamStoreGetByName(t *testing.T) {
}
}
if err := (<-store.Team().GetByName(utils.T, "")).Err; err == nil {
if err := (<-store.Team().GetByName("")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
@@ -143,7 +142,7 @@ func TestTeamStoreGetByIniviteId(t *testing.T) {
o1.Type = model.TEAM_OPEN
o1.InviteId = model.NewId()
if err := (<-store.Team().Save(utils.T, &o1)).Err; err != nil {
if err := (<-store.Team().Save(&o1)).Err; err != nil {
t.Fatal(err)
}
@@ -153,11 +152,11 @@ func TestTeamStoreGetByIniviteId(t *testing.T) {
o2.Email = model.NewId() + "@nowhere.com"
o2.Type = model.TEAM_OPEN
if err := (<-store.Team().Save(utils.T, &o2)).Err; err != nil {
if err := (<-store.Team().Save(&o2)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.Team().GetByInviteId(utils.T, o1.InviteId); r1.Err != nil {
if r1 := <-store.Team().GetByInviteId(o1.InviteId); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Team).ToJson() != o1.ToJson() {
@@ -166,9 +165,9 @@ func TestTeamStoreGetByIniviteId(t *testing.T) {
}
o2.InviteId = ""
<-store.Team().Update(utils.T, &o2)
<-store.Team().Update(&o2)
if r1 := <-store.Team().GetByInviteId(utils.T, o2.Id); r1.Err != nil {
if r1 := <-store.Team().GetByInviteId(o2.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Team).Id != o2.Id {
@@ -176,7 +175,7 @@ func TestTeamStoreGetByIniviteId(t *testing.T) {
}
}
if err := (<-store.Team().GetByInviteId(utils.T, "")).Err; err == nil {
if err := (<-store.Team().GetByInviteId("")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
@@ -189,14 +188,14 @@ func TestTeamStoreGetForEmail(t *testing.T) {
o1.Name = "a" + model.NewId() + "b"
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
Must(store.Team().Save(utils.T, &o1))
Must(store.Team().Save(&o1))
u1 := model.User{}
u1.TeamId = o1.Id
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if r1 := <-store.Team().GetTeamsForEmail(utils.T, u1.Email); r1.Err != nil {
if r1 := <-store.Team().GetTeamsForEmail(u1.Email); r1.Err != nil {
t.Fatal(r1.Err)
} else {
teams := r1.Data.([]*model.Team)
@@ -206,7 +205,7 @@ func TestTeamStoreGetForEmail(t *testing.T) {
}
}
if r1 := <-store.Team().GetTeamsForEmail(utils.T, "missing"); r1.Err != nil {
if r1 := <-store.Team().GetTeamsForEmail("missing"); r1.Err != nil {
t.Fatal(r1.Err)
}
}
@@ -220,16 +219,16 @@ func TestAllTeamListing(t *testing.T) {
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
o1.AllowTeamListing = true
Must(store.Team().Save(utils.T, &o1))
Must(store.Team().Save(&o1))
o2 := model.Team{}
o2.DisplayName = "DisplayName"
o2.Name = "a" + model.NewId() + "b"
o2.Email = model.NewId() + "@nowhere.com"
o2.Type = model.TEAM_OPEN
Must(store.Team().Save(utils.T, &o2))
Must(store.Team().Save(&o2))
if r1 := <-store.Team().GetAllTeamListing(utils.T); r1.Err != nil {
if r1 := <-store.Team().GetAllTeamListing(); r1.Err != nil {
t.Fatal(r1.Err)
} else {
teams := r1.Data.([]*model.Team)
@@ -249,16 +248,16 @@ func TestDelete(t *testing.T) {
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
o1.AllowTeamListing = true
Must(store.Team().Save(utils.T, &o1))
Must(store.Team().Save(&o1))
o2 := model.Team{}
o2.DisplayName = "DisplayName"
o2.Name = "a" + model.NewId() + "b"
o2.Email = model.NewId() + "@nowhere.com"
o2.Type = model.TEAM_OPEN
Must(store.Team().Save(utils.T, &o2))
Must(store.Team().Save(&o2))
if r1 := <-store.Team().PermanentDelete(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Team().PermanentDelete(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
}
}

View File

@@ -5,11 +5,9 @@ package store
import (
"fmt"
"strings"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
"strings"
)
const (
@@ -56,7 +54,7 @@ func (us SqlUserStore) CreateIndexesIfNotExists() {
us.CreateIndexIfNotExists("idx_users_email", "Users", "Email")
}
func (us SqlUserStore) Save(T goi18n.TranslateFunc, user *model.User) StoreChannel {
func (us SqlUserStore) Save(user *model.User) StoreChannel {
storeChannel := make(StoreChannel)
@@ -108,7 +106,7 @@ func (us SqlUserStore) Save(T goi18n.TranslateFunc, user *model.User) StoreChann
return storeChannel
}
func (us SqlUserStore) Update(T goi18n.TranslateFunc, user *model.User, allowActiveUpdate bool) StoreChannel {
func (us SqlUserStore) Update(user *model.User, allowActiveUpdate bool) StoreChannel {
storeChannel := make(StoreChannel)
@@ -185,7 +183,7 @@ func (us SqlUserStore) Update(T goi18n.TranslateFunc, user *model.User, allowAct
return storeChannel
}
func (us SqlUserStore) UpdateLastPictureUpdate(T goi18n.TranslateFunc, userId string) StoreChannel {
func (us SqlUserStore) UpdateLastPictureUpdate(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -206,7 +204,7 @@ func (us SqlUserStore) UpdateLastPictureUpdate(T goi18n.TranslateFunc, userId st
return storeChannel
}
func (us SqlUserStore) UpdateLastPingAt(T goi18n.TranslateFunc, userId string, time int64) StoreChannel {
func (us SqlUserStore) UpdateLastPingAt(userId string, time int64) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -225,7 +223,7 @@ func (us SqlUserStore) UpdateLastPingAt(T goi18n.TranslateFunc, userId string, t
return storeChannel
}
func (us SqlUserStore) UpdateLastActivityAt(T goi18n.TranslateFunc, userId string, time int64) StoreChannel {
func (us SqlUserStore) UpdateLastActivityAt(userId string, time int64) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -244,7 +242,7 @@ func (us SqlUserStore) UpdateLastActivityAt(T goi18n.TranslateFunc, userId strin
return storeChannel
}
func (us SqlUserStore) UpdateUserAndSessionActivity(T goi18n.TranslateFunc, userId string, sessionId string, time int64) StoreChannel {
func (us SqlUserStore) UpdateUserAndSessionActivity(userId string, sessionId string, time int64) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -265,7 +263,7 @@ func (us SqlUserStore) UpdateUserAndSessionActivity(T goi18n.TranslateFunc, user
return storeChannel
}
func (us SqlUserStore) UpdatePassword(T goi18n.TranslateFunc, userId, hashedPassword string) StoreChannel {
func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -287,7 +285,7 @@ func (us SqlUserStore) UpdatePassword(T goi18n.TranslateFunc, userId, hashedPass
return storeChannel
}
func (us SqlUserStore) UpdateFailedPasswordAttempts(T goi18n.TranslateFunc, userId string, attempts int) StoreChannel {
func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -306,7 +304,7 @@ func (us SqlUserStore) UpdateFailedPasswordAttempts(T goi18n.TranslateFunc, user
return storeChannel
}
func (us SqlUserStore) UpdateAuthData(T goi18n.TranslateFunc, userId, service, authData string) StoreChannel {
func (us SqlUserStore) UpdateAuthData(userId, service, authData string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -328,7 +326,7 @@ func (us SqlUserStore) UpdateAuthData(T goi18n.TranslateFunc, userId, service, a
return storeChannel
}
func (us SqlUserStore) Get(T goi18n.TranslateFunc, id string) StoreChannel {
func (us SqlUserStore) Get(id string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -351,7 +349,7 @@ func (us SqlUserStore) Get(T goi18n.TranslateFunc, id string) StoreChannel {
return storeChannel
}
func (s SqlUserStore) GetEtagForProfiles(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (s SqlUserStore) GetEtagForProfiles(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -371,7 +369,7 @@ func (s SqlUserStore) GetEtagForProfiles(T goi18n.TranslateFunc, teamId string)
return storeChannel
}
func (us SqlUserStore) GetProfiles(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (us SqlUserStore) GetProfiles(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -402,7 +400,7 @@ func (us SqlUserStore) GetProfiles(T goi18n.TranslateFunc, teamId string) StoreC
return storeChannel
}
func (us SqlUserStore) GetSystemAdminProfiles(T goi18n.TranslateFunc) StoreChannel {
func (us SqlUserStore) GetSystemAdminProfiles() StoreChannel {
storeChannel := make(StoreChannel)
@@ -433,7 +431,7 @@ func (us SqlUserStore) GetSystemAdminProfiles(T goi18n.TranslateFunc) StoreChann
return storeChannel
}
func (us SqlUserStore) GetByEmail(T goi18n.TranslateFunc, teamId string, email string) StoreChannel {
func (us SqlUserStore) GetByEmail(teamId string, email string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -455,7 +453,7 @@ func (us SqlUserStore) GetByEmail(T goi18n.TranslateFunc, teamId string, email s
return storeChannel
}
func (us SqlUserStore) GetByAuth(T goi18n.TranslateFunc, teamId string, authData string, authService string) StoreChannel {
func (us SqlUserStore) GetByAuth(teamId string, authData string, authService string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -477,7 +475,7 @@ func (us SqlUserStore) GetByAuth(T goi18n.TranslateFunc, teamId string, authData
return storeChannel
}
func (us SqlUserStore) GetByUsername(T goi18n.TranslateFunc, teamId string, username string) StoreChannel {
func (us SqlUserStore) GetByUsername(teamId string, username string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -499,7 +497,7 @@ func (us SqlUserStore) GetByUsername(T goi18n.TranslateFunc, teamId string, user
return storeChannel
}
func (us SqlUserStore) VerifyEmail(T goi18n.TranslateFunc, userId string) StoreChannel {
func (us SqlUserStore) VerifyEmail(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -518,7 +516,7 @@ func (us SqlUserStore) VerifyEmail(T goi18n.TranslateFunc, userId string) StoreC
return storeChannel
}
func (us SqlUserStore) GetForExport(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (us SqlUserStore) GetForExport(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -545,7 +543,7 @@ func (us SqlUserStore) GetForExport(T goi18n.TranslateFunc, teamId string) Store
return storeChannel
}
func (us SqlUserStore) GetTotalUsersCount(T goi18n.TranslateFunc) StoreChannel {
func (us SqlUserStore) GetTotalUsersCount() StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -564,7 +562,7 @@ func (us SqlUserStore) GetTotalUsersCount(T goi18n.TranslateFunc) StoreChannel {
return storeChannel
}
func (us SqlUserStore) GetTotalActiveUsersCount(T goi18n.TranslateFunc) StoreChannel {
func (us SqlUserStore) GetTotalActiveUsersCount() StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -585,7 +583,7 @@ func (us SqlUserStore) GetTotalActiveUsersCount(T goi18n.TranslateFunc) StoreCha
return storeChannel
}
func (us SqlUserStore) PermanentDelete(T goi18n.TranslateFunc, userId string) StoreChannel {
func (us SqlUserStore) PermanentDelete(userId string) StoreChannel {
storeChannel := make(StoreChannel)

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"strings"
"testing"
"time"
@@ -19,27 +18,27 @@ func TestUserStoreSave(t *testing.T) {
u1.Username = model.NewId()
u1.TeamId = model.NewId()
if err := (<-store.User().Save(utils.T, &u1)).Err; err != nil {
if err := (<-store.User().Save(&u1)).Err; err != nil {
t.Fatal("couldn't save user", err)
}
if err := (<-store.User().Save(utils.T, &u1)).Err; err == nil {
if err := (<-store.User().Save(&u1)).Err; err == nil {
t.Fatal("shouldn't be able to update user from save")
}
u1.Id = ""
if err := (<-store.User().Save(utils.T, &u1)).Err; err == nil {
if err := (<-store.User().Save(&u1)).Err; err == nil {
t.Fatal("should be unique email")
}
u1.Email = ""
if err := (<-store.User().Save(utils.T, &u1)).Err; err == nil {
if err := (<-store.User().Save(&u1)).Err; err == nil {
t.Fatal("should be unique username")
}
u1.Email = strings.Repeat("0123456789", 20)
u1.Username = ""
if err := (<-store.User().Save(utils.T, &u1)).Err; err == nil {
if err := (<-store.User().Save(&u1)).Err; err == nil {
t.Fatal("should be unique username")
}
@@ -47,7 +46,7 @@ func TestUserStoreSave(t *testing.T) {
u1.Id = ""
u1.Email = model.NewId()
u1.Username = model.NewId()
if err := (<-store.User().Save(utils.T, &u1)).Err; err != nil {
if err := (<-store.User().Save(&u1)).Err; err != nil {
t.Fatal("couldn't save item", err)
}
}
@@ -55,7 +54,7 @@ func TestUserStoreSave(t *testing.T) {
u1.Id = ""
u1.Email = model.NewId()
u1.Username = model.NewId()
if err := (<-store.User().Save(utils.T, &u1)).Err; err == nil {
if err := (<-store.User().Save(&u1)).Err; err == nil {
t.Fatal("should be the limit", err)
}
}
@@ -66,21 +65,21 @@ func TestUserStoreUpdate(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
time.Sleep(100 * time.Millisecond)
if err := (<-store.User().Update(utils.T, &u1, false)).Err; err != nil {
if err := (<-store.User().Update(&u1, false)).Err; err != nil {
t.Fatal(err)
}
u1.Id = "missing"
if err := (<-store.User().Update(utils.T, &u1, false)).Err; err == nil {
if err := (<-store.User().Update(&u1, false)).Err; err == nil {
t.Fatal("Update should have failed because of missing key")
}
u1.Id = model.NewId()
if err := (<-store.User().Update(utils.T, &u1, false)).Err; err == nil {
if err := (<-store.User().Update(&u1, false)).Err; err == nil {
t.Fatal("Update should have faile because id change")
}
}
@@ -91,13 +90,13 @@ func TestUserStoreUpdateLastPingAt(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if err := (<-store.User().UpdateLastPingAt(utils.T, u1.Id, 1234567890)).Err; err != nil {
if err := (<-store.User().UpdateLastPingAt(u1.Id, 1234567890)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.User().Get(utils.T, u1.Id); r1.Err != nil {
if r1 := <-store.User().Get(u1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.User).LastPingAt != 1234567890 {
@@ -113,13 +112,13 @@ func TestUserStoreUpdateLastActivityAt(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if err := (<-store.User().UpdateLastActivityAt(utils.T, u1.Id, 1234567890)).Err; err != nil {
if err := (<-store.User().UpdateLastActivityAt(u1.Id, 1234567890)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.User().Get(utils.T, u1.Id); r1.Err != nil {
if r1 := <-store.User().Get(u1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.User).LastActivityAt != 1234567890 {
@@ -135,13 +134,13 @@ func TestUserStoreUpdateFailedPasswordAttempts(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if err := (<-store.User().UpdateFailedPasswordAttempts(utils.T, u1.Id, 3)).Err; err != nil {
if err := (<-store.User().UpdateFailedPasswordAttempts(u1.Id, 3)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.User().Get(utils.T, u1.Id); r1.Err != nil {
if r1 := <-store.User().Get(u1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.User).FailedAttempts != 3 {
@@ -157,18 +156,18 @@ func TestUserStoreUpdateUserAndSessionActivity(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
s1 := model.Session{}
s1.UserId = u1.Id
s1.TeamId = u1.TeamId
Must(store.Session().Save(utils.T, &s1))
Must(store.Session().Save(&s1))
if err := (<-store.User().UpdateUserAndSessionActivity(utils.T, u1.Id, s1.Id, 1234567890)).Err; err != nil {
if err := (<-store.User().UpdateUserAndSessionActivity(u1.Id, s1.Id, 1234567890)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.User().Get(utils.T, u1.Id); r1.Err != nil {
if r1 := <-store.User().Get(u1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.User).LastActivityAt != 1234567890 {
@@ -176,7 +175,7 @@ func TestUserStoreUpdateUserAndSessionActivity(t *testing.T) {
}
}
if r2 := <-store.Session().Get(utils.T, s1.Id); r2.Err != nil {
if r2 := <-store.Session().Get(s1.Id); r2.Err != nil {
t.Fatal(r2.Err)
} else {
if r2.Data.(*model.Session).LastActivityAt != 1234567890 {
@@ -192,9 +191,9 @@ func TestUserStoreGet(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if r1 := <-store.User().Get(utils.T, u1.Id); r1.Err != nil {
if r1 := <-store.User().Get(u1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.User).ToJson() != u1.ToJson() {
@@ -202,7 +201,7 @@ func TestUserStoreGet(t *testing.T) {
}
}
if err := (<-store.User().Get(utils.T, "")).Err; err == nil {
if err := (<-store.User().Get("")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
@@ -213,9 +212,9 @@ func TestUserCount(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if result := <-store.User().GetTotalUsersCount(utils.T); result.Err != nil {
if result := <-store.User().GetTotalUsersCount(); result.Err != nil {
t.Fatal(result.Err)
} else {
count := result.Data.(int64)
@@ -231,9 +230,9 @@ func TestActiveUserCount(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if result := <-store.User().GetTotalActiveUsersCount(utils.T); result.Err != nil {
if result := <-store.User().GetTotalActiveUsersCount(); result.Err != nil {
t.Fatal(result.Err)
} else {
count := result.Data.(int64)
@@ -249,14 +248,14 @@ func TestUserStoreGetProfiles(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
u2 := model.User{}
u2.TeamId = u1.TeamId
u2.Email = model.NewId()
Must(store.User().Save(utils.T, &u2))
Must(store.User().Save(&u2))
if r1 := <-store.User().GetProfiles(utils.T, u1.TeamId); r1.Err != nil {
if r1 := <-store.User().GetProfiles(u1.TeamId); r1.Err != nil {
t.Fatal(r1.Err)
} else {
users := r1.Data.(map[string]*model.User)
@@ -269,7 +268,7 @@ func TestUserStoreGetProfiles(t *testing.T) {
}
}
if r2 := <-store.User().GetProfiles(utils.T, "123"); r2.Err != nil {
if r2 := <-store.User().GetProfiles("123"); r2.Err != nil {
t.Fatal(r2.Err)
} else {
if len(r2.Data.(map[string]*model.User)) != 0 {
@@ -284,14 +283,14 @@ func TestUserStoreGetSystemAdminProfiles(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
u2 := model.User{}
u2.TeamId = u1.TeamId
u2.Email = model.NewId()
Must(store.User().Save(utils.T, &u2))
Must(store.User().Save(&u2))
if r1 := <-store.User().GetSystemAdminProfiles(utils.T); r1.Err != nil {
if r1 := <-store.User().GetSystemAdminProfiles(); r1.Err != nil {
t.Fatal(r1.Err)
} else {
users := r1.Data.(map[string]*model.User)
@@ -307,13 +306,13 @@ func TestUserStoreGetByEmail(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if err := (<-store.User().GetByEmail(utils.T, u1.TeamId, u1.Email)).Err; err != nil {
if err := (<-store.User().GetByEmail(u1.TeamId, u1.Email)).Err; err != nil {
t.Fatal(err)
}
if err := (<-store.User().GetByEmail(utils.T, "", "")).Err; err == nil {
if err := (<-store.User().GetByEmail("", "")).Err; err == nil {
t.Fatal("Should have failed because of missing email")
}
}
@@ -326,13 +325,13 @@ func TestUserStoreGetByAuthData(t *testing.T) {
u1.Email = model.NewId()
u1.AuthData = "123"
u1.AuthService = "service"
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if err := (<-store.User().GetByAuth(utils.T, u1.TeamId, u1.AuthData, u1.AuthService)).Err; err != nil {
if err := (<-store.User().GetByAuth(u1.TeamId, u1.AuthData, u1.AuthService)).Err; err != nil {
t.Fatal(err)
}
if err := (<-store.User().GetByAuth(utils.T, "", "", "")).Err; err == nil {
if err := (<-store.User().GetByAuth("", "", "")).Err; err == nil {
t.Fatal("Should have failed because of missing auth data")
}
}
@@ -344,13 +343,13 @@ func TestUserStoreGetByUsername(t *testing.T) {
u1.TeamId = model.NewId()
u1.Email = model.NewId()
u1.Username = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if err := (<-store.User().GetByUsername(utils.T, u1.TeamId, u1.Username)).Err; err != nil {
if err := (<-store.User().GetByUsername(u1.TeamId, u1.Username)).Err; err != nil {
t.Fatal(err)
}
if err := (<-store.User().GetByUsername(utils.T, "", "")).Err; err == nil {
if err := (<-store.User().GetByUsername("", "")).Err; err == nil {
t.Fatal("Should have failed because of missing username")
}
}
@@ -361,15 +360,15 @@ func TestUserStoreUpdatePassword(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
hashedPassword := model.HashPassword("newpwd")
if err := (<-store.User().UpdatePassword(utils.T, u1.Id, hashedPassword)).Err; err != nil {
if err := (<-store.User().UpdatePassword(u1.Id, hashedPassword)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.User().GetByEmail(utils.T, u1.TeamId, u1.Email); r1.Err != nil {
if r1 := <-store.User().GetByEmail(u1.TeamId, u1.Email); r1.Err != nil {
t.Fatal(r1.Err)
} else {
user := r1.Data.(*model.User)
@@ -385,9 +384,9 @@ func TestUserStoreDelete(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
if err := (<-store.User().PermanentDelete(utils.T, u1.Id)).Err; err != nil {
if err := (<-store.User().PermanentDelete(u1.Id)).Err; err != nil {
t.Fatal(err)
}
}
@@ -398,16 +397,16 @@ func TestUserStoreUpdateAuthData(t *testing.T) {
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
Must(store.User().Save(utils.T, &u1))
Must(store.User().Save(&u1))
service := "someservice"
authData := "1"
if err := (<-store.User().UpdateAuthData(utils.T, u1.Id, service, authData)).Err; err != nil {
if err := (<-store.User().UpdateAuthData(u1.Id, service, authData)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.User().GetByEmail(utils.T, u1.TeamId, u1.Email); r1.Err != nil {
if r1 := <-store.User().GetByEmail(u1.TeamId, u1.Email); r1.Err != nil {
t.Fatal(r1.Err)
} else {
user := r1.Data.(*model.User)

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlWebhookStore struct {
@@ -44,7 +43,7 @@ func (s SqlWebhookStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_outgoing_webhook_team_id", "OutgoingWebhooks", "TeamId")
}
func (s SqlWebhookStore) SaveIncoming(T goi18n.TranslateFunc, webhook *model.IncomingWebhook) StoreChannel {
func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -78,7 +77,7 @@ func (s SqlWebhookStore) SaveIncoming(T goi18n.TranslateFunc, webhook *model.Inc
return storeChannel
}
func (s SqlWebhookStore) GetIncoming(T goi18n.TranslateFunc, id string) StoreChannel {
func (s SqlWebhookStore) GetIncoming(id string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -99,7 +98,7 @@ func (s SqlWebhookStore) GetIncoming(T goi18n.TranslateFunc, id string) StoreCha
return storeChannel
}
func (s SqlWebhookStore) DeleteIncoming(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel {
func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -117,7 +116,7 @@ func (s SqlWebhookStore) DeleteIncoming(T goi18n.TranslateFunc, webhookId string
return storeChannel
}
func (s SqlWebhookStore) PermanentDeleteIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -135,7 +134,7 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByUser(T goi18n.TranslateFunc, u
return storeChannel
}
func (s SqlWebhookStore) GetIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlWebhookStore) GetIncomingByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -156,7 +155,7 @@ func (s SqlWebhookStore) GetIncomingByUser(T goi18n.TranslateFunc, userId string
return storeChannel
}
func (s SqlWebhookStore) GetIncomingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel {
func (s SqlWebhookStore) GetIncomingByChannel(channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -177,7 +176,7 @@ func (s SqlWebhookStore) GetIncomingByChannel(T goi18n.TranslateFunc, channelId
return storeChannel
}
func (s SqlWebhookStore) SaveOutgoing(T goi18n.TranslateFunc, webhook *model.OutgoingWebhook) StoreChannel {
func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -211,7 +210,7 @@ func (s SqlWebhookStore) SaveOutgoing(T goi18n.TranslateFunc, webhook *model.Out
return storeChannel
}
func (s SqlWebhookStore) GetOutgoing(T goi18n.TranslateFunc, id string) StoreChannel {
func (s SqlWebhookStore) GetOutgoing(id string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -232,7 +231,7 @@ func (s SqlWebhookStore) GetOutgoing(T goi18n.TranslateFunc, id string) StoreCha
return storeChannel
}
func (s SqlWebhookStore) GetOutgoingByCreator(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlWebhookStore) GetOutgoingByCreator(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -253,7 +252,7 @@ func (s SqlWebhookStore) GetOutgoingByCreator(T goi18n.TranslateFunc, userId str
return storeChannel
}
func (s SqlWebhookStore) GetOutgoingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel {
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -274,7 +273,7 @@ func (s SqlWebhookStore) GetOutgoingByChannel(T goi18n.TranslateFunc, channelId
return storeChannel
}
func (s SqlWebhookStore) GetOutgoingByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel {
func (s SqlWebhookStore) GetOutgoingByTeam(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -295,7 +294,7 @@ func (s SqlWebhookStore) GetOutgoingByTeam(T goi18n.TranslateFunc, teamId string
return storeChannel
}
func (s SqlWebhookStore) DeleteOutgoing(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel {
func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -313,7 +312,7 @@ func (s SqlWebhookStore) DeleteOutgoing(T goi18n.TranslateFunc, webhookId string
return storeChannel
}
func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -331,7 +330,7 @@ func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(T goi18n.TranslateFunc, u
return storeChannel
}
func (s SqlWebhookStore) UpdateOutgoing(T goi18n.TranslateFunc, hook *model.OutgoingWebhook) StoreChannel {
func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

View File

@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing"
)
@@ -17,11 +16,11 @@ func TestWebhookStoreSaveIncoming(t *testing.T) {
o1.UserId = model.NewId()
o1.TeamId = model.NewId()
if err := (<-store.Webhook().SaveIncoming(utils.T, &o1)).Err; err != nil {
if err := (<-store.Webhook().SaveIncoming(&o1)).Err; err != nil {
t.Fatal("couldn't save item", err)
}
if err := (<-store.Webhook().SaveIncoming(utils.T, &o1)).Err; err == nil {
if err := (<-store.Webhook().SaveIncoming(&o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
}
@@ -34,9 +33,9 @@ func TestWebhookStoreGetIncoming(t *testing.T) {
o1.UserId = model.NewId()
o1.TeamId = model.NewId()
o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook)
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
if r1 := <-store.Webhook().GetIncoming(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt {
@@ -44,7 +43,7 @@ func TestWebhookStoreGetIncoming(t *testing.T) {
}
}
if err := (<-store.Webhook().GetIncoming(utils.T, "123")).Err; err == nil {
if err := (<-store.Webhook().GetIncoming("123")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
@@ -57,9 +56,9 @@ func TestWebhookStoreGetIncomingByUser(t *testing.T) {
o1.UserId = model.NewId()
o1.TeamId = model.NewId()
o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook)
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
if r1 := <-store.Webhook().GetIncomingByUser(utils.T, o1.UserId); r1.Err != nil {
if r1 := <-store.Webhook().GetIncomingByUser(o1.UserId); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.([]*model.IncomingWebhook)[0].CreateAt != o1.CreateAt {
@@ -67,7 +66,7 @@ func TestWebhookStoreGetIncomingByUser(t *testing.T) {
}
}
if result := <-store.Webhook().GetIncomingByUser(utils.T, "123"); result.Err != nil {
if result := <-store.Webhook().GetIncomingByUser("123"); result.Err != nil {
t.Fatal(result.Err)
} else {
if len(result.Data.([]*model.IncomingWebhook)) != 0 {
@@ -84,9 +83,9 @@ func TestWebhookStoreDeleteIncoming(t *testing.T) {
o1.UserId = model.NewId()
o1.TeamId = model.NewId()
o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook)
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
if r1 := <-store.Webhook().GetIncoming(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt {
@@ -94,11 +93,11 @@ func TestWebhookStoreDeleteIncoming(t *testing.T) {
}
}
if r2 := <-store.Webhook().DeleteIncoming(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
if r2 := <-store.Webhook().DeleteIncoming(o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Webhook().GetIncoming(utils.T, o1.Id)); r3.Err == nil {
if r3 := (<-store.Webhook().GetIncoming(o1.Id)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
}
@@ -112,9 +111,9 @@ func TestWebhookStoreDeleteIncomingByUser(t *testing.T) {
o1.UserId = model.NewId()
o1.TeamId = model.NewId()
o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook)
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
if r1 := <-store.Webhook().GetIncoming(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt {
@@ -122,11 +121,11 @@ func TestWebhookStoreDeleteIncomingByUser(t *testing.T) {
}
}
if r2 := <-store.Webhook().PermanentDeleteIncomingByUser(utils.T, o1.UserId); r2.Err != nil {
if r2 := <-store.Webhook().PermanentDeleteIncomingByUser(o1.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Webhook().GetIncoming(utils.T, o1.Id)); r3.Err == nil {
if r3 := (<-store.Webhook().GetIncoming(o1.Id)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
}
@@ -141,11 +140,11 @@ func TestWebhookStoreSaveOutgoing(t *testing.T) {
o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"}
if err := (<-store.Webhook().SaveOutgoing(utils.T, &o1)).Err; err != nil {
if err := (<-store.Webhook().SaveOutgoing(&o1)).Err; err != nil {
t.Fatal("couldn't save item", err)
}
if err := (<-store.Webhook().SaveOutgoing(utils.T, &o1)).Err; err == nil {
if err := (<-store.Webhook().SaveOutgoing(&o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
}
@@ -159,9 +158,9 @@ func TestWebhookStoreGetOutgoing(t *testing.T) {
o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoing(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
@@ -169,7 +168,7 @@ func TestWebhookStoreGetOutgoing(t *testing.T) {
}
}
if err := (<-store.Webhook().GetOutgoing(utils.T, "123")).Err; err == nil {
if err := (<-store.Webhook().GetOutgoing("123")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
@@ -183,9 +182,9 @@ func TestWebhookStoreGetOutgoingByChannel(t *testing.T) {
o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoingByChannel(utils.T, o1.ChannelId); r1.Err != nil {
if r1 := <-store.Webhook().GetOutgoingByChannel(o1.ChannelId); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
@@ -193,7 +192,7 @@ func TestWebhookStoreGetOutgoingByChannel(t *testing.T) {
}
}
if result := <-store.Webhook().GetOutgoingByChannel(utils.T, "123"); result.Err != nil {
if result := <-store.Webhook().GetOutgoingByChannel("123"); result.Err != nil {
t.Fatal(result.Err)
} else {
if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
@@ -211,9 +210,9 @@ func TestWebhookStoreGetOutgoingByCreator(t *testing.T) {
o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoingByCreator(utils.T, o1.CreatorId); r1.Err != nil {
if r1 := <-store.Webhook().GetOutgoingByCreator(o1.CreatorId); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
@@ -221,7 +220,7 @@ func TestWebhookStoreGetOutgoingByCreator(t *testing.T) {
}
}
if result := <-store.Webhook().GetOutgoingByCreator(utils.T, "123"); result.Err != nil {
if result := <-store.Webhook().GetOutgoingByCreator("123"); result.Err != nil {
t.Fatal(result.Err)
} else {
if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
@@ -239,9 +238,9 @@ func TestWebhookStoreGetOutgoingByTeam(t *testing.T) {
o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoingByTeam(utils.T, o1.TeamId); r1.Err != nil {
if r1 := <-store.Webhook().GetOutgoingByTeam(o1.TeamId); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
@@ -249,7 +248,7 @@ func TestWebhookStoreGetOutgoingByTeam(t *testing.T) {
}
}
if result := <-store.Webhook().GetOutgoingByTeam(utils.T, "123"); result.Err != nil {
if result := <-store.Webhook().GetOutgoingByTeam("123"); result.Err != nil {
t.Fatal(result.Err)
} else {
if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
@@ -267,9 +266,9 @@ func TestWebhookStoreDeleteOutgoing(t *testing.T) {
o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoing(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
@@ -277,11 +276,11 @@ func TestWebhookStoreDeleteOutgoing(t *testing.T) {
}
}
if r2 := <-store.Webhook().DeleteOutgoing(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
if r2 := <-store.Webhook().DeleteOutgoing(o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Webhook().GetOutgoing(utils.T, o1.Id)); r3.Err == nil {
if r3 := (<-store.Webhook().GetOutgoing(o1.Id)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
}
@@ -296,9 +295,9 @@ func TestWebhookStoreDeleteOutgoingByUser(t *testing.T) {
o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoing(utils.T, o1.Id); r1.Err != nil {
if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
@@ -306,11 +305,11 @@ func TestWebhookStoreDeleteOutgoingByUser(t *testing.T) {
}
}
if r2 := <-store.Webhook().PermanentDeleteOutgoingByUser(utils.T, o1.CreatorId); r2.Err != nil {
if r2 := <-store.Webhook().PermanentDeleteOutgoingByUser(o1.CreatorId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Webhook().GetOutgoing(utils.T, o1.Id)); r3.Err == nil {
if r3 := (<-store.Webhook().GetOutgoing(o1.Id)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
}
@@ -325,11 +324,11 @@ func TestWebhookStoreUpdateOutgoing(t *testing.T) {
o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
o1.Token = model.NewId()
if r2 := <-store.Webhook().UpdateOutgoing(utils.T, o1); r2.Err != nil {
if r2 := <-store.Webhook().UpdateOutgoing(o1); r2.Err != nil {
t.Fatal(r2.Err)
}
}

View File

@@ -4,11 +4,9 @@
package store
import (
"time"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
"time"
)
type StoreResult struct {
@@ -45,150 +43,150 @@ type Store interface {
}
type TeamStore interface {
Save(T goi18n.TranslateFunc, team *model.Team) StoreChannel
Update(T goi18n.TranslateFunc, team *model.Team) StoreChannel
UpdateDisplayName(T goi18n.TranslateFunc, name string, teamId string) StoreChannel
Get(T goi18n.TranslateFunc, id string) StoreChannel
GetByName(T goi18n.TranslateFunc, name string) StoreChannel
GetTeamsForEmail(T goi18n.TranslateFunc, domain string) StoreChannel
GetAll(T goi18n.TranslateFunc) StoreChannel
GetAllTeamListing(T goi18n.TranslateFunc) StoreChannel
GetByInviteId(T goi18n.TranslateFunc, inviteId string) StoreChannel
PermanentDelete(T goi18n.TranslateFunc, teamId string) StoreChannel
Save(team *model.Team) StoreChannel
Update(team *model.Team) StoreChannel
UpdateDisplayName(name string, teamId string) StoreChannel
Get(id string) StoreChannel
GetByName(name string) StoreChannel
GetTeamsForEmail(domain string) StoreChannel
GetAll() StoreChannel
GetAllTeamListing() StoreChannel
GetByInviteId(inviteId string) StoreChannel
PermanentDelete(teamId string) StoreChannel
}
type ChannelStore interface {
Save(T goi18n.TranslateFunc, channel *model.Channel) StoreChannel
SaveDirectChannel(T goi18n.TranslateFunc, channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
Update(T goi18n.TranslateFunc, channel *model.Channel) StoreChannel
Get(T goi18n.TranslateFunc, id string) StoreChannel
GetFromMaster(T goi18n.TranslateFunc, id string) StoreChannel
Delete(T goi18n.TranslateFunc, channelId string, time int64) StoreChannel
PermanentDeleteByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel
GetByName(T goi18n.TranslateFunc, team_id string, domain string) StoreChannel
GetChannels(T goi18n.TranslateFunc, teamId string, userId string) StoreChannel
GetMoreChannels(T goi18n.TranslateFunc, teamId string, userId string) StoreChannel
GetChannelCounts(T goi18n.TranslateFunc, teamId string, userId string) StoreChannel
GetForExport(T goi18n.TranslateFunc, teamId string) StoreChannel
Save(channel *model.Channel) StoreChannel
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
Update(channel *model.Channel) StoreChannel
Get(id string) StoreChannel
GetFromMaster(id string) StoreChannel
Delete(channelId string, time int64) StoreChannel
PermanentDeleteByTeam(teamId string) StoreChannel
GetByName(team_id string, domain string) StoreChannel
GetChannels(teamId string, userId string) StoreChannel
GetMoreChannels(teamId string, userId string) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
GetForExport(teamId string) StoreChannel
SaveMember(T goi18n.TranslateFunc, member *model.ChannelMember) StoreChannel
UpdateMember(T goi18n.TranslateFunc, member *model.ChannelMember) StoreChannel
GetMembers(T goi18n.TranslateFunc, channelId string) StoreChannel
GetMember(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel
GetMemberCount(T goi18n.TranslateFunc, channelId string) StoreChannel
RemoveMember(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel
PermanentDeleteMembersByUser(T goi18n.TranslateFunc, userId string) StoreChannel
GetExtraMembers(T goi18n.TranslateFunc, channelId string, limit int) StoreChannel
CheckPermissionsTo(T goi18n.TranslateFunc, teamId string, channelId string, userId string) StoreChannel
CheckOpenChannelPermissions(T goi18n.TranslateFunc, teamId string, channelId string) StoreChannel
CheckPermissionsToByName(T goi18n.TranslateFunc, teamId string, channelName string, userId string) StoreChannel
UpdateLastViewedAt(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel
IncrementMentionCount(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel
AnalyticsTypeCount(T goi18n.TranslateFunc, teamId string, channelType string) StoreChannel
SaveMember(member *model.ChannelMember) StoreChannel
UpdateMember(member *model.ChannelMember) StoreChannel
GetMembers(channelId string) StoreChannel
GetMember(channelId string, userId string) StoreChannel
GetMemberCount(channelId string) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
PermanentDeleteMembersByUser(userId string) StoreChannel
GetExtraMembers(channelId string, limit int) StoreChannel
CheckPermissionsTo(teamId string, channelId string, userId string) StoreChannel
CheckOpenChannelPermissions(teamId string, channelId string) StoreChannel
CheckPermissionsToByName(teamId string, channelName string, userId string) StoreChannel
UpdateLastViewedAt(channelId string, userId string) StoreChannel
IncrementMentionCount(channelId string, userId string) StoreChannel
AnalyticsTypeCount(teamId string, channelType string) StoreChannel
}
type PostStore interface {
Save(T goi18n.TranslateFunc, post *model.Post) StoreChannel
Update(T goi18n.TranslateFunc, post *model.Post, newMessage string, newHashtags string) StoreChannel
Get(T goi18n.TranslateFunc, id string) StoreChannel
Delete(T goi18n.TranslateFunc, postId string, time int64) StoreChannel
PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel
GetPosts(T goi18n.TranslateFunc, channelId string, offset int, limit int) StoreChannel
GetPostsBefore(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsAfter(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsSince(T goi18n.TranslateFunc, channelId string, time int64) StoreChannel
GetEtag(T goi18n.TranslateFunc, channelId string) StoreChannel
Search(T goi18n.TranslateFunc, teamId string, userId string, params *model.SearchParams) StoreChannel
GetForExport(T goi18n.TranslateFunc, channelId string) StoreChannel
AnalyticsUserCountsWithPostsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel
AnalyticsPostCountsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel
AnalyticsPostCount(T goi18n.TranslateFunc, teamId string) StoreChannel
Save(post *model.Post) StoreChannel
Update(post *model.Post, newMessage string, newHashtags string) StoreChannel
Get(id string) StoreChannel
Delete(postId string, time int64) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
GetPosts(channelId string, offset int, limit int) StoreChannel
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsSince(channelId string, time int64) StoreChannel
GetEtag(channelId string) StoreChannel
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
GetForExport(channelId string) StoreChannel
AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel
AnalyticsPostCountsByDay(teamId string) StoreChannel
AnalyticsPostCount(teamId string) StoreChannel
}
type UserStore interface {
Save(T goi18n.TranslateFunc, user *model.User) StoreChannel
Update(T goi18n.TranslateFunc, user *model.User, allowRoleUpdate bool) StoreChannel
UpdateLastPictureUpdate(T goi18n.TranslateFunc, userId string) StoreChannel
UpdateLastPingAt(T goi18n.TranslateFunc, userId string, time int64) StoreChannel
UpdateLastActivityAt(T goi18n.TranslateFunc, userId string, time int64) StoreChannel
UpdateUserAndSessionActivity(T goi18n.TranslateFunc, userId string, sessionId string, time int64) StoreChannel
UpdatePassword(T goi18n.TranslateFunc, userId, newPassword string) StoreChannel
UpdateAuthData(T goi18n.TranslateFunc, userId, service, authData string) StoreChannel
Get(T goi18n.TranslateFunc, id string) StoreChannel
GetProfiles(T goi18n.TranslateFunc, teamId string) StoreChannel
GetByEmail(T goi18n.TranslateFunc, teamId string, email string) StoreChannel
GetByAuth(T goi18n.TranslateFunc, teamId string, authData string, authService string) StoreChannel
GetByUsername(T goi18n.TranslateFunc, teamId string, username string) StoreChannel
VerifyEmail(T goi18n.TranslateFunc, userId string) StoreChannel
GetEtagForProfiles(T goi18n.TranslateFunc, teamId string) StoreChannel
UpdateFailedPasswordAttempts(T goi18n.TranslateFunc, userId string, attempts int) StoreChannel
GetForExport(T goi18n.TranslateFunc, teamId string) StoreChannel
GetTotalUsersCount(T goi18n.TranslateFunc) StoreChannel
GetTotalActiveUsersCount(T goi18n.TranslateFunc) StoreChannel
GetSystemAdminProfiles(T goi18n.TranslateFunc) StoreChannel
PermanentDelete(T goi18n.TranslateFunc, userId string) StoreChannel
Save(user *model.User) StoreChannel
Update(user *model.User, allowRoleUpdate bool) StoreChannel
UpdateLastPictureUpdate(userId string) StoreChannel
UpdateLastPingAt(userId string, time int64) StoreChannel
UpdateLastActivityAt(userId string, time int64) StoreChannel
UpdateUserAndSessionActivity(userId string, sessionId string, time int64) StoreChannel
UpdatePassword(userId, newPassword string) StoreChannel
UpdateAuthData(userId, service, authData string) StoreChannel
Get(id string) StoreChannel
GetProfiles(teamId string) StoreChannel
GetByEmail(teamId string, email string) StoreChannel
GetByAuth(teamId string, authData string, authService string) StoreChannel
GetByUsername(teamId string, username string) StoreChannel
VerifyEmail(userId string) StoreChannel
GetEtagForProfiles(teamId string) StoreChannel
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
GetForExport(teamId string) StoreChannel
GetTotalUsersCount() StoreChannel
GetTotalActiveUsersCount() StoreChannel
GetSystemAdminProfiles() StoreChannel
PermanentDelete(userId string) StoreChannel
}
type SessionStore interface {
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
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
}
type AuditStore interface {
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
Save(audit *model.Audit) StoreChannel
Get(user_id string, limit int) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
}
type OAuthStore interface {
SaveApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel
UpdateApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel
GetApp(T goi18n.TranslateFunc, id string) StoreChannel
GetAppByUser(T goi18n.TranslateFunc, userId string) StoreChannel
SaveAuthData(T goi18n.TranslateFunc, authData *model.AuthData) StoreChannel
GetAuthData(T goi18n.TranslateFunc, code string) StoreChannel
RemoveAuthData(T goi18n.TranslateFunc, code string) StoreChannel
PermanentDeleteAuthDataByUser(T goi18n.TranslateFunc, userId string) StoreChannel
SaveAccessData(T goi18n.TranslateFunc, accessData *model.AccessData) StoreChannel
GetAccessData(T goi18n.TranslateFunc, token string) StoreChannel
GetAccessDataByAuthCode(T goi18n.TranslateFunc, authCode string) StoreChannel
RemoveAccessData(T goi18n.TranslateFunc, token string) StoreChannel
SaveApp(app *model.OAuthApp) StoreChannel
UpdateApp(app *model.OAuthApp) StoreChannel
GetApp(id string) StoreChannel
GetAppByUser(userId string) StoreChannel
SaveAuthData(authData *model.AuthData) StoreChannel
GetAuthData(code string) StoreChannel
RemoveAuthData(code string) StoreChannel
PermanentDeleteAuthDataByUser(userId string) StoreChannel
SaveAccessData(accessData *model.AccessData) StoreChannel
GetAccessData(token string) StoreChannel
GetAccessDataByAuthCode(authCode string) StoreChannel
RemoveAccessData(token string) StoreChannel
}
type SystemStore interface {
Save(T goi18n.TranslateFunc, system *model.System) StoreChannel
Update(T goi18n.TranslateFunc, system *model.System) StoreChannel
Get(T goi18n.TranslateFunc) StoreChannel
Save(system *model.System) StoreChannel
Update(system *model.System) StoreChannel
Get() StoreChannel
}
type WebhookStore interface {
SaveIncoming(T goi18n.TranslateFunc, webhook *model.IncomingWebhook) StoreChannel
GetIncoming(T goi18n.TranslateFunc, id string) StoreChannel
GetIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel
GetIncomingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel
DeleteIncoming(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel
PermanentDeleteIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel
SaveOutgoing(T goi18n.TranslateFunc, webhook *model.OutgoingWebhook) StoreChannel
GetOutgoing(T goi18n.TranslateFunc, id string) StoreChannel
GetOutgoingByCreator(T goi18n.TranslateFunc, userId string) StoreChannel
GetOutgoingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel
GetOutgoingByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel
DeleteOutgoing(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel
PermanentDeleteOutgoingByUser(T goi18n.TranslateFunc, userId string) StoreChannel
UpdateOutgoing(T goi18n.TranslateFunc, hook *model.OutgoingWebhook) StoreChannel
SaveIncoming(webhook *model.IncomingWebhook) StoreChannel
GetIncoming(id string) StoreChannel
GetIncomingByUser(userId string) StoreChannel
GetIncomingByChannel(channelId string) StoreChannel
DeleteIncoming(webhookId string, time int64) StoreChannel
PermanentDeleteIncomingByUser(userId string) StoreChannel
SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel
GetOutgoing(id string) StoreChannel
GetOutgoingByCreator(userId string) StoreChannel
GetOutgoingByChannel(channelId string) StoreChannel
GetOutgoingByTeam(teamId string) StoreChannel
DeleteOutgoing(webhookId string, time int64) StoreChannel
PermanentDeleteOutgoingByUser(userId string) StoreChannel
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
}
type PreferenceStore interface {
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
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
}

View File

@@ -5,12 +5,6 @@ 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"
@@ -19,6 +13,11 @@ 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
@@ -167,7 +166,7 @@ func root(c *api.Context, w http.ResponseWriter, r *http.Request) {
if len(c.Session.UserId) == 0 {
page := NewHtmlTemplatePage("signup_team", "Signup")
if result := <-api.Srv.Store.Team().GetAllTeamListing(c.T); result.Err != nil {
if result := <-api.Srv.Store.Team().GetAllTeamListing(); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -184,8 +183,8 @@ func root(c *api.Context, w http.ResponseWriter, r *http.Request) {
page.Render(c, w)
} else {
teamChan := api.Srv.Store.Team().Get(c.T, c.Session.TeamId)
userChan := api.Srv.Store.User().Get(c.T, c.Session.UserId)
teamChan := api.Srv.Store.Team().Get(c.Session.TeamId)
userChan := api.Srv.Store.User().Get(c.Session.UserId)
var team *model.Team
if tr := <-teamChan; tr.Err != nil {
@@ -229,7 +228,7 @@ func login(c *api.Context, w http.ResponseWriter, r *http.Request) {
teamName := params["team"]
var team *model.Team
if tResult := <-api.Srv.Store.Team().GetByName(c.T, teamName); tResult.Err != nil {
if tResult := <-api.Srv.Store.Team().GetByName(teamName); tResult.Err != nil {
l4g.Error("Couldn't find team name=%v, err=%v", teamName, tResult.Err.Message)
http.Redirect(w, r, api.GetProtocol(r)+"://"+r.Host, http.StatusTemporaryRedirect)
return
@@ -238,12 +237,12 @@ func login(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
// We still might be able to switch to this team because we've logged in before
_, session := api.FindMultiSessionForTeamId(c.T, r, team.Id)
_, session := api.FindMultiSessionForTeamId(r, team.Id)
if session != nil {
w.Header().Set(model.HEADER_TOKEN, session.Token)
lastViewChannelName := "town-square"
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(c.T, lastViewResult.Data.(model.Preference).Value); lastViewChannelResult.Err == nil {
if lastViewResult := <-api.Srv.Store.Preference().Get(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
}
}
@@ -305,7 +304,7 @@ func signupUserComplete(c *api.Context, w http.ResponseWriter, r *http.Request)
if len(id) > 0 {
props = make(map[string]string)
if result := <-api.Srv.Store.Team().GetByInviteId(c.T, id); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByInviteId(id); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -370,7 +369,7 @@ func postPermalink(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
var post *model.Post
if result := <-api.Srv.Store.Post().Get(c.T, postId); result.Err != nil {
if result := <-api.Srv.Store.Post().Get(postId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -379,7 +378,7 @@ func postPermalink(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
var channel *model.Channel
if result := <-api.Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId); result.Err != nil {
if result := <-api.Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -389,7 +388,7 @@ func postPermalink(c *api.Context, w http.ResponseWriter, r *http.Request) {
return
}
} else {
if result := <-api.Srv.Store.Channel().Get(c.T, post.ChannelId); result.Err != nil {
if result := <-api.Srv.Store.Channel().Get(post.ChannelId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -413,7 +412,7 @@ func getChannel(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
var channel *model.Channel
if result := <-api.Srv.Store.Channel().CheckPermissionsToByName(c.T, c.Session.TeamId, name, c.Session.UserId); result.Err != nil {
if result := <-api.Srv.Store.Channel().CheckPermissionsToByName(c.Session.TeamId, name, c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -424,7 +423,7 @@ func getChannel(c *api.Context, w http.ResponseWriter, r *http.Request) {
return
}
} else {
if result := <-api.Srv.Store.Channel().Get(c.T, channelId); result.Err != nil {
if result := <-api.Srv.Store.Channel().Get(channelId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -455,14 +454,14 @@ func autoJoinChannelName(c *api.Context, w http.ResponseWriter, r *http.Request,
}
} else {
// We will attempt to auto-join open channels
return joinOpenChannel(c, w, r, api.Srv.Store.Channel().GetByName(c.T, c.Session.TeamId, channelName))
return joinOpenChannel(c, w, r, api.Srv.Store.Channel().GetByName(c.Session.TeamId, channelName))
}
return nil
}
func autoJoinChannelId(c *api.Context, w http.ResponseWriter, r *http.Request, channelId string) *model.Channel {
return joinOpenChannel(c, w, r, api.Srv.Store.Channel().Get(c.T, channelId))
return joinOpenChannel(c, w, r, api.Srv.Store.Channel().Get(channelId))
}
func joinOpenChannel(c *api.Context, w http.ResponseWriter, r *http.Request, channel store.StoreChannel) *model.Channel {
@@ -486,7 +485,7 @@ func joinOpenChannel(c *api.Context, w http.ResponseWriter, r *http.Request, cha
func checkSessionSwitch(c *api.Context, w http.ResponseWriter, r *http.Request, teamName string) *model.Team {
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(c.T, teamName); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByName(teamName); result.Err != nil {
c.Err = result.Err
return nil
} else {
@@ -496,7 +495,7 @@ func checkSessionSwitch(c *api.Context, w http.ResponseWriter, r *http.Request,
// We are logged into a different team. Lets see if we have another
// session in the cookie that will give us access.
if c.Session.TeamId != team.Id {
index, session := api.FindMultiSessionForTeamId(c.T, r, team.Id)
index, session := api.FindMultiSessionForTeamId(r, team.Id)
if session == nil {
// redirect to login
http.Redirect(w, r, c.GetSiteURL()+"/"+team.Name+"/?redirect="+url.QueryEscape(r.URL.Path), http.StatusTemporaryRedirect)
@@ -510,7 +509,7 @@ func checkSessionSwitch(c *api.Context, w http.ResponseWriter, r *http.Request,
}
func doLoadChannel(c *api.Context, w http.ResponseWriter, r *http.Request, team *model.Team, channel *model.Channel, postid string) {
userChan := api.Srv.Store.User().Get(c.T, c.Session.UserId)
userChan := api.Srv.Store.User().Get(c.Session.UserId)
var user *model.User
if ur := <-userChan; ur.Err != nil {
@@ -543,7 +542,7 @@ func verifyEmail(c *api.Context, w http.ResponseWriter, r *http.Request) {
userId := r.URL.Query().Get("uid")
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(c.T, name); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByName(name); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -551,7 +550,7 @@ func verifyEmail(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
if resend == "true" {
if result := <-api.Srv.Store.User().GetByEmail(c.T, team.Id, email); result.Err != nil {
if result := <-api.Srv.Store.User().GetByEmail(team.Id, email); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -570,7 +569,7 @@ func verifyEmail(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
if len(userId) == 26 && len(hashedId) != 0 && model.ComparePassword(hashedId, userId) {
if c.Err = (<-api.Srv.Store.User().VerifyEmail(c.T, userId)).Err; c.Err != nil {
if c.Err = (<-api.Srv.Store.User().VerifyEmail(userId)).Err; c.Err != nil {
return
} else {
c.LogAudit("Email Verified")
@@ -626,7 +625,7 @@ func resetPassword(c *api.Context, w http.ResponseWriter, r *http.Request) {
teamDisplayName := "Developer/Beta"
var team *model.Team
if tResult := <-api.Srv.Store.Team().GetByName(c.T, teamName); tResult.Err != nil {
if tResult := <-api.Srv.Store.Team().GetByName(teamName); tResult.Err != nil {
c.Err = tResult.Err
return
} else {
@@ -668,7 +667,7 @@ func signupWithOAuth(c *api.Context, w http.ResponseWriter, r *http.Request) {
hash := r.URL.Query().Get("h")
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(c.T, teamName); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByName(teamName); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -716,7 +715,7 @@ func completeOAuth(c *api.Context, w http.ResponseWriter, r *http.Request) {
uri := c.GetSiteURL() + "/signup/" + service + "/complete" // Remove /signup after a few releases (~1.8)
if body, team, props, err := api.AuthorizeOAuthUser(c.T, service, code, state, uri); err != nil {
if body, team, props, err := api.AuthorizeOAuthUser(service, code, state, uri); err != nil {
c.Err = err
return
} else {
@@ -769,7 +768,7 @@ func loginWithOAuth(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
// Make sure team exists
if result := <-api.Srv.Store.Team().GetByName(c.T, teamName); result.Err != nil {
if result := <-api.Srv.Store.Team().GetByName(teamName); result.Err != nil {
c.Err = result.Err
return
}
@@ -791,8 +790,8 @@ func adminConsole(c *api.Context, w http.ResponseWriter, r *http.Request) {
return
}
teamChan := api.Srv.Store.Team().Get(c.T, c.Session.TeamId)
userChan := api.Srv.Store.User().Get(c.T, c.Session.UserId)
teamChan := api.Srv.Store.Team().Get(c.Session.TeamId)
userChan := api.Srv.Store.User().Get(c.Session.UserId)
var team *model.Team
if tr := <-teamChan; tr.Err != nil {
@@ -846,7 +845,7 @@ func authorizeOAuth(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
var app *model.OAuthApp
if result := <-api.Srv.Store.OAuth().GetApp(c.T, clientId); result.Err != nil {
if result := <-api.Srv.Store.OAuth().GetApp(clientId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -854,7 +853,7 @@ func authorizeOAuth(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
var team *model.Team
if result := <-api.Srv.Store.Team().Get(c.T, c.Session.TeamId); result.Err != nil {
if result := <-api.Srv.Store.Team().Get(c.Session.TeamId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -909,10 +908,10 @@ func getAccessToken(c *api.Context, w http.ResponseWriter, r *http.Request) {
redirectUri := r.FormValue("redirect_uri")
achan := api.Srv.Store.OAuth().GetApp(c.T, clientId)
tchan := api.Srv.Store.OAuth().GetAccessDataByAuthCode(c.T, code)
achan := api.Srv.Store.OAuth().GetApp(clientId)
tchan := api.Srv.Store.OAuth().GetAccessDataByAuthCode(code)
authData := api.GetAuthData(c.T, code)
authData := api.GetAuthData(code)
if authData == nil {
c.LogAudit("fail - invalid auth code")
@@ -920,7 +919,7 @@ func getAccessToken(c *api.Context, w http.ResponseWriter, r *http.Request) {
return
}
uchan := api.Srv.Store.User().Get(c.T, authData.UserId)
uchan := api.Srv.Store.User().Get(authData.UserId)
if authData.IsExpired() {
c.LogAudit("fail - auth code expired")
@@ -967,7 +966,7 @@ func getAccessToken(c *api.Context, w http.ResponseWriter, r *http.Request) {
accessData := result.Data.(*model.AccessData)
// Revoke access token, related auth code, and session from DB as well as from cache
if err := api.RevokeAccessToken(c.T, accessData.Token); err != nil {
if err := api.RevokeAccessToken(accessData.Token); err != nil {
l4g.Error("Encountered an error revoking an access token, err=" + err.Message)
}
@@ -985,7 +984,7 @@ func getAccessToken(c *api.Context, w http.ResponseWriter, r *http.Request) {
session := &model.Session{UserId: user.Id, TeamId: user.TeamId, Roles: user.Roles, IsOAuth: true}
if result := <-api.Srv.Store.Session().Save(c.T, session); result.Err != nil {
if result := <-api.Srv.Store.Session().Save(session); result.Err != nil {
c.Err = model.NewAppError("getAccessToken", "server_error: Encountered internal server error while saving session to database", "")
return
} else {
@@ -995,7 +994,7 @@ func getAccessToken(c *api.Context, w http.ResponseWriter, r *http.Request) {
accessData := &model.AccessData{AuthCode: authData.Code, Token: session.Token, RedirectUri: callback}
if result := <-api.Srv.Store.OAuth().SaveAccessData(c.T, accessData); result.Err != nil {
if result := <-api.Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
l4g.Error(result.Err)
c.Err = model.NewAppError("getAccessToken", "server_error: Encountered internal server error while saving access token to database", "")
return
@@ -1022,7 +1021,7 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
hchan := api.Srv.Store.Webhook().GetIncoming(c.T, id)
hchan := api.Srv.Store.Webhook().GetIncoming(id)
r.ParseForm()
@@ -1070,7 +1069,7 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
if len(channelName) != 0 {
if channelName[0] == '@' {
if result := <-api.Srv.Store.User().GetByUsername(c.T, hook.TeamId, channelName[1:]); result.Err != nil {
if result := <-api.Srv.Store.User().GetByUsername(hook.TeamId, channelName[1:]); result.Err != nil {
c.Err = model.NewAppError("incomingWebhook", "Couldn't find the user", "err="+result.Err.Message)
return
} else {
@@ -1080,9 +1079,9 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
channelName = channelName[1:]
}
cchan = api.Srv.Store.Channel().GetByName(c.T, hook.TeamId, channelName)
cchan = api.Srv.Store.Channel().GetByName(hook.TeamId, channelName)
} else {
cchan = api.Srv.Store.Channel().Get(c.T, hook.ChannelId)
cchan = api.Srv.Store.Channel().Get(hook.ChannelId)
}
overrideUsername := parsedRequest.Username
@@ -1095,7 +1094,7 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
channel = result.Data.(*model.Channel)
}
pchan := api.Srv.Store.Channel().CheckPermissionsTo(c.T, hook.TeamId, channel.Id, hook.UserId)
pchan := api.Srv.Store.Channel().CheckPermissionsTo(hook.TeamId, channel.Id, hook.UserId)
// create a mock session
c.Session = model.Session{UserId: hook.UserId, TeamId: hook.TeamId, IsOAuth: false}
@@ -1125,7 +1124,7 @@ func claimAccount(c *api.Context, w http.ResponseWriter, r *http.Request) {
newType := r.URL.Query().Get("new_type")
var team *model.Team
if tResult := <-api.Srv.Store.Team().GetByName(c.T, teamName); tResult.Err != nil {
if tResult := <-api.Srv.Store.Team().GetByName(teamName); tResult.Err != nil {
l4g.Error("Couldn't find team name=%v, err=%v", teamName, tResult.Err.Message)
http.Redirect(w, r, api.GetProtocol(r)+"://"+r.Host, http.StatusTemporaryRedirect)
return
@@ -1135,7 +1134,7 @@ func claimAccount(c *api.Context, w http.ResponseWriter, r *http.Request) {
authType := ""
if len(email) != 0 {
if uResult := <-api.Srv.Store.User().GetByEmail(c.T, team.Id, email); uResult.Err != nil {
if uResult := <-api.Srv.Store.User().GetByEmail(team.Id, email); uResult.Err != nil {
l4g.Error("Couldn't find user teamid=%v, email=%v, err=%v", team.Id, email, uResult.Err.Message)
http.Redirect(w, r, api.GetProtocol(r)+"://"+r.Host, http.StatusTemporaryRedirect)
return

View File

@@ -62,7 +62,7 @@ func TestGetAccessToken(t *testing.T) {
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Password: "pwd"}
ruser := ApiClient.Must(ApiClient.CreateUser(&user, "")).Data.(*model.User)
store.Must(api.Srv.Store.User().VerifyEmail(utils.T, ruser.Id))
store.Must(api.Srv.Store.User().VerifyEmail(ruser.Id))
app := &model.OAuthApp{Name: "TestApp" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -191,7 +191,7 @@ func TestIncomingWebhook(t *testing.T) {
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
user = ApiClient.Must(ApiClient.CreateUser(user, "")).Data.(*model.User)
store.Must(api.Srv.Store.User().VerifyEmail(utils.T, user.Id))
store.Must(api.Srv.Store.User().VerifyEmail(user.Id))
ApiClient.LoginByEmail(team.Name, user.Email, "pwd")