summaryrefslogtreecommitdiffstats
path: root/api/post.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/post.go')
-rw-r--r--api/post.go92
1 files changed, 47 insertions, 45 deletions
diff --git a/api/post.go b/api/post.go
index 7cd45d310..181385f56 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) {
@@ -44,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
@@ -59,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)
}
@@ -70,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
@@ -136,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)
@@ -203,9 +205,9 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc
func handlePostEventsAndForget(c *Context, post *model.Post, triggerWebhooks bool) {
go func() {
- tchan := Srv.Store.Team().Get(c.Session.TeamId)
- cchan := Srv.Store.Channel().Get(post.ChannelId)
- uchan := Srv.Store.User().Get(post.UserId)
+ tchan := Srv.Store.Team().Get(c.T, c.Session.TeamId)
+ cchan := Srv.Store.Channel().Get(c.T, post.ChannelId)
+ uchan := Srv.Store.User().Get(c.T, post.UserId)
var team *model.Team
if result := <-tchan; result.Err != nil {
@@ -238,14 +240,14 @@ 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 {
+ 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 {
@@ -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)
@@ -308,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{}
@@ -392,8 +394,8 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team,
go func() {
// Get a list of user names (to be used as keywords) and ids for the given team
- uchan := Srv.Store.User().GetProfiles(c.Session.TeamId)
- echan := Srv.Store.Channel().GetMembers(post.ChannelId)
+ uchan := Srv.Store.User().GetProfiles(c.T, c.Session.TeamId)
+ echan := Srv.Store.Channel().GetMembers(c.T, post.ChannelId)
var channelName string
var bodyText string
@@ -540,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)
}
}
@@ -624,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 {
@@ -692,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)
}
}()
@@ -708,8 +710,8 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId)
- pchan := Srv.Store.Post().Get(post.Id)
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId)
+ pchan := Srv.Store.Post().Get(c.T, post.Id)
if !c.HasPermissionsToChannel(cchan, "updatePost") {
return
@@ -743,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 {
@@ -779,8 +781,8 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
- etagChan := Srv.Store.Post().GetEtag(id)
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
+ etagChan := Srv.Store.Post().GetEtag(c.T, id)
if !c.HasPermissionsToChannel(cchan, "getPosts") {
return
@@ -792,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
@@ -821,8 +823,8 @@ func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
- pchan := Srv.Store.Post().GetPostsSince(id, time)
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
+ pchan := Srv.Store.Post().GetPostsSince(c.T, id, time)
if !c.HasPermissionsToChannel(cchan, "getPostsSince") {
return
@@ -854,8 +856,8 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
- pchan := Srv.Store.Post().Get(postId)
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
+ pchan := Srv.Store.Post().Get(c.T, postId)
if !c.HasPermissionsToChannel(cchan, "getPost") {
return
@@ -889,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 {
@@ -901,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
}
@@ -930,8 +932,8 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
- pchan := Srv.Store.Post().Get(postId)
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
+ pchan := Srv.Store.Post().Get(c.T, postId)
if result := <-pchan; result.Err != nil {
c.Err = result.Err
@@ -961,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
}
@@ -1010,9 +1012,9 @@ 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)
+ etagChan := Srv.Store.Post().GetEtag(c.T, id)
if !c.HasPermissionsToChannel(cchan, "getPostsBeforeOrAfter") {
return
@@ -1025,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 {
@@ -1055,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))
}
}