diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/admin.go | 4 | ||||
-rw-r--r-- | api/channel.go | 106 | ||||
-rw-r--r-- | api/command.go | 4 | ||||
-rw-r--r-- | api/export.go | 10 | ||||
-rw-r--r-- | api/file.go | 8 | ||||
-rw-r--r-- | api/import.go | 9 | ||||
-rw-r--r-- | api/post.go | 30 | ||||
-rw-r--r-- | api/slackimport.go | 22 | ||||
-rw-r--r-- | api/team.go | 4 | ||||
-rw-r--r-- | api/user.go | 4 | ||||
-rw-r--r-- | api/web_conn.go | 3 | ||||
-rw-r--r-- | api/webhook.go | 8 |
12 files changed, 109 insertions, 103 deletions
diff --git a/api/admin.go b/api/admin.go index 61741b445..008e55699 100644 --- a/api/admin.go +++ b/api/admin.go @@ -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 { diff --git a/api/channel.go b/api/channel.go index f2880da5d..39ea62f2b 100644 --- a/api/channel.go +++ b/api/channel.go @@ -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 { diff --git a/api/command.go b/api/command.go index 00293cf16..5db7e0d13 100644 --- a/api/command.go +++ b/api/command.go @@ -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 { diff --git a/api/export.go b/api/export.go index 160da8d9f..2030b0723 100644 --- a/api/export.go +++ b/api/export.go @@ -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() diff --git a/api/file.go b/api/file.go index 46e81691e..b83144222 100644 --- a/api/file.go +++ b/api/file.go @@ -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 diff --git a/api/import.go b/api/import.go index 5c8f99348..7c4770327 100644 --- a/api/import.go +++ b/api/import.go @@ -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) diff --git a/api/post.go b/api/post.go index 17a3be8ba..c54bd59b3 100644 --- a/api/post.go +++ b/api/post.go @@ -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) diff --git a/api/slackimport.go b/api/slackimport.go index e0a0ff036..6c392a6cf 100644 --- a/api/slackimport.go +++ b/api/slackimport.go @@ -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") diff --git a/api/team.go b/api/team.go index e55d454e0..eb328ce7b 100644 --- a/api/team.go +++ b/api/team.go @@ -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 } diff --git a/api/user.go b/api/user.go index 71426acaa..142fe10b8 100644 --- a/api/user.go +++ b/api/user.go @@ -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 } diff --git a/api/web_conn.go b/api/web_conn.go index 2b0e29038..aed16aa55 100644 --- a/api/web_conn.go +++ b/api/web_conn.go @@ -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 diff --git a/api/webhook.go b/api/webhook.go index 7c7d89866..284563ddd 100644 --- a/api/webhook.go +++ b/api/webhook.go @@ -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 { |