PLT-7 adding loc db calls for oauth table

Этот коммит содержится в:
=Corey Hulen
2016-01-20 10:04:17 -06:00
родитель 640d3018c9
Коммит 11c035aef4
19 изменённых файлов: 302 добавлений и 291 удалений

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

@@ -157,8 +157,8 @@ 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(teamId, model.CHANNEL_OPEN)
privateChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
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(teamId)
if r := <-openChan; r.Err != nil {

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

@@ -5,12 +5,14 @@ package api
import (
"fmt"
l4g "github.com/alecthomas/log4go"
"github.com/gorilla/mux"
"github.com/mattermost/platform/model"
"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"
)
const (
@@ -76,7 +78,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(channel); result.Err != nil {
if result := <-Srv.Store.Channel().Save(c.T, channel); result.Err != nil {
return nil, result.Err
} else {
sc := result.Data.(*model.Channel)
@@ -85,7 +87,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(cm); cmresult.Err != nil {
if cmresult := <-Srv.Store.Channel().SaveMember(c.T, cm); cmresult.Err != nil {
return nil, cmresult.Err
}
}
@@ -149,7 +151,7 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
NotifyProps: model.GetDefaultChannelNotifyProps(),
}
if result := <-Srv.Store.Channel().SaveDirectChannel(channel, cm1, cm2); result.Err != nil {
if result := <-Srv.Store.Channel().SaveDirectChannel(c.T, channel, cm1, cm2); result.Err != nil {
return nil, result.Err
} else {
return result.Data.(*model.Channel), nil
@@ -182,8 +184,8 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
sc := Srv.Store.Channel().Get(channel.Id)
cmc := Srv.Store.Channel().GetMember(channel.Id, c.Session.UserId)
sc := Srv.Store.Channel().Get(c.T, channel.Id)
cmc := Srv.Store.Channel().GetMember(c.T, channel.Id, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -233,7 +235,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannel.Type = channel.Type
}
if ucresult := <-Srv.Store.Channel().Update(oldChannel); ucresult.Err != nil {
if ucresult := <-Srv.Store.Channel().Update(c.T, oldChannel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -258,8 +260,8 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
sc := Srv.Store.Channel().Get(channelId)
cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
sc := Srv.Store.Channel().Get(c.T, channelId)
cmc := Srv.Store.Channel().GetMember(c.T, channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -277,7 +279,7 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelHeader := channel.Header
channel.Header = channelHeader
if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
if ucresult := <-Srv.Store.Channel().Update(c.T, channel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -333,8 +335,8 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
sc := Srv.Store.Channel().Get(channelId)
cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
sc := Srv.Store.Channel().Get(c.T, channelId)
cmc := Srv.Store.Channel().GetMember(c.T, channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -352,7 +354,7 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
channel.Purpose = channelPurpose
if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
if ucresult := <-Srv.Store.Channel().Update(c.T, channel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -366,7 +368,7 @@ func getChannels(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
if result := <-Srv.Store.Channel().GetChannels(c.Session.TeamId, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Channel().GetChannels(c.T, 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.Session.UserId); result.Err != nil {
@@ -391,7 +393,7 @@ func getMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
if result := <-Srv.Store.Channel().GetMoreChannels(c.Session.TeamId, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Channel().GetMoreChannels(c.T, c.Session.TeamId, c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else if HandleEtag(result.Data.(*model.ChannelList).Etag(), w, r) {
@@ -407,7 +409,7 @@ func getChannelCounts(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
if result := <-Srv.Store.Channel().GetChannelCounts(c.Session.TeamId, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Channel().GetChannelCounts(c.T, 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) {
@@ -437,7 +439,7 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
func JoinChannel(c *Context, channelId string, role string) {
sc := Srv.Store.Channel().Get(channelId)
sc := Srv.Store.Channel().Get(c.T, channelId)
uc := Srv.Store.User().Get(c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
@@ -455,7 +457,7 @@ func JoinChannel(c *Context, channelId string, role string) {
}
if channel.Type == model.CHANNEL_OPEN {
if _, err := AddUserToChannel(user, channel); err != nil {
if _, err := AddUserToChannel(c.T, user, channel); err != nil {
c.Err = err
return
}
@@ -481,7 +483,7 @@ func PostUserAddRemoveMessageAndForget(c *Context, channelId string, message str
}()
}
func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
func AddUserToChannel(T goi18n.TranslateFunc, 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", "")
}
@@ -491,7 +493,7 @@ func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelM
}
newMember := &model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, NotifyProps: model.GetDefaultChannelNotifyProps()}
if cmresult := <-Srv.Store.Channel().SaveMember(newMember); cmresult.Err != nil {
if cmresult := <-Srv.Store.Channel().SaveMember(T, 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", "")
}
@@ -506,29 +508,29 @@ func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelM
return newMember, nil
}
func JoinDefaultChannels(user *model.User, channelRole string) *model.AppError {
func JoinDefaultChannels(T goi18n.TranslateFunc, 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(user.TeamId, "town-square"); result.Err != nil {
if result := <-Srv.Store.Channel().GetByName(T, 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(cm); cmResult.Err != nil {
if cmResult := <-Srv.Store.Channel().SaveMember(T, cm); cmResult.Err != nil {
err = cmResult.Err
}
}
if result := <-Srv.Store.Channel().GetByName(user.TeamId, "off-topic"); result.Err != nil {
if result := <-Srv.Store.Channel().GetByName(T, 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(cm); cmResult.Err != nil {
if cmResult := <-Srv.Store.Channel().SaveMember(T, cm); cmResult.Err != nil {
err = cmResult.Err
}
}
@@ -541,7 +543,7 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
sc := Srv.Store.Channel().Get(id)
sc := Srv.Store.Channel().Get(c.T, id)
uc := Srv.Store.User().Get(c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
@@ -570,12 +572,12 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if cmresult := <-Srv.Store.Channel().RemoveMember(channel.Id, c.Session.UserId); cmresult.Err != nil {
if cmresult := <-Srv.Store.Channel().RemoveMember(c.T, channel.Id, c.Session.UserId); cmresult.Err != nil {
c.Err = cmresult.Err
return
}
RemoveUserFromChannel(c.Session.UserId, c.Session.UserId, channel)
RemoveUserFromChannel(c.T, c.Session.UserId, c.Session.UserId, channel)
PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(`%v has left the channel.`, user.Username))
@@ -590,8 +592,8 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
sc := Srv.Store.Channel().Get(id)
scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
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.Session.UserId)
ihc := Srv.Store.Webhook().GetIncomingByChannel(c.T, id)
ohc := Srv.Store.Webhook().GetOutgoingByChannel(c.T, id)
@@ -657,7 +659,7 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}()
}
if dresult := <-Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); dresult.Err != nil {
if dresult := <-Srv.Store.Channel().Delete(c.T, channel.Id, model.GetMillis()); dresult.Err != nil {
c.Err = dresult.Err
return
}
@@ -683,7 +685,7 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
Srv.Store.Channel().UpdateLastViewedAt(id, c.Session.UserId)
Srv.Store.Channel().UpdateLastViewedAt(c.T, id, c.Session.UserId)
preference := model.Preference{
UserId: c.Session.UserId,
@@ -709,8 +711,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(id)
cmchan := Srv.Store.Channel().GetMember(id, c.Session.UserId)
cchan := Srv.Store.Channel().Get(c.T, id)
cmchan := Srv.Store.Channel().GetMember(c.T, id, c.Session.UserId)
if cresult := <-cchan; cresult.Err != nil {
c.Err = cresult.Err
@@ -749,7 +751,7 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) {
memberLimit = int(memberLimitInt64)
}
sc := Srv.Store.Channel().Get(id)
sc := Srv.Store.Channel().Get(c.T, id)
var channel *model.Channel
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -763,9 +765,9 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
ecm := Srv.Store.Channel().GetExtraMembers(id, memberLimit)
ccm := Srv.Store.Channel().GetMemberCount(id)
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)
if cmresult := <-scm; cmresult.Err != nil {
c.Err = cmresult.Err
@@ -814,8 +816,8 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
sc := Srv.Store.Channel().Get(id)
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.Session.UserId)
nuc := Srv.Store.User().Get(userId)
@@ -840,7 +842,7 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
oUser := oresult.Data.(*model.User)
cm, err := AddUserToChannel(nUser, channel)
cm, err := AddUserToChannel(c.T, nUser, channel)
if err != nil {
c.Err = err
return
@@ -850,7 +852,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(id, oUser.Id)
<-Srv.Store.Channel().UpdateLastViewedAt(c.T, id, oUser.Id)
w.Write([]byte(cm.ToJson()))
}
}
@@ -868,8 +870,8 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
sc := Srv.Store.Channel().Get(channelId)
cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
sc := Srv.Store.Channel().Get(c.T, channelId)
cmc := Srv.Store.Channel().GetMember(c.T, channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -891,7 +893,7 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := RemoveUserFromChannel(userIdToRemove, c.Session.UserId, channel); err != nil {
if err := RemoveUserFromChannel(c.T, userIdToRemove, c.Session.UserId, channel); err != nil {
c.Err = model.NewAppError("updateChannel", "Unable to remove user.", err.Message)
return
}
@@ -906,12 +908,12 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
func RemoveUserFromChannel(userIdToRemove string, removerUserId string, channel *model.Channel) *model.AppError {
func RemoveUserFromChannel(T goi18n.TranslateFunc, 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(channel.Id, userIdToRemove); cmresult.Err != nil {
if cmresult := <-Srv.Store.Channel().RemoveMember(T, channel.Id, userIdToRemove); cmresult.Err != nil {
return cmresult.Err
}
@@ -939,7 +941,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
if !c.HasPermissionsToUser(userId, "updateNotifyLevel") {
return
@@ -949,7 +951,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
result := <-Srv.Store.Channel().GetMember(channelId, userId)
result := <-Srv.Store.Channel().GetMember(c.T, channelId, userId)
if result.Err != nil {
c.Err = result.Err
return
@@ -966,7 +968,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
member.NotifyProps["desktop"] = desktop
}
if result := <-Srv.Store.Channel().UpdateMember(&member); result.Err != nil {
if result := <-Srv.Store.Channel().UpdateMember(c.T, &member); result.Err != nil {
c.Err = result.Err
return
} else {

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

@@ -79,7 +79,7 @@ func checkCommand(c *Context, command *model.Command) bool {
}
if len(command.ChannelId) > 0 {
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, command.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, 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.Session.TeamId, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Channel().GetMoreChannels(c.T, c.Session.TeamId, c.Session.UserId); result.Err != nil {
c.Err = result.Err
return false
} else {

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

@@ -122,7 +122,7 @@ func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOpt
// Export the channels, local storage and users
for _, team := range teams {
if err := ExportChannels(writer, options, team.Id); err != nil {
if err := ExportChannels(T, writer, options, team.Id); err != nil {
return err
}
if err := ExportUsers(writer, options, team.Id); err != nil {
@@ -136,18 +136,18 @@ func ExportTeams(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOpt
return nil
}
func ExportChannels(writer ExportWriter, options *ExportOptions, teamId string) *model.AppError {
func ExportChannels(T goi18n.TranslateFunc, 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(teamId); result.Err != nil {
if result := <-Srv.Store.Channel().GetForExport(T, 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(channelId); result.Err != nil {
if result := <-Srv.Store.Channel().Get(T, channelId); result.Err != nil {
return result.Err
} else {
channel := result.Data.(*model.Channel)
@@ -158,7 +158,7 @@ func ExportChannels(writer ExportWriter, options *ExportOptions, teamId string)
for i := range channels {
// Get members
mchan := Srv.Store.Channel().GetMembers(channels[i].Id)
mchan := Srv.Store.Channel().GetMembers(T, channels[i].Id)
// Sanitize
channels[i].PreExport()

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

@@ -101,7 +101,7 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, 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.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, 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.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, 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.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
newProps := make(map[string]string)
newProps["filename"] = filename

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

@@ -6,6 +6,7 @@ package api
import (
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
//
@@ -21,7 +22,7 @@ func ImportPost(post *model.Post) {
}
}
func ImportUser(user *model.User) *model.User {
func ImportUser(T goi18n.TranslateFunc, user *model.User) *model.User {
user.MakeNonNil()
if result := <-Srv.Store.User().Save(user); result.Err != nil {
@@ -30,7 +31,7 @@ func ImportUser(user *model.User) *model.User {
} else {
ruser := result.Data.(*model.User)
if err := JoinDefaultChannels(ruser, ""); err != nil {
if err := JoinDefaultChannels(T, ruser, ""); err != nil {
l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, err)
}
@@ -42,8 +43,8 @@ func ImportUser(user *model.User) *model.User {
}
}
func ImportChannel(channel *model.Channel) *model.Channel {
if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
func ImportChannel(T goi18n.TranslateFunc, channel *model.Channel) *model.Channel {
if result := <-Srv.Store.Channel().Save(T, channel); result.Err != nil {
return nil
} else {
sc := result.Data.(*model.Channel)

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

@@ -46,7 +46,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
}
// Create and save post object to channel
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId)
if !c.HasPermissionsToChannel(cchan, "createPost") {
return
@@ -61,7 +61,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
} else {
if result := <-Srv.Store.Channel().UpdateLastViewedAt(post.ChannelId, c.Session.UserId); result.Err != nil {
if result := <-Srv.Store.Channel().UpdateLastViewedAt(c.T, 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)
}
@@ -206,7 +206,7 @@ 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(post.ChannelId)
cchan := Srv.Store.Channel().Get(c.T, post.ChannelId)
uchan := Srv.Store.User().Get(post.UserId)
var team *model.Team
@@ -247,7 +247,7 @@ func handlePostEventsAndForget(c *Context, post *model.Post, triggerWebhooks boo
func makeDirectChannelVisible(T goi18n.TranslateFunc, teamId string, channelId string) {
var members []model.ChannelMember
if result := <-Srv.Store.Channel().GetMembers(channelId); result.Err != nil {
if result := <-Srv.Store.Channel().GetMembers(T, channelId); result.Err != nil {
l4g.Error("Failed to get channel members channel_id=%v err=%v", channelId, result.Err.Message)
return
} else {
@@ -395,7 +395,7 @@ 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.Session.TeamId)
echan := Srv.Store.Channel().GetMembers(post.ChannelId)
echan := Srv.Store.Channel().GetMembers(c.T, post.ChannelId)
var channelName string
var bodyText string
@@ -542,7 +542,7 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team,
}
for id := range toEmailMap {
updateMentionCountAndForget(post.ChannelId, id)
updateMentionCountAndForget(c.T, post.ChannelId, id)
}
}
@@ -694,9 +694,9 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team,
}()
}
func updateMentionCountAndForget(channelId, userId string) {
func updateMentionCountAndForget(T goi18n.TranslateFunc, channelId, userId string) {
go func() {
if result := <-Srv.Store.Channel().IncrementMentionCount(channelId, userId); result.Err != nil {
if result := <-Srv.Store.Channel().IncrementMentionCount(T, 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,7 +710,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(post.Id)
if !c.HasPermissionsToChannel(cchan, "updatePost") {
@@ -781,7 +781,7 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
etagChan := Srv.Store.Post().GetEtag(id)
if !c.HasPermissionsToChannel(cchan, "getPosts") {
@@ -823,7 +823,7 @@ func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
pchan := Srv.Store.Post().GetPostsSince(id, time)
if !c.HasPermissionsToChannel(cchan, "getPostsSince") {
@@ -856,7 +856,7 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(postId)
if !c.HasPermissionsToChannel(cchan, "getPost") {
@@ -903,7 +903,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
}
post := list.Posts[list.Order[0]]
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId)
if !c.HasPermissionsToChannel(cchan, "getPostById") {
return
}
@@ -932,7 +932,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(postId)
if result := <-pchan; result.Err != nil {
@@ -1012,7 +1012,7 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
return
}
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
// We can do better than this etag in this situation
etagChan := Srv.Store.Post().GetEtag(id)

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

@@ -7,12 +7,14 @@ 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 {
@@ -89,7 +91,7 @@ func SlackParsePosts(data io.Reader) []SlackPost {
return posts
}
func SlackAddUsers(teamId string, slackusers []SlackUser, log *bytes.Buffer) map[string]*model.User {
func SlackAddUsers(T goi18n.TranslateFunc, 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")
@@ -116,7 +118,7 @@ func SlackAddUsers(teamId string, slackusers []SlackUser, log *bytes.Buffer) map
Password: password,
}
if mUser := ImportUser(&newUser); mUser != nil {
if mUser := ImportUser(T, &newUser); mUser != nil {
addedUsers[sUser.Id] = mUser
log.WriteString("Email, Password: " + newUser.Email + ", " + password + "\r\n")
} else {
@@ -170,7 +172,7 @@ func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*
}
}
func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[string][]SlackPost, users map[string]*model.User, log *bytes.Buffer) map[string]*model.Channel {
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 {
// Write Header
log.WriteString("\r\n Channels Added \r\n")
log.WriteString("=================\r\n\r\n")
@@ -184,10 +186,10 @@ func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[str
Name: SlackConvertChannelName(sChannel.Name),
Purpose: sChannel.Topic["value"],
}
mChannel := ImportChannel(&newChannel)
mChannel := ImportChannel(T, &newChannel)
if mChannel == nil {
// Maybe it already exists?
if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name); result.Err != nil {
if result := <-Srv.Store.Channel().GetByName(T, teamId, sChannel.Name); result.Err != nil {
l4g.Debug("Failed to import: %s", newChannel.DisplayName)
log.WriteString("Failed to import: " + newChannel.DisplayName + "\r\n")
continue
@@ -204,7 +206,7 @@ func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[str
return addedChannels
}
func SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
func SlackImport(T goi18n.TranslateFunc, 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
@@ -240,8 +242,8 @@ func SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model
}
}
addedUsers := SlackAddUsers(teamID, users, log)
SlackAddChannels(teamID, channels, posts, addedUsers, log)
addedUsers := SlackAddUsers(T, teamID, users, log)
SlackAddChannels(T, teamID, channels, posts, addedUsers, log)
log.WriteString("\r\n Notes \r\n")
log.WriteString("=======\r\n\r\n")

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

@@ -605,7 +605,7 @@ func PermanentDeleteTeam(c *Context, team *model.Team) *model.AppError {
}
}
if result := <-Srv.Store.Channel().PermanentDeleteByTeam(team.Id); result.Err != nil {
if result := <-Srv.Store.Channel().PermanentDeleteByTeam(c.T, team.Id); result.Err != nil {
return result.Err
}
@@ -694,7 +694,7 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
switch importFrom {
case "slack":
var err *model.AppError
if err, log = SlackImport(fileData, fileSize, c.Session.TeamId); err != nil {
if err, log = SlackImport(c.T, fileData, fileSize, c.Session.TeamId); err != nil {
c.Err = err
c.Err.StatusCode = http.StatusBadRequest
}

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

@@ -216,7 +216,7 @@ func CreateUser(T goi18n.TranslateFunc, team *model.Team, user *model.User) (*mo
ruser := result.Data.(*model.User)
// Soft error if there is an issue joining the default channels
if err := JoinDefaultChannels(ruser, channelRole); err != nil {
if err := JoinDefaultChannels(T, 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)
}
@@ -1456,7 +1456,7 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
return result.Err
}
if result := <-Srv.Store.Channel().PermanentDeleteMembersByUser(user.Id); result.Err != nil {
if result := <-Srv.Store.Channel().PermanentDeleteMembersByUser(c.T, user.Id); result.Err != nil {
return result.Err
}

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

@@ -8,6 +8,7 @@ import (
"github.com/gorilla/websocket"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
"time"
)
@@ -107,7 +108,7 @@ func (c *WebConn) writePump() {
}
func (c *WebConn) updateChannelAccessCache(channelId string) bool {
allowed := hasPermissionsToChannel(Srv.Store.Channel().CheckPermissionsTo(c.TeamId, channelId, c.UserId))
allowed := hasPermissionsToChannel(Srv.Store.Channel().CheckPermissionsTo(utils.T, c.TeamId, channelId, c.UserId))
c.ChannelAccessCache[channelId] = allowed
return allowed

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

@@ -41,8 +41,8 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
cchan := Srv.Store.Channel().Get(hook.ChannelId)
pchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, hook.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().Get(c.T, hook.ChannelId)
pchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, hook.ChannelId, c.Session.UserId)
hook.UserId = c.Session.UserId
hook.TeamId = c.Session.TeamId
@@ -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(hook.ChannelId)
pchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, hook.ChannelId, c.Session.UserId)
cchan := Srv.Store.Channel().Get(c.T, hook.ChannelId)
pchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, hook.ChannelId, c.Session.UserId)
var channel *model.Channel
if result := <-cchan; result.Err != nil {

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

@@ -4,16 +4,18 @@
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 {
@@ -149,9 +151,9 @@ func manualTest(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
}
func getChannelID(channelname string, teamid string, userid string) (id string, err bool) {
func getChannelID(T goi18n.TranslateFunc, channelname string, teamid string, userid string) (id string, err bool) {
// Grab all the channels
result := <-api.Srv.Store.Channel().GetChannels(teamid, userid)
result := <-api.Srv.Store.Channel().GetChannels(T, teamid, userid)
if result.Err != nil {
l4g.Debug("Unable to get channels")
return "", false

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

@@ -6,6 +6,7 @@ package manualtesting
import (
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
const LINK_POST_TEXT = `
@@ -21,7 +22,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(model.DEFAULT_CHANNEL, env.CreatedTeamId, env.CreatedUserId)
channelID, err := getChannelID(utils.T, model.DEFAULT_CHANNEL, env.CreatedTeamId, env.CreatedUserId)
if err != true {
return model.NewAppError("/manualtest", "Unable to get channels", "")
}

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

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

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

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

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

@@ -655,20 +655,20 @@ func TestPostStoreSearch(t *testing.T) {
c1.DisplayName = "Channel1"
c1.Name = "a" + model.NewId() + "b"
c1.Type = model.CHANNEL_OPEN
c1 = (<-store.Channel().Save(c1)).Data.(*model.Channel)
c1 = (<-store.Channel().Save(utils.T, c1)).Data.(*model.Channel)
m1 := model.ChannelMember{}
m1.ChannelId = c1.Id
m1.UserId = userId
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
Must(store.Channel().SaveMember(utils.T, &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(c2)).Data.(*model.Channel)
c2 = (<-store.Channel().Save(utils.T, c2)).Data.(*model.Channel)
o1 := &model.Post{}
o1.ChannelId = c1.Id
@@ -772,7 +772,7 @@ func TestUserCountsWithPostsByDay(t *testing.T) {
c1.DisplayName = "Channel2"
c1.Name = "a" + model.NewId() + "b"
c1.Type = model.CHANNEL_OPEN
c1 = Must(store.Channel().Save(c1)).(*model.Channel)
c1 = Must(store.Channel().Save(utils.T, c1)).(*model.Channel)
o1 := &model.Post{}
o1.ChannelId = c1.Id
@@ -832,7 +832,7 @@ func TestPostCountsByDay(t *testing.T) {
c1.DisplayName = "Channel2"
c1.Name = "a" + model.NewId() + "b"
c1.Type = model.CHANNEL_OPEN
c1 = Must(store.Channel().Save(c1)).(*model.Channel)
c1 = Must(store.Channel().Save(utils.T, c1)).(*model.Channel)
o1 := &model.Post{}
o1.ChannelId = c1.Id

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

@@ -58,33 +58,33 @@ type TeamStore interface {
}
type ChannelStore interface {
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
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
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
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
}
type PostStore interface {

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

@@ -243,7 +243,7 @@ func login(c *api.Context, w http.ResponseWriter, r *http.Request) {
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(lastViewResult.Data.(model.Preference).Value); lastViewChannelResult.Err == nil {
if lastViewChannelResult := <-api.Srv.Store.Channel().Get(c.T, lastViewResult.Data.(model.Preference).Value); lastViewChannelResult.Err == nil {
lastViewChannelName = lastViewChannelResult.Data.(*model.Channel).Name
}
}
@@ -379,7 +379,7 @@ func postPermalink(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
var channel *model.Channel
if result := <-api.Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId); result.Err != nil {
if result := <-api.Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -389,7 +389,7 @@ func postPermalink(c *api.Context, w http.ResponseWriter, r *http.Request) {
return
}
} else {
if result := <-api.Srv.Store.Channel().Get(post.ChannelId); result.Err != nil {
if result := <-api.Srv.Store.Channel().Get(c.T, post.ChannelId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -413,7 +413,7 @@ func getChannel(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
var channel *model.Channel
if result := <-api.Srv.Store.Channel().CheckPermissionsToByName(c.Session.TeamId, name, c.Session.UserId); result.Err != nil {
if result := <-api.Srv.Store.Channel().CheckPermissionsToByName(c.T, c.Session.TeamId, name, c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -424,7 +424,7 @@ func getChannel(c *api.Context, w http.ResponseWriter, r *http.Request) {
return
}
} else {
if result := <-api.Srv.Store.Channel().Get(channelId); result.Err != nil {
if result := <-api.Srv.Store.Channel().Get(c.T, channelId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -455,14 +455,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.Session.TeamId, channelName))
return joinOpenChannel(c, w, r, api.Srv.Store.Channel().GetByName(c.T, 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(channelId))
return joinOpenChannel(c, w, r, api.Srv.Store.Channel().Get(c.T, channelId))
}
func joinOpenChannel(c *api.Context, w http.ResponseWriter, r *http.Request, channel store.StoreChannel) *model.Channel {
@@ -1080,9 +1080,9 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
channelName = channelName[1:]
}
cchan = api.Srv.Store.Channel().GetByName(hook.TeamId, channelName)
cchan = api.Srv.Store.Channel().GetByName(c.T, hook.TeamId, channelName)
} else {
cchan = api.Srv.Store.Channel().Get(hook.ChannelId)
cchan = api.Srv.Store.Channel().Get(c.T, hook.ChannelId)
}
overrideUsername := parsedRequest.Username
@@ -1095,7 +1095,7 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
channel = result.Data.(*model.Channel)
}
pchan := api.Srv.Store.Channel().CheckPermissionsTo(hook.TeamId, channel.Id, hook.UserId)
pchan := api.Srv.Store.Channel().CheckPermissionsTo(c.T, hook.TeamId, channel.Id, hook.UserId)
// create a mock session
c.Session = model.Session{UserId: hook.UserId, TeamId: hook.TeamId, IsOAuth: false}