From f5eb3c1bcb0c7e367f64bd8e5a0d2d5418f8e2ef Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 07:59:56 -0600 Subject: PLT-7 adding loc for db calls audits and prefs --- api/post.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'api/post.go') diff --git a/api/post.go b/api/post.go index 7cd45d310..a662cc147 100644 --- a/api/post.go +++ b/api/post.go @@ -5,11 +5,6 @@ package api import ( "fmt" - l4g "github.com/alecthomas/log4go" - "github.com/gorilla/mux" - "github.com/mattermost/platform/model" - "github.com/mattermost/platform/store" - "github.com/mattermost/platform/utils" "net/http" "net/url" "path/filepath" @@ -17,6 +12,13 @@ import ( "strconv" "strings" "time" + + l4g "github.com/alecthomas/log4go" + "github.com/gorilla/mux" + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/store" + "github.com/mattermost/platform/utils" + goi18n "github.com/nicksnyder/go-i18n/i18n" ) func InitPost(r *mux.Router) { @@ -238,12 +240,12 @@ func handlePostEventsAndForget(c *Context, post *model.Post, triggerWebhooks boo } if channel.Type == model.CHANNEL_DIRECT { - go makeDirectChannelVisible(c.Session.TeamId, post.ChannelId) + go makeDirectChannelVisible(c.T, c.Session.TeamId, post.ChannelId) } }() } -func makeDirectChannelVisible(teamId string, channelId string) { +func makeDirectChannelVisible(T goi18n.TranslateFunc, teamId string, channelId string) { var members []model.ChannelMember if result := <-Srv.Store.Channel().GetMembers(channelId); result.Err != nil { l4g.Error("Failed to get channel members channel_id=%v err=%v", channelId, result.Err.Message) @@ -261,7 +263,7 @@ func makeDirectChannelVisible(teamId string, channelId string) { for i, member := range members { otherUserId := members[1-i].UserId - if result := <-Srv.Store.Preference().Get(member.UserId, model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW, otherUserId); result.Err != nil { + if result := <-Srv.Store.Preference().Get(T, member.UserId, model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW, otherUserId); result.Err != nil { // create a new preference since one doesn't exist yet preference := &model.Preference{ UserId: member.UserId, @@ -270,7 +272,7 @@ func makeDirectChannelVisible(teamId string, channelId string) { Value: "true", } - if saveResult := <-Srv.Store.Preference().Save(&model.Preferences{*preference}); saveResult.Err != nil { + if saveResult := <-Srv.Store.Preference().Save(T, &model.Preferences{*preference}); saveResult.Err != nil { l4g.Error("Failed to save direct channel preference user_id=%v other_user_id=%v err=%v", member.UserId, otherUserId, saveResult.Err.Message) } else { message := model.NewMessage(teamId, channelId, member.UserId, model.ACTION_PREFERENCE_CHANGED) @@ -285,7 +287,7 @@ func makeDirectChannelVisible(teamId string, channelId string) { // update the existing preference to make the channel visible preference.Value = "true" - if updateResult := <-Srv.Store.Preference().Save(&model.Preferences{preference}); updateResult.Err != nil { + if updateResult := <-Srv.Store.Preference().Save(T, &model.Preferences{preference}); updateResult.Err != nil { l4g.Error("Failed to update direct channel preference user_id=%v other_user_id=%v err=%v", member.UserId, otherUserId, updateResult.Err.Message) } else { message := model.NewMessage(teamId, channelId, member.UserId, model.ACTION_PREFERENCE_CHANGED) -- cgit v1.2.3-1-g7c22 From 5b2ec623473abeb44577fbfc9122b792a94a5184 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 08:33:26 -0600 Subject: PLT-7 adding loc db calls for team table --- api/post.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/post.go') diff --git a/api/post.go b/api/post.go index a662cc147..87678e9c6 100644 --- a/api/post.go +++ b/api/post.go @@ -205,7 +205,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.Session.TeamId) + tchan := Srv.Store.Team().Get(c.T, c.Session.TeamId) cchan := Srv.Store.Channel().Get(post.ChannelId) uchan := Srv.Store.User().Get(post.UserId) -- cgit v1.2.3-1-g7c22 From ef11df753227f3082d5c2226c0e7525e14ed47c7 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 08:44:05 -0600 Subject: PLT-7 adding loc db calls for webhooks table --- api/post.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/post.go') diff --git a/api/post.go b/api/post.go index 87678e9c6..17a3be8ba 100644 --- a/api/post.go +++ b/api/post.go @@ -310,7 +310,7 @@ func handleWebhookEventsAndForget(c *Context, post *model.Post, team *model.Team return } - hchan := Srv.Store.Webhook().GetOutgoingByTeam(c.Session.TeamId) + hchan := Srv.Store.Webhook().GetOutgoingByTeam(c.T, c.Session.TeamId) hooks := []*model.OutgoingWebhook{} -- cgit v1.2.3-1-g7c22 From 11c035aef45fbc6dfbc360123611108a199eca79 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 10:04:17 -0600 Subject: PLT-7 adding loc db calls for oauth table --- api/post.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'api/post.go') 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) -- cgit v1.2.3-1-g7c22 From 3ac5ecf0e98823cab22c77d3a56393cbe6bbc19a Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 10:18:11 -0600 Subject: PLT-7 adding loc db calls for session table --- api/post.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/post.go') diff --git a/api/post.go b/api/post.go index c54bd59b3..f78dd0dcd 100644 --- a/api/post.go +++ b/api/post.go @@ -626,7 +626,7 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team, } if *utils.Cfg.EmailSettings.SendPushNotifications { - sessionChan := Srv.Store.Session().GetSessions(id) + sessionChan := Srv.Store.Session().GetSessions(c.T, id) if result := <-sessionChan; result.Err != nil { l4g.Error("Failed to retrieve sessions in notifications id=%v, err=%v", id, result.Err) } else { -- cgit v1.2.3-1-g7c22 From aac8d121a00922f007b9c67d890ea9dbcfbe4b8f Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 10:34:31 -0600 Subject: PLT-7 adding loc db calls for posts table --- api/post.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'api/post.go') diff --git a/api/post.go b/api/post.go index f78dd0dcd..f41f52fe9 100644 --- a/api/post.go +++ b/api/post.go @@ -72,7 +72,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) { func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) { var pchan store.StoreChannel if len(post.RootId) > 0 { - pchan = Srv.Store.Post().Get(post.RootId) + pchan = Srv.Store.Post().Get(c.T, post.RootId) } // Verify the parent/child relationships are correct @@ -138,7 +138,7 @@ func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post } var rpost *model.Post - if result := <-Srv.Store.Post().Save(post); result.Err != nil { + if result := <-Srv.Store.Post().Save(c.T, post); result.Err != nil { return nil, result.Err } else { rpost = result.Data.(*model.Post) @@ -711,7 +711,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) { } cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId) - pchan := Srv.Store.Post().Get(post.Id) + pchan := Srv.Store.Post().Get(c.T, post.Id) if !c.HasPermissionsToChannel(cchan, "updatePost") { return @@ -745,7 +745,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) { hashtags, _ := model.ParseHashtags(post.Message) - if result := <-Srv.Store.Post().Update(oldPost, post.Message, hashtags); result.Err != nil { + if result := <-Srv.Store.Post().Update(c.T, oldPost, post.Message, hashtags); result.Err != nil { c.Err = result.Err return } else { @@ -782,7 +782,7 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) { } cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId) - etagChan := Srv.Store.Post().GetEtag(id) + etagChan := Srv.Store.Post().GetEtag(c.T, id) if !c.HasPermissionsToChannel(cchan, "getPosts") { return @@ -794,7 +794,7 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) { return } - pchan := Srv.Store.Post().GetPosts(id, offset, limit) + pchan := Srv.Store.Post().GetPosts(c.T, id, offset, limit) if result := <-pchan; result.Err != nil { c.Err = result.Err @@ -824,7 +824,7 @@ func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) { } cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId) - pchan := Srv.Store.Post().GetPostsSince(id, time) + pchan := Srv.Store.Post().GetPostsSince(c.T, id, time) if !c.HasPermissionsToChannel(cchan, "getPostsSince") { return @@ -857,7 +857,7 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) { } cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId) - pchan := Srv.Store.Post().Get(postId) + pchan := Srv.Store.Post().Get(c.T, postId) if !c.HasPermissionsToChannel(cchan, "getPost") { return @@ -891,7 +891,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) { return } - if result := <-Srv.Store.Post().Get(postId); result.Err != nil { + if result := <-Srv.Store.Post().Get(c.T, postId); result.Err != nil { c.Err = result.Err return } else { @@ -933,7 +933,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) { } cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId) - pchan := Srv.Store.Post().Get(postId) + pchan := Srv.Store.Post().Get(c.T, postId) if result := <-pchan; result.Err != nil { c.Err = result.Err @@ -963,7 +963,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if dresult := <-Srv.Store.Post().Delete(postId, model.GetMillis()); dresult.Err != nil { + if dresult := <-Srv.Store.Post().Delete(c.T, postId, model.GetMillis()); dresult.Err != nil { c.Err = dresult.Err return } @@ -1014,7 +1014,7 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b 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) + etagChan := Srv.Store.Post().GetEtag(c.T, id) if !c.HasPermissionsToChannel(cchan, "getPostsBeforeOrAfter") { return @@ -1027,9 +1027,9 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b var pchan store.StoreChannel if before { - pchan = Srv.Store.Post().GetPostsBefore(id, postId, numPosts, offset) + pchan = Srv.Store.Post().GetPostsBefore(c.T, id, postId, numPosts, offset) } else { - pchan = Srv.Store.Post().GetPostsAfter(id, postId, numPosts, offset) + pchan = Srv.Store.Post().GetPostsAfter(c.T, id, postId, numPosts, offset) } if result := <-pchan; result.Err != nil { @@ -1057,7 +1057,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) { for _, params := range paramsList { // don't allow users to search for everything if params.Terms != "*" { - channels = append(channels, Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, params)) + channels = append(channels, Srv.Store.Post().Search(c.T, c.Session.TeamId, c.Session.UserId, params)) } } -- cgit v1.2.3-1-g7c22 From 75f8729e2d25467500778e633c45c97e78a8f7a0 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 12:43:44 -0600 Subject: PLT-7 adding loc db calls for users table --- api/post.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'api/post.go') diff --git a/api/post.go b/api/post.go index f41f52fe9..181385f56 100644 --- a/api/post.go +++ b/api/post.go @@ -207,7 +207,7 @@ func handlePostEventsAndForget(c *Context, post *model.Post, triggerWebhooks boo go func() { tchan := Srv.Store.Team().Get(c.T, c.Session.TeamId) cchan := Srv.Store.Channel().Get(c.T, post.ChannelId) - uchan := Srv.Store.User().Get(post.UserId) + uchan := Srv.Store.User().Get(c.T, post.UserId) var team *model.Team if result := <-tchan; result.Err != nil { @@ -394,7 +394,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) + uchan := Srv.Store.User().GetProfiles(c.T, c.Session.TeamId) echan := Srv.Store.Channel().GetMembers(c.T, post.ChannelId) var channelName string -- cgit v1.2.3-1-g7c22