Commit 11c035ae authored by =Corey Hulen's avatar =Corey Hulen

PLT-7 adding loc db calls for oauth table

parent 640d3018
......@@ -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 {
......
This diff is collapsed.
......@@ -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", "")
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -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
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
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(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)
}