mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
PLT-7 adding loc for db calls audits and prefs
This commit is contained in:
@@ -692,7 +692,7 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
Value: id,
|
||||
}
|
||||
|
||||
Srv.Store.Preference().Save(&model.Preferences{preference})
|
||||
Srv.Store.Preference().Save(c.T, &model.Preferences{preference})
|
||||
|
||||
message := model.NewMessage(c.Session.TeamId, id, c.Session.UserId, model.ACTION_CHANNEL_VIEWED)
|
||||
message.Add("channel_id", id)
|
||||
|
||||
@@ -233,7 +233,7 @@ func GetProtocol(r *http.Request) string {
|
||||
|
||||
func (c *Context) LogAudit(extraInfo string) {
|
||||
audit := &model.Audit{UserId: c.Session.UserId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id}
|
||||
if r := <-Srv.Store.Audit().Save(audit); r.Err != nil {
|
||||
if r := <-Srv.Store.Audit().Save(c.T, audit); r.Err != nil {
|
||||
c.LogError(r.Err)
|
||||
}
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func (c *Context) LogAuditWithUserId(userId, extraInfo string) {
|
||||
}
|
||||
|
||||
audit := &model.Audit{UserId: userId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id}
|
||||
if r := <-Srv.Store.Audit().Save(audit); r.Err != nil {
|
||||
if r := <-Srv.Store.Audit().Save(c.T, audit); r.Err != nil {
|
||||
c.LogError(r.Err)
|
||||
}
|
||||
}
|
||||
|
||||
22
api/post.go
22
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)
|
||||
|
||||
@@ -837,7 +837,7 @@ func TestMakeDirectChannelVisible(t *testing.T) {
|
||||
|
||||
channel := Client.Must(Client.CreateDirectChannel(map[string]string{"user_id": user2.Id})).Data.(*model.Channel)
|
||||
|
||||
makeDirectChannelVisible(team.Id, channel.Id)
|
||||
makeDirectChannelVisible(utils.T, team.Id, channel.Id)
|
||||
|
||||
if result, err := Client.GetPreference(model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW, user2.Id); err != nil {
|
||||
t.Fatal("Errored trying to set direct channel to be visible for user1")
|
||||
|
||||
@@ -21,7 +21,7 @@ func InitPreference(r *mux.Router) {
|
||||
}
|
||||
|
||||
func getAllPreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if result := <-Srv.Store.Preference().GetAll(c.Session.UserId); result.Err != nil {
|
||||
if result := <-Srv.Store.Preference().GetAll(c.T, c.Session.UserId); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
} else {
|
||||
data := result.Data.(model.Preferences)
|
||||
@@ -46,7 +46,7 @@ func savePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Preference().Save(&preferences); result.Err != nil {
|
||||
if result := <-Srv.Store.Preference().Save(c.T, &preferences); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func getPreferenceCategory(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
category := params["category"]
|
||||
|
||||
if result := <-Srv.Store.Preference().GetCategory(c.Session.UserId, category); result.Err != nil {
|
||||
if result := <-Srv.Store.Preference().GetCategory(c.T, c.Session.UserId, category); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
} else {
|
||||
data := result.Data.(model.Preferences)
|
||||
@@ -72,7 +72,7 @@ func getPreference(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
category := params["category"]
|
||||
name := params["name"]
|
||||
|
||||
if result := <-Srv.Store.Preference().Get(c.Session.UserId, category, name); result.Err != nil {
|
||||
if result := <-Srv.Store.Preference().Get(c.T, c.Session.UserId, category, name); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
} else {
|
||||
data := result.Data.(model.Preference)
|
||||
|
||||
13
api/team.go
13
api/team.go
@@ -6,16 +6,17 @@ package api
|
||||
import (
|
||||
"bytes"
|
||||
"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"
|
||||
"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"
|
||||
)
|
||||
|
||||
func InitTeam(r *mux.Router) {
|
||||
@@ -222,7 +223,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teamSignup.User.TeamId = rteam.Id
|
||||
teamSignup.User.EmailVerified = true
|
||||
|
||||
ruser, err := CreateUser(rteam, &teamSignup.User)
|
||||
ruser, err := CreateUser(c.T, rteam, &teamSignup.User)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
44
api/user.go
44
api/user.go
@@ -7,15 +7,6 @@ import (
|
||||
"bytes"
|
||||
b64 "encoding/base64"
|
||||
"fmt"
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/golang/freetype"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"github.com/mssola/user_agent"
|
||||
"hash/fnv"
|
||||
"image"
|
||||
"image/color"
|
||||
@@ -29,6 +20,17 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/golang/freetype"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"github.com/mssola/user_agent"
|
||||
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||
)
|
||||
|
||||
func InitUser(r *mux.Router) {
|
||||
@@ -127,14 +129,14 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
ruser, err := CreateUser(team, user)
|
||||
ruser, err := CreateUser(c.T, team, user)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if sendWelcomeEmail {
|
||||
sendWelcomeEmailAndForget(ruser.Id, ruser.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team), ruser.EmailVerified)
|
||||
sendWelcomeEmailAndForget(c.T, ruser.Id, ruser.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team), ruser.EmailVerified)
|
||||
}
|
||||
|
||||
w.Write([]byte(ruser.ToJson()))
|
||||
@@ -183,7 +185,7 @@ func IsVerifyHashRequired(user *model.User, team *model.Team, hash string) bool
|
||||
return shouldVerifyHash
|
||||
}
|
||||
|
||||
func CreateUser(team *model.Team, user *model.User) (*model.User, *model.AppError) {
|
||||
func CreateUser(T goi18n.TranslateFunc, team *model.Team, user *model.User) (*model.User, *model.AppError) {
|
||||
|
||||
channelRole := ""
|
||||
if team.Email == user.Email {
|
||||
@@ -218,7 +220,7 @@ func CreateUser(team *model.Team, user *model.User) (*model.User, *model.AppErro
|
||||
l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, err)
|
||||
}
|
||||
|
||||
addDirectChannelsAndForget(ruser)
|
||||
addDirectChannelsAndForget(T, ruser)
|
||||
|
||||
if user.EmailVerified {
|
||||
if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
|
||||
@@ -227,7 +229,7 @@ func CreateUser(team *model.Team, user *model.User) (*model.User, *model.AppErro
|
||||
}
|
||||
|
||||
pref := model.Preference{UserId: ruser.Id, Category: model.PREFERENCE_CATEGORY_TUTORIAL_STEPS, Name: ruser.Id, Value: "0"}
|
||||
if presult := <-Srv.Store.Preference().Save(&model.Preferences{pref}); presult.Err != nil {
|
||||
if presult := <-Srv.Store.Preference().Save(T, &model.Preferences{pref}); presult.Err != nil {
|
||||
l4g.Error("Encountered error saving tutorial preference, err=%v", presult.Err.Message)
|
||||
}
|
||||
|
||||
@@ -292,7 +294,7 @@ func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service
|
||||
user.TeamId = team.Id
|
||||
user.EmailVerified = true
|
||||
|
||||
ruser, err := CreateUser(team, user)
|
||||
ruser, err := CreateUser(c.T, team, user)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return nil
|
||||
@@ -306,7 +308,7 @@ func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service
|
||||
return ruser
|
||||
}
|
||||
|
||||
func sendWelcomeEmailAndForget(userId, email, teamName, teamDisplayName, siteURL, teamURL string, verified bool) {
|
||||
func sendWelcomeEmailAndForget(T goi18n.TranslateFunc, userId, email, teamName, teamDisplayName, siteURL, teamURL string, verified bool) {
|
||||
go func() {
|
||||
|
||||
subjectPage := NewServerTemplatePage("welcome_subject")
|
||||
@@ -326,7 +328,7 @@ func sendWelcomeEmailAndForget(userId, email, teamName, teamDisplayName, siteURL
|
||||
}()
|
||||
}
|
||||
|
||||
func addDirectChannelsAndForget(user *model.User) {
|
||||
func addDirectChannelsAndForget(T goi18n.TranslateFunc, user *model.User) {
|
||||
go func() {
|
||||
var profiles map[string]*model.User
|
||||
if result := <-Srv.Store.User().GetProfiles(user.TeamId); result.Err != nil {
|
||||
@@ -359,7 +361,7 @@ func addDirectChannelsAndForget(user *model.User) {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Preference().Save(&preferences); result.Err != nil {
|
||||
if result := <-Srv.Store.Preference().Save(T, &preferences); result.Err != nil {
|
||||
l4g.Error("Failed to add direct channel preferences for new user user_id=%s, eam_id=%s, err=%v", user.Id, user.TeamId, result.Err.Error())
|
||||
}
|
||||
}()
|
||||
@@ -883,7 +885,7 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
userChan := Srv.Store.User().Get(id)
|
||||
auditChan := Srv.Store.Audit().Get(id, 20)
|
||||
auditChan := Srv.Store.Audit().Get(c.T, id, 20)
|
||||
|
||||
if c.Err = (<-userChan).Err; c.Err != nil {
|
||||
return
|
||||
@@ -1450,7 +1452,7 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Preference().PermanentDeleteByUser(user.Id); result.Err != nil {
|
||||
if result := <-Srv.Store.Preference().PermanentDeleteByUser(c.T, user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
@@ -1466,7 +1468,7 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Audit().PermanentDeleteByUser(user.Id); result.Err != nil {
|
||||
if result := <-Srv.Store.Audit().PermanentDeleteByUser(c.T, user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user