[MM-55595] Use annotated logger in search layer (#25468)

This commit is contained in:
Ben Schumacher 2023-12-04 18:34:57 +01:00 committed by GitHub
parent 5a4dba8809
commit b2ec1ff8ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
130 changed files with 2107 additions and 1930 deletions

View File

@ -1149,7 +1149,7 @@ func (th *TestHelper) cleanupTestFile(info *model.FileInfo) error {
func (th *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
if cm, err := th.App.Srv().Store().Channel().GetMember(context.Background(), channel.Id, user.Id); err == nil {
cm.SchemeAdmin = true
if _, err = th.App.Srv().Store().Channel().UpdateMember(cm); err != nil {
if _, err = th.App.Srv().Store().Channel().UpdateMember(th.Context, cm); err != nil {
panic(err)
}
} else {
@ -1160,7 +1160,7 @@ func (th *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Chan
func (th *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
if tm, err := th.App.Srv().Store().Team().GetMember(th.Context, team.Id, user.Id); err == nil {
tm.SchemeAdmin = true
if _, err = th.App.Srv().Store().Team().UpdateMember(tm); err != nil {
if _, err = th.App.Srv().Store().Team().UpdateMember(th.Context, tm); err != nil {
panic(err)
}
} else {
@ -1171,7 +1171,7 @@ func (th *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team)
func (th *TestHelper) UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
if tm, err := th.App.Srv().Store().Team().GetMember(th.Context, team.Id, user.Id); err == nil {
tm.SchemeAdmin = false
if _, err = th.App.Srv().Store().Team().UpdateMember(tm); err != nil {
if _, err = th.App.Srv().Store().Team().UpdateMember(th.Context, tm); err != nil {
panic(err)
}
} else {

View File

@ -28,7 +28,7 @@ func purgeBleveIndexes(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := c.App.PurgeBleveIndexes(); err != nil {
if err := c.App.PurgeBleveIndexes(c.AppContext); err != nil {
c.Err = err
return
}

View File

@ -98,7 +98,7 @@ func patchBot(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
updatedBot, appErr := c.App.PatchBot(botUserId, botPatch)
updatedBot, appErr := c.App.PatchBot(c.AppContext, botUserId, botPatch)
if appErr != nil {
c.Err = appErr
return

View File

@ -49,7 +49,7 @@ func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := c.App.TestElasticsearch(cfg); err != nil {
if err := c.App.TestElasticsearch(c.AppContext, cfg); err != nil {
c.Err = err
return
}
@ -71,7 +71,7 @@ func purgeElasticsearchIndexes(c *Context, w http.ResponseWriter, r *http.Reques
return
}
if err := c.App.PurgeElasticsearchIndexes(); err != nil {
if err := c.App.PurgeElasticsearchIndexes(c.AppContext); err != nil {
c.Err = err
return
}

View File

@ -917,7 +917,7 @@ func TestGetFileLink(t *testing.T) {
CheckBadRequestStatus(t, resp)
// Hacky way to assign file to a post (usually would be done by CreatePost call)
err = th.App.Srv().Store().FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
err = th.App.Srv().Store().FileInfo().AttachToPost(th.Context, fileId, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
require.NoError(t, err)
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = false })
@ -1075,7 +1075,7 @@ func TestGetPublicFile(t *testing.T) {
fileId := fileResp.FileInfos[0].Id
// Hacky way to assign file to a post (usually would be done by CreatePost call)
err = th.App.Srv().Store().FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
err = th.App.Srv().Store().FileInfo().AttachToPost(th.Context, fileId, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
require.NoError(t, err)
info, err := th.App.Srv().Store().FileInfo().Get(fileId)
@ -1140,25 +1140,25 @@ func TestSearchFiles(t *testing.T) {
filename := "search for fileInfo1"
fileInfo1, appErr := th.App.UploadFile(th.Context, data, th.BasicChannel.Id, filename)
require.Nil(t, appErr)
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo1.Id, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
err = th.App.Srv().Store().FileInfo().AttachToPost(th.Context, fileInfo1.Id, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
require.NoError(t, err)
filename = "search for fileInfo2"
fileInfo2, appErr := th.App.UploadFile(th.Context, data, th.BasicChannel.Id, filename)
require.Nil(t, appErr)
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo2.Id, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
err = th.App.Srv().Store().FileInfo().AttachToPost(th.Context, fileInfo2.Id, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
require.NoError(t, err)
filename = "tagged search for fileInfo3"
fileInfo3, appErr := th.App.UploadFile(th.Context, data, th.BasicChannel.Id, filename)
require.Nil(t, appErr)
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo3.Id, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
err = th.App.Srv().Store().FileInfo().AttachToPost(th.Context, fileInfo3.Id, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
require.NoError(t, err)
filename = "tagged for fileInfo4"
fileInfo4, appErr := th.App.UploadFile(th.Context, data, th.BasicChannel.Id, filename)
require.Nil(t, appErr)
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo4.Id, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
err = th.App.Srv().Store().FileInfo().AttachToPost(th.Context, fileInfo4.Id, th.BasicPost.Id, th.BasicPost.ChannelId, th.BasicUser.Id)
require.NoError(t, err)
archivedChannel := th.CreatePublicChannel()
@ -1167,7 +1167,7 @@ func TestSearchFiles(t *testing.T) {
post := &model.Post{ChannelId: archivedChannel.Id, Message: model.NewId() + "a"}
rpost, _, err := client.CreatePost(context.Background(), post)
require.NoError(t, err)
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo5.Id, rpost.Id, rpost.ChannelId, th.BasicUser.Id)
err = th.App.Srv().Store().FileInfo().AttachToPost(th.Context, fileInfo5.Id, rpost.Id, rpost.ChannelId, th.BasicUser.Id)
require.NoError(t, err)
th.Client.DeleteChannel(context.Background(), archivedChannel.Id)

View File

@ -87,7 +87,7 @@ func applyIPFilters(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.License().IsCloud() {
portalUserCustomer, cErr := c.App.Cloud().GetCloudCustomer(c.AppContext.Session().UserId)
if cErr != nil {
mlog.Error("Failed to get portal user customer", mlog.Err(cErr))
c.Logger.Error("Failed to get portal user customer", mlog.Err(cErr))
}
if cErr == nil && portalUserCustomer != nil {
cloudWorkspaceOwnerEmailAddress = portalUserCustomer.Email
@ -97,17 +97,17 @@ func applyIPFilters(c *Context, w http.ResponseWriter, r *http.Request) {
go func() {
initiatingUser, err := c.App.Srv().Store().User().GetProfileByIds(context.Background(), []string{c.AppContext.Session().UserId}, nil, true)
if err != nil {
mlog.Error("Failed to get initiating user", mlog.Err(err))
c.Logger.Error("Failed to get initiating user", mlog.Err(err))
}
users, err := c.App.Srv().Store().User().GetSystemAdminProfiles()
if err != nil {
mlog.Error("Failed to get system admins", mlog.Err(err))
c.Logger.Error("Failed to get system admins", mlog.Err(err))
}
for _, user := range users {
if err = c.App.Srv().EmailService.SendIPFiltersChangedEmail(user.Email, initiatingUser[0], *c.App.Config().ServiceSettings.SiteURL, *c.App.Config().CloudSettings.CWSURL, user.Locale, cloudWorkspaceOwnerEmailAddress == user.Email); err != nil {
mlog.Error("Error while sending IP filters changed email", mlog.Err(err))
c.Logger.Error("Error while sending IP filters changed email", mlog.Err(err))
}
}
}()

View File

@ -2253,7 +2253,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
channelMember, err := th.App.Srv().Store().Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = 0
_, err = th.App.Srv().Store().Channel().UpdateMember(channelMember)
_, err = th.App.Srv().Store().Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
@ -2274,7 +2274,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
channelMember, err = th.App.Srv().Store().Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post1.CreateAt - 1
_, err = th.App.Srv().Store().Channel().UpdateMember(channelMember)
_, err = th.App.Srv().Store().Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
@ -2298,7 +2298,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
channelMember, err = th.App.Srv().Store().Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post6.CreateAt - 1
_, err = th.App.Srv().Store().Channel().UpdateMember(channelMember)
_, err = th.App.Srv().Store().Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
@ -2325,7 +2325,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
channelMember, err = th.App.Srv().Store().Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post10.CreateAt - 1
_, err = th.App.Srv().Store().Channel().UpdateMember(channelMember)
_, err = th.App.Srv().Store().Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
@ -2350,7 +2350,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
channelMember, err = th.App.Srv().Store().Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post10.CreateAt
_, err = th.App.Srv().Store().Channel().UpdateMember(channelMember)
_, err = th.App.Srv().Store().Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
@ -2389,7 +2389,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
channelMember, err = th.App.Srv().Store().Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post12.CreateAt - 1
_, err = th.App.Srv().Store().Channel().UpdateMember(channelMember)
_, err = th.App.Srv().Store().Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)

View File

@ -442,7 +442,7 @@ func TestGetChannelsForScheme(t *testing.T) {
assert.Zero(t, len(l2))
channel1.SchemeId = &scheme1.Id
channel1, err = th.App.Srv().Store().Channel().Update(channel1)
channel1, err = th.App.Srv().Store().Channel().Update(th.Context, channel1)
assert.NoError(t, err)
l3, _, err := th.SystemAdminClient.GetChannelsForScheme(context.Background(), scheme1.Id, 0, 100)

View File

@ -1130,7 +1130,7 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
profiles, appErr := c.App.SearchUsers(&props, options)
profiles, appErr := c.App.SearchUsers(c.AppContext, &props, options)
if appErr != nil {
c.Err = appErr
return
@ -1206,7 +1206,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
)
return
}
result, err := c.App.AutocompleteUsersInChannel(teamId, channelId, name, options)
result, err := c.App.AutocompleteUsersInChannel(c.AppContext, teamId, channelId, name, options)
if err != nil {
c.Err = err
return
@ -1215,7 +1215,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
autocomplete.Users = result.InChannel
autocomplete.OutOfChannel = result.OutOfChannel
} else if teamId != "" {
result, err := c.App.AutocompleteUsersInTeam(teamId, name, options)
result, err := c.App.AutocompleteUsersInTeam(c.AppContext, teamId, name, options)
if err != nil {
c.Err = err
return
@ -1223,7 +1223,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
autocomplete.Users = result.InTeam
} else {
result, err := c.App.SearchUsersInTeam("", name, options)
result, err := c.App.SearchUsersInTeam(c.AppContext, "", name, options)
if err != nil {
c.Err = err
return

View File

@ -6109,7 +6109,7 @@ func TestGetThreadsForUser(t *testing.T) {
require.NoError(t, err)
CheckCreatedStatus(t, resp)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{})
require.NoError(t, err)
@ -6126,7 +6126,7 @@ func TestGetThreadsForUser(t *testing.T) {
require.NoError(t, err)
CheckCreatedStatus(t, resp)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{})
require.NoError(t, err)
@ -6145,7 +6145,7 @@ func TestGetThreadsForUser(t *testing.T) {
require.NoError(t, err)
CheckCreatedStatus(t, resp)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
Extended: true,
@ -6167,7 +6167,7 @@ func TestGetThreadsForUser(t *testing.T) {
require.NoError(t, err)
CheckCreatedStatus(t, resp)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
Deleted: false,
@ -6224,7 +6224,7 @@ func TestGetThreadsForUser(t *testing.T) {
client := th.Client
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
rpost, resp, err := client.CreatePost(context.Background(), &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
require.NoError(t, err)
@ -6267,7 +6267,7 @@ func TestGetThreadsForUser(t *testing.T) {
require.NoError(t, err)
CheckCreatedStatus(t, resp)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{})
require.NoError(t, err)
@ -6289,7 +6289,7 @@ func TestGetThreadsForUser(t *testing.T) {
CheckCreatedStatus(t, resp)
}
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
Deleted: false,
@ -6316,7 +6316,7 @@ func TestGetThreadsForUser(t *testing.T) {
rootIdBefore := rootIds[14].Id
rootIdAfter := rootIds[16].Id
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
Deleted: false,
@ -6367,8 +6367,8 @@ func TestGetThreadsForUser(t *testing.T) {
CheckCreatedStatus(t, resp)
}
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id)
uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
Deleted: false,
@ -6403,8 +6403,8 @@ func TestGetThreadsForUser(t *testing.T) {
CheckCreatedStatus(t, resp)
}
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id)
uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
Deleted: false,
@ -6426,7 +6426,7 @@ func TestGetThreadsForUser(t *testing.T) {
})
t.Run("setting both threadsOnly, and totalsOnly params is not allowed", func(t *testing.T) {
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
_, resp, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
ThreadsOnly: true,
@ -6553,8 +6553,8 @@ func TestThreadSocketEvents(t *testing.T) {
replyPost, appErr := th.App.CreatePostAsUser(th.Context, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply @" + th.BasicUser.Username, UserId: th.BasicUser2.Id, RootId: rpost.Id}, th.Context.Session().Id, false)
require.Nil(t, appErr)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser2.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser2.Id)
t.Run("Listed for update event", func(t *testing.T) {
var caught bool
@ -6815,7 +6815,7 @@ func TestFollowThreads(t *testing.T) {
require.NoError(t, err)
CheckCreatedStatus(t, resp)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
var uss *model.Threads
uss, _, err = th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
Deleted: false,
@ -6914,8 +6914,8 @@ func TestMaintainUnreadRepliesInThread(t *testing.T) {
})
client := th.Client
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id)
// create a post by regular user
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
@ -6969,8 +6969,8 @@ func TestThreadCounts(t *testing.T) {
})
client := th.Client
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id)
// create a post by regular user
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
@ -6989,7 +6989,7 @@ func TestThreadCounts(t *testing.T) {
})
// delete first thread
th.App.Srv().Store().Post().Delete(rpost.Id, model.GetMillis(), th.BasicUser.Id)
th.App.Srv().Store().Post().Delete(th.Context, rpost.Id, model.GetMillis(), th.BasicUser.Id)
// we should now have 1 thread with 2 replies
checkThreadListReplies(t, th, th.Client, th.BasicUser.Id, 2, 1, &model.GetUserThreadsOpts{
@ -7020,8 +7020,8 @@ func TestSingleThreadGet(t *testing.T) {
client := th.Client
t.Run("get single thread", func(t *testing.T) {
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id)
// create a post by regular user
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
@ -7108,8 +7108,8 @@ func TestMaintainUnreadMentionsInThread(t *testing.T) {
return uss, resp
}
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id)
// create regular post
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
@ -7162,7 +7162,7 @@ func TestReadThreads(t *testing.T) {
_, resp, err = client.CreatePost(context.Background(), &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply", RootId: rpost.Id})
require.NoError(t, err)
CheckCreatedStatus(t, resp)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
var uss, uss2 *model.Threads
uss, _, err = th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
@ -7184,8 +7184,8 @@ func TestReadThreads(t *testing.T) {
})
t.Run("1 thread by timestamp", func(t *testing.T) {
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id)
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsgC1"})
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReplyC1", RootId: rpost.Id})
@ -7212,8 +7212,8 @@ func TestReadThreads(t *testing.T) {
})
t.Run("1 thread by post id", func(t *testing.T) {
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id)
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id)
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsgC1"})
reply1, _ := postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReplyC1", RootId: rpost.Id})

View File

@ -142,7 +142,7 @@ type AppIface interface {
// any ensureBotOptions hence it is not required for now.
// TODO: Once the focalboard migration completed, we should add this logic to the app and
// let plugin-api use the same code
EnsureBot(c request.CTX, productID string, bot *model.Bot) (string, error)
EnsureBot(rctx request.CTX, productID string, bot *model.Bot) (string, error)
// Expand announcements in incoming webhooks from Slack. Those announcements
// can be found in the text attribute, or in the pretext, text, title and value
// attributes of the attachment structure. The Slack attachment structure is
@ -273,7 +273,7 @@ type AppIface interface {
// so that it points to the URL (relative) of the emoji - static if emoji is default, /api if custom.
OverrideIconURLIfEmoji(c request.CTX, post *model.Post)
// PatchBot applies the given patch to the bot and corresponding user.
PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError)
PatchBot(rctx request.CTX, botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError)
// PatchChannelModerationsForChannel Updates a channels scheme roles based on a given ChannelModerationPatch, if the permissions match the higher scoped role the scheme is deleted.
PatchChannelModerationsForChannel(c request.CTX, channel *model.Channel, channelModerationsPatch []*model.ChannelModerationPatch) ([]*model.ChannelModeration, *model.AppError)
// Perform an HTTP POST request to an integration's action endpoint.
@ -434,8 +434,8 @@ type AppIface interface {
AutocompleteChannels(c request.CTX, userID, term string) (model.ChannelListWithTeamData, *model.AppError)
AutocompleteChannelsForSearch(c request.CTX, teamID string, userID string, term string) (model.ChannelList, *model.AppError)
AutocompleteChannelsForTeam(c request.CTX, teamID, userID, term string) (model.ChannelList, *model.AppError)
AutocompleteUsersInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError)
AutocompleteUsersInTeam(teamID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError)
AutocompleteUsersInChannel(rctx request.CTX, teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError)
AutocompleteUsersInTeam(rctx request.CTX, teamID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError)
BuildPostReactions(ctx request.CTX, postID string) (*[]ReactionImportData, *model.AppError)
BuildPushNotificationMessage(c request.CTX, contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string, explicitMention bool, channelWideMention bool, replyToThreadType string) (*model.PushNotification, *model.AppError)
BuildSamlMetadataObject(idpMetadata []byte) (*model.SamlMetadataResponse, *model.AppError)
@ -477,7 +477,7 @@ type AppIface interface {
Compliance() einterfaces.ComplianceInterface
Config() *model.Config
ConvertGroupMessageToChannel(c request.CTX, convertedByUserId string, gmConversionRequest *model.GroupMessageConversionRequestBody) (*model.Channel, *model.AppError)
CopyFileInfos(userID string, fileIDs []string) ([]string, *model.AppError)
CopyFileInfos(rctx request.CTX, userID string, fileIDs []string) ([]string, *model.AppError)
CreateChannel(c request.CTX, channel *model.Channel, addMember bool) (*model.Channel, *model.AppError)
CreateChannelWithUser(c request.CTX, channel *model.Channel, userID string) (*model.Channel, *model.AppError)
CreateCommand(cmd *model.Command) (*model.Command, *model.AppError)
@ -952,8 +952,8 @@ type AppIface interface {
ProcessSlackText(text string) string
Publish(message *model.WebSocketEvent)
PublishUserTyping(userID, channelID, parentId string) *model.AppError
PurgeBleveIndexes() *model.AppError
PurgeElasticsearchIndexes() *model.AppError
PurgeBleveIndexes(c request.CTX) *model.AppError
PurgeElasticsearchIndexes(c request.CTX) *model.AppError
QueryLogs(rctx request.CTX, page, perPage int, logFilter *model.LogFilter) (map[string][]string, *model.AppError)
ReadFile(path string) ([]byte, *model.AppError)
RecycleDatabaseConnection(rctx request.CTX)
@ -1027,10 +1027,10 @@ type AppIface interface {
SearchPrivateTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError)
SearchPublicTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError)
SearchUserAccessTokens(term string) ([]*model.UserAccessToken, *model.AppError)
SearchUsers(props *model.UserSearch, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchUsers(rctx request.CTX, props *model.UserSearch, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchUsersInChannel(channelID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchUsersInGroup(groupID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchUsersInTeam(teamID, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchUsersInTeam(rctx request.CTX, teamID, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchUsersNotInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchUsersNotInGroup(groupID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
SearchUsersNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
@ -1065,7 +1065,7 @@ type AppIface interface {
SetChannels(ch *Channels)
SetCustomStatus(c request.CTX, userID string, cs *model.CustomStatus) *model.AppError
SetDefaultProfileImage(c request.CTX, user *model.User) *model.AppError
SetFileSearchableContent(fileID string, data string) *model.AppError
SetFileSearchableContent(rctx request.CTX, fileID string, data string) *model.AppError
SetPhase2PermissionsMigrationStatus(isComplete bool) error
SetPluginKey(pluginID string, key string, value []byte) *model.AppError
SetPluginKeyWithExpiry(pluginID string, key string, value []byte, expireInSeconds int64) *model.AppError
@ -1096,7 +1096,7 @@ type AppIface interface {
SwitchOAuthToEmail(c request.CTX, email, password, requesterId string) (string, *model.AppError)
TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError)
TelemetryId() string
TestElasticsearch(cfg *model.Config) *model.AppError
TestElasticsearch(rctx request.CTX, cfg *model.Config) *model.AppError
TestEmail(rctx request.CTX, userID string, cfg *model.Config) *model.AppError
TestFileStoreConnection() *model.AppError
TestFileStoreConnectionWithConfig(cfg *model.FileSettings) *model.AppError

View File

@ -120,7 +120,7 @@ func (s *Server) configureAudit(adt *audit.Audit, bAllowAdvancedLogging bool) er
if err != nil {
return fmt.Errorf("invalid config source for audit, %w", err)
}
mlog.Debug("Loaded audit configuration", mlog.String("source", dsn))
s.Log().Debug("Loaded audit configuration", mlog.String("source", dsn))
} else {
s.Log().Debug("Advanced logging config not provided for audit")
}
@ -136,10 +136,10 @@ func (s *Server) configureAudit(adt *audit.Audit, bAllowAdvancedLogging bool) er
}
func (s *Server) onAuditTargetQueueFull(qname string, maxQSize int) bool {
mlog.Error("Audit queue full, dropping record.", mlog.String("qname", qname), mlog.Int("queueSize", maxQSize))
s.Log().Error("Audit queue full, dropping record.", mlog.String("qname", qname), mlog.Int("queueSize", maxQSize))
return true // drop it
}
func (s *Server) onAuditError(err error) {
mlog.Error("Audit Error", mlog.Err(err))
s.Log().Error("Audit Error", mlog.Err(err))
}

View File

@ -218,7 +218,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) {
// Clean up all posts from this user.
// There are some dummy messages like "user joined team" etc.
// which needs to be cleaned up.
require.NoError(t, th.GetSqlStore().Post().PermanentDeleteByUser(th.BasicUser.Id))
require.NoError(t, th.GetSqlStore().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id))
savedPost, err := th.App.CreatePost(th.Context, &model.Post{
ChannelId: channel.Id,

View File

@ -39,7 +39,7 @@ func (w *botServiceWrapper) EnsureBot(c request.CTX, productID string, bot *mode
// any ensureBotOptions hence it is not required for now.
// TODO: Once the focalboard migration completed, we should add this logic to the app and
// let plugin-api use the same code
func (a *App) EnsureBot(c request.CTX, productID string, bot *model.Bot) (string, error) {
func (a *App) EnsureBot(rctx request.CTX, productID string, bot *model.Bot) (string, error) {
if bot == nil {
return "", errors.New("passed a nil bot")
}
@ -64,7 +64,7 @@ func (a *App) EnsureBot(c request.CTX, productID string, bot *model.Bot) (string
Description: &bot.Description,
}
if _, err = a.PatchBot(botID, botPatch); err != nil {
if _, err = a.PatchBot(rctx, botID, botPatch); err != nil {
return "", fmt.Errorf("failed to patch bot: %w", err)
}
@ -78,7 +78,7 @@ func (a *App) EnsureBot(c request.CTX, productID string, bot *model.Bot) (string
return "", fmt.Errorf("failed to set plugin key: %w", err)
}
} else {
c.Logger().Error("Product attempted to use an account that already exists. Convert user to a bot "+
rctx.Logger().Error("Product attempted to use an account that already exists. Convert user to a bot "+
"account in the CLI by running 'mattermost user convert <username> --bot'. If the user is an "+
"existing user account you want to preserve, change its username and restart the Mattermost server, "+
"after which the plugin will create a bot account with that name. For more information about bot "+
@ -91,7 +91,7 @@ func (a *App) EnsureBot(c request.CTX, productID string, bot *model.Bot) (string
return user.Id, nil
}
createdBot, err := a.CreateBot(c, bot)
createdBot, err := a.CreateBot(rctx, bot)
if err != nil {
return "", fmt.Errorf("failed to create bot: %w", err)
}
@ -294,7 +294,7 @@ func (a *App) getOrCreateBot(botDef *model.Bot) (*model.Bot, *model.AppError) {
}
// PatchBot applies the given patch to the bot and corresponding user.
func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError) {
func (a *App) PatchBot(rctx request.CTX, botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError) {
bot, err := a.GetBot(botUserId, true)
if err != nil {
return nil, err
@ -323,7 +323,7 @@ func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot,
user.Email = patchedUser.Email
user.FirstName = patchedUser.FirstName
userUpdate, nErr := a.Srv().Store().User().Update(user, true)
userUpdate, nErr := a.Srv().Store().User().Update(rctx, user, true)
if nErr != nil {
var appErr *model.AppError
var invErr *store.ErrInvalidInput

View File

@ -131,7 +131,7 @@ func TestPatchBot(t *testing.T) {
Description: sToP("updated bot"),
}
_, err = th.App.PatchBot(bot.UserId, botPatch)
_, err = th.App.PatchBot(th.Context, bot.UserId, botPatch)
require.NotNil(t, err)
require.Equal(t, "model.user.is_valid.username.app_error", err.Id)
})
@ -154,7 +154,7 @@ func TestPatchBot(t *testing.T) {
Description: sToP(strings.Repeat("x", 1025)),
}
_, err = th.App.PatchBot(bot.UserId, botPatch)
_, err = th.App.PatchBot(th.Context, bot.UserId, botPatch)
require.NotNil(t, err)
require.Equal(t, "model.bot.is_valid.description.app_error", err.Id)
})
@ -180,7 +180,7 @@ func TestPatchBot(t *testing.T) {
Description: sToP("an updated bot"),
}
patchedBot, err := th.App.PatchBot(createdBot.UserId, botPatch)
patchedBot, err := th.App.PatchBot(th.Context, createdBot.UserId, botPatch)
require.Nil(t, err)
// patchedBot should create a new .UpdateAt time
@ -210,7 +210,7 @@ func TestPatchBot(t *testing.T) {
Username: sToP(th.BasicUser2.Username),
}
_, err = th.App.PatchBot(bot.UserId, botPatch)
_, err = th.App.PatchBot(th.Context, bot.UserId, botPatch)
require.NotNil(t, err)
require.Equal(t, "app.user.save.username_exists.app_error", err.Id)
})

View File

@ -503,7 +503,7 @@ func (a *App) createDirectChannel(c request.CTX, userID string, otherUserID stri
}
func (a *App) createDirectChannelWithUser(c request.CTX, user, otherUser *model.User, channelOptions ...model.ChannelOption) (*model.Channel, *model.AppError) {
channel, nErr := a.Srv().Store().Channel().CreateDirectChannel(user, otherUser, channelOptions...)
channel, nErr := a.Srv().Store().Channel().CreateDirectChannel(c, user, otherUser, channelOptions...)
if nErr != nil {
var invErr *store.ErrInvalidInput
var cErr *store.ErrConflict
@ -691,7 +691,7 @@ func (a *App) GetGroupChannel(c request.CTX, userIDs []string) (*model.Channel,
// UpdateChannel updates a given channel by its Id. It also publishes the CHANNEL_UPDATED event.
func (a *App) UpdateChannel(c request.CTX, channel *model.Channel) (*model.Channel, *model.AppError) {
_, err := a.Srv().Store().Channel().Update(channel)
_, err := a.Srv().Store().Channel().Update(c, channel)
if err != nil {
var appErr *model.AppError
var invErr *store.ErrInvalidInput
@ -1372,7 +1372,7 @@ func (a *App) UpdateChannelMemberNotifyProps(c request.CTX, data map[string]stri
}
func (a *App) updateChannelMember(c request.CTX, member *model.ChannelMember) (*model.ChannelMember, *model.AppError) {
member, err := a.Srv().Store().Channel().UpdateMember(member)
member, err := a.Srv().Store().Channel().UpdateMember(c, member)
if err != nil {
var appErr *model.AppError
var nfErr *store.ErrNotFound
@ -2526,7 +2526,7 @@ func (a *App) removeUserFromChannel(c request.CTX, userIDToRemove string, remove
return err
}
if err := a.Srv().Store().Channel().RemoveMember(channel.Id, userIDToRemove); err != nil {
if err := a.Srv().Store().Channel().RemoveMember(c, channel.Id, userIDToRemove); err != nil {
return model.NewAppError("removeUserFromChannel", "app.channel.remove_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
if err := a.Srv().Store().ChannelMemberHistory().LogLeaveEvent(userIDToRemove, channel.Id, model.GetMillis()); err != nil {
@ -2547,7 +2547,7 @@ func (a *App) removeUserFromChannel(c request.CTX, userIDToRemove string, remove
return model.NewAppError("removeUserFromChannel", "api.team.remove_user_from_team.missing.app_error", nil, "", http.StatusBadRequest).Wrap(err)
}
if err := a.ch.srv.teamService.RemoveTeamMember(teamMember); err != nil {
if err := a.ch.srv.teamService.RemoveTeamMember(c, teamMember); err != nil {
return model.NewAppError("removeUserFromChannel", "api.team.remove_user_from_team.missing.app_error", nil, "", http.StatusBadRequest).Wrap(err)
}
@ -2675,7 +2675,7 @@ func (a *App) ValidateUserPermissionsOnChannels(c request.CTX, userId string, ch
for _, channelId := range channelIds {
channel, err := a.GetChannel(c, channelId)
if err != nil {
mlog.Info("Invite users to team - couldn't get channel " + channelId)
c.Logger().Info("Invite users to team - couldn't get channel " + channelId)
continue
}
@ -2684,7 +2684,7 @@ func (a *App) ValidateUserPermissionsOnChannels(c request.CTX, userId string, ch
} else if channel.Type == model.ChannelTypeOpen && a.HasPermissionToChannel(c, userId, channelId, model.PermissionManagePublicChannelMembers) {
allowedChannelIds = append(allowedChannelIds, channelId)
} else {
mlog.Info("Invite users to team - no permission to add members to that channel. UserId: " + userId + " ChannelId: " + channelId)
c.Logger().Info("Invite users to team - no permission to add members to that channel. UserId: " + userId + " ChannelId: " + channelId)
}
}
return allowedChannelIds
@ -2852,7 +2852,7 @@ func (a *App) AutocompleteChannels(c request.CTX, userID, term string) (model.Ch
return nil, appErr
}
channelList, err := a.Srv().Store().Channel().Autocomplete(userID, term, includeDeleted, user.IsGuest())
channelList, err := a.Srv().Store().Channel().Autocomplete(c, userID, term, includeDeleted, user.IsGuest())
if err != nil {
return nil, model.NewAppError("AutocompleteChannels", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -2869,7 +2869,7 @@ func (a *App) AutocompleteChannelsForTeam(c request.CTX, teamID, userID, term st
return nil, appErr
}
channelList, err := a.Srv().Store().Channel().AutocompleteInTeam(teamID, userID, term, includeDeleted, user.IsGuest())
channelList, err := a.Srv().Store().Channel().AutocompleteInTeam(c, teamID, userID, term, includeDeleted, user.IsGuest())
if err != nil {
return nil, model.NewAppError("AutocompleteChannels", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -3064,11 +3064,11 @@ func (a *App) ViewChannel(c request.CTX, view *model.ChannelView, userID string,
}
func (a *App) PermanentDeleteChannel(c request.CTX, channel *model.Channel) *model.AppError {
if err := a.Srv().Store().Post().PermanentDeleteByChannel(channel.Id); err != nil {
if err := a.Srv().Store().Post().PermanentDeleteByChannel(c, channel.Id); err != nil {
return model.NewAppError("PermanentDeleteChannel", "app.post.permanent_delete_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
if err := a.Srv().Store().Channel().PermanentDeleteMembersByChannel(channel.Id); err != nil {
if err := a.Srv().Store().Channel().PermanentDeleteMembersByChannel(c, channel.Id); err != nil {
return model.NewAppError("PermanentDeleteChannel", "app.channel.remove_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -3086,7 +3086,7 @@ func (a *App) PermanentDeleteChannel(c request.CTX, channel *model.Channel) *mod
deleteAt := model.GetMillis()
if nErr := a.Srv().Store().Channel().PermanentDelete(channel.Id); nErr != nil {
if nErr := a.Srv().Store().Channel().PermanentDelete(c, channel.Id); nErr != nil {
return model.NewAppError("PermanentDeleteChannel", "app.channel.permanent_delete.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
}
@ -3101,7 +3101,7 @@ func (a *App) PermanentDeleteChannel(c request.CTX, channel *model.Channel) *mod
}
func (a *App) RemoveAllDeactivatedMembersFromChannel(c request.CTX, channel *model.Channel) *model.AppError {
err := a.Srv().Store().Channel().RemoveAllDeactivatedMembers(channel.Id)
err := a.Srv().Store().Channel().RemoveAllDeactivatedMembers(c, channel.Id)
if err != nil {
return model.NewAppError("RemoveAllDeactivatedMembersFromChannel", "app.channel.remove_all_deactivated_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -3160,7 +3160,7 @@ func (a *App) MoveChannel(c request.CTX, team *model.Team, channel *model.Channe
}
channel.TeamId = team.Id
if _, err := a.Srv().Store().Channel().Update(channel); err != nil {
if _, err := a.Srv().Store().Channel().Update(c, channel); err != nil {
var appErr *model.AppError
var invErr *store.ErrInvalidInput
switch {
@ -3594,7 +3594,7 @@ func (a *App) setSidebarCategoriesForConvertedGroupMessage(c request.CTX, gmConv
})
if appErr != nil {
mlog.Error("Failed to search sidebar categories for user for adding converted GM")
c.Logger().Error("Failed to search sidebar categories for user for adding converted GM")
continue
}
@ -3613,7 +3613,7 @@ func (a *App) setSidebarCategoriesForConvertedGroupMessage(c request.CTX, gmConv
channelsCategory := categories.Categories[0]
_, appErr = a.UpdateSidebarCategories(c, user.Id, gmConversionRequest.TeamID, []*model.SidebarCategoryWithChannels{channelsCategory})
if appErr != nil {
mlog.Error("Failed to add converted GM to default sidebar category for user", mlog.String("user_id", user.Id), mlog.Err(err))
c.Logger().Error("Failed to add converted GM to default sidebar category for user", mlog.String("user_id", user.Id), mlog.Err(err))
}
}
@ -3708,7 +3708,7 @@ func (a *App) postMessageForConvertGroupMessageToChannel(c request.CTX, channelI
}
if _, appErr := a.CreatePost(c, post, channel, false, true); appErr != nil {
mlog.Error("Failed to create post for notifying about GM converted to private channel", mlog.Err(appErr))
c.Logger().Error("Failed to create post for notifying about GM converted to private channel", mlog.Err(appErr))
return model.NewAppError(
"postMessageForConvertGroupMessageToChannel",

View File

@ -2537,13 +2537,13 @@ func TestConvertGroupMessageToChannel(t *testing.T) {
UpdateAt: time.Now().Unix(),
Type: model.ChannelTypeGroup,
}, nil)
mockChannelStore.On("Update", mock.AnythingOfType("*model.Channel")).Return(&model.Channel{}, nil)
mockChannelStore.On("Update", mock.AnythingOfType("*request.Context"), mock.AnythingOfType("*model.Channel")).Return(&model.Channel{}, nil)
mockChannelStore.On("InvalidateChannel", "channelidchannelidchanneli")
mockChannelStore.On("InvalidateChannelByName", "team_id_1", "new_name").Times(1)
mockChannelStore.On("InvalidateChannelByName", "dm", "")
mockChannelStore.On("GetMember", sqlstore.WithMaster(context.Background()), "channelidchannelidchanneli", "user_id_1").Return(&model.ChannelMember{}, nil).Times(1)
mockChannelStore.On("GetMember", context.Background(), "channelidchannelidchanneli", "user_id_1").Return(&model.ChannelMember{}, nil).Times(2)
mockChannelStore.On("UpdateMember", mock.AnythingOfType("*model.ChannelMember")).Return(&model.ChannelMember{UserId: "user_id_1"}, nil)
mockChannelStore.On("UpdateMember", mock.AnythingOfType("*request.Context"), mock.AnythingOfType("*model.ChannelMember")).Return(&model.ChannelMember{UserId: "user_id_1"}, nil)
mockChannelStore.On("InvalidateAllChannelMembersForUser", "user_id_1").Return()
mockChannelStore.On("InvalidatePinnedPostCount", "channelidchannelidchanneli")
mockChannelStore.On("GetAllChannelMembersNotifyPropsForChannel", "channelidchannelidchanneli", true).Return(map[string]model.StringMap{}, nil)

View File

@ -14,7 +14,7 @@ import (
func (s *Server) clusterInstallPluginHandler(msg *model.ClusterMessage) {
var data model.PluginEventData
if jsonErr := json.Unmarshal(msg.Data, &data); jsonErr != nil {
mlog.Warn("Failed to decode from JSON", mlog.Err(jsonErr))
s.Log().Warn("Failed to decode from JSON", mlog.Err(jsonErr))
}
s.Channels().installPluginFromClusterMessage(data.Id)
}
@ -22,14 +22,14 @@ func (s *Server) clusterInstallPluginHandler(msg *model.ClusterMessage) {
func (s *Server) clusterRemovePluginHandler(msg *model.ClusterMessage) {
var data model.PluginEventData
if jsonErr := json.Unmarshal(msg.Data, &data); jsonErr != nil {
mlog.Warn("Failed to decode from JSON", mlog.Err(jsonErr))
s.Log().Warn("Failed to decode from JSON", mlog.Err(jsonErr))
}
s.Channels().removePluginFromClusterMessage(data.Id)
}
func (s *Server) clusterPluginEventHandler(msg *model.ClusterMessage) {
if msg.Props == nil {
mlog.Warn("ClusterMessage.Props for plugin event should not be nil")
s.Log().Warn("ClusterMessage.Props for plugin event should not be nil")
return
}
pluginID := msg.Props["PluginID"]
@ -39,8 +39,10 @@ func (s *Server) clusterPluginEventHandler(msg *model.ClusterMessage) {
}
eventID := msg.Props["EventID"]
if pluginID == "" || eventID == "" {
mlog.Warn("Invalid ClusterMessage.Props values for plugin event",
mlog.String("plugin_id", pluginID), mlog.String("event_id", eventID))
s.Log().Warn("Invalid ClusterMessage.Props values for plugin event",
mlog.String("plugin_id", pluginID),
mlog.String("event_id", eventID),
)
return
}
@ -51,7 +53,7 @@ func (s *Server) clusterPluginEventHandler(msg *model.ClusterMessage) {
hooks, err := channels.HooksForPluginOrProduct(pluginID)
if err != nil {
mlog.Warn("Getting hooks for plugin failed", mlog.String("plugin_id", pluginID), mlog.Err(err))
s.Log().Warn("Getting hooks for plugin failed", mlog.String("plugin_id", pluginID), mlog.Err(err))
return
}

View File

@ -547,7 +547,7 @@ func (a *App) HandleCommandResponse(c request.CTX, command *model.Command, args
_, err := a.HandleCommandResponsePost(c, command, args, response, builtIn)
if err != nil {
mlog.Debug("Error occurred in handling command response post", mlog.Err(err))
c.Logger().Debug("Error occurred in handling command response post", mlog.Err(err))
lastError = err
}
@ -556,7 +556,7 @@ func (a *App) HandleCommandResponse(c request.CTX, command *model.Command, args
_, err := a.HandleCommandResponsePost(c, command, args, resp, builtIn)
if err != nil {
mlog.Debug("Error occurred in handling command response post", mlog.Err(err))
c.Logger().Debug("Error occurred in handling command response post", mlog.Err(err))
lastError = err
}
}

View File

@ -93,7 +93,7 @@ func TestCheckPendingNotifications(t *testing.T) {
channelMember, err := th.store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
require.NoError(t, err)
channelMember.LastViewedAt = 9999999
_, err = th.store.Channel().UpdateMember(channelMember)
_, err = th.store.Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
nErr := th.store.Preference().Save(model.Preferences{{
@ -114,7 +114,7 @@ func TestCheckPendingNotifications(t *testing.T) {
channelMember, err = th.store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
require.NoError(t, err)
channelMember.LastViewedAt = 10001000
_, err = th.store.Channel().UpdateMember(channelMember)
_, err = th.store.Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
// We reset the interval to something shorter
@ -208,7 +208,7 @@ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
channelMember, err := th.store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
require.NoError(t, err)
channelMember.LastViewedAt = 9999000
_, err = th.store.Channel().UpdateMember(channelMember)
_, err = th.store.Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
@ -250,7 +250,7 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
channelMember, err := th.store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
require.NoError(t, err)
channelMember.LastViewedAt = 9999000
_, err = th.store.Channel().UpdateMember(channelMember)
_, err = th.store.Channel().UpdateMember(th.Context, channelMember)
require.NoError(t, err)
// preference value is not an integer, so we'll fall back to the default 15min value

View File

@ -4,7 +4,6 @@
package email
import (
"bytes"
"os"
"path/filepath"
"testing"
@ -12,6 +11,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin/plugintest/mock"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/app/users"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
@ -32,7 +32,8 @@ type TestHelper struct {
BasicUser2 *model.User
SystemAdminUser *model.User
LogBuffer *bytes.Buffer
Context request.CTX
}
func Setup(tb testing.TB) *TestHelper {
@ -132,8 +133,8 @@ func setupTestHelper(s store.Store, tb testing.TB) *TestHelper {
service: service,
configStore: configStore,
store: s,
LogBuffer: &bytes.Buffer{},
workspace: tempWorkspace,
Context: request.TestContext(tb),
}
}

View File

@ -176,8 +176,8 @@ func (a *App) DeleteEmoji(c request.CTX, emoji *model.Emoji) *model.AppError {
}
}
a.deleteEmojiImage(emoji.Id)
a.deleteReactionsForEmoji(emoji.Name)
a.deleteEmojiImage(c, emoji.Id)
a.deleteReactionsForEmoji(c, emoji.Name)
return nil
}
@ -355,14 +355,14 @@ func imageToPaletted(img image.Image) *image.Paletted {
return pm
}
func (a *App) deleteEmojiImage(id string) {
func (a *App) deleteEmojiImage(rctx request.CTX, id string) {
if err := a.MoveFile(getEmojiImagePath(id), "emoji/"+id+"/image_deleted"); err != nil {
mlog.Warn("Failed to rename image when deleting emoji", mlog.String("emoji_id", id))
rctx.Logger().Warn("Failed to rename image when deleting emoji", mlog.String("emoji_id", id))
}
}
func (a *App) deleteReactionsForEmoji(emojiName string) {
func (a *App) deleteReactionsForEmoji(rctx request.CTX, emojiName string) {
if err := a.Srv().Store().Reaction().DeleteAllWithEmojiName(emojiName); err != nil {
mlog.Warn("Unable to delete reactions when deleting emoji", mlog.String("emoji_name", emojiName), mlog.Err(err))
rctx.Logger().Warn("Unable to delete reactions when deleting emoji", mlog.String("emoji_name", emojiName), mlog.Err(err))
}
}

View File

@ -672,7 +672,7 @@ func TestBuildPostReplies(t *testing.T) {
createPostWithAttachments := func(th *TestHelper, n int, rootID string) *model.Post {
var fileIDs []string
for i := 0; i < n; i++ {
info, err := th.App.Srv().Store().FileInfo().Save(&model.FileInfo{
info, err := th.App.Srv().Store().FileInfo().Save(th.Context, &model.FileInfo{
CreatorId: th.BasicUser.Id,
Name: fmt.Sprintf("file%d", i),
Path: fmt.Sprintf("/data/file%d", i),

View File

@ -505,7 +505,7 @@ func (a *App) MigrateFilenamesToFileInfos(rctx request.CTX, post *model.Post) []
savedInfos := make([]*model.FileInfo, 0, len(infos))
fileIDs := make([]string, 0, len(filenames))
for _, info := range infos {
if _, nErr = a.Srv().Store().FileInfo().Save(info); nErr != nil {
if _, nErr = a.Srv().Store().FileInfo().Save(rctx, info); nErr != nil {
rctx.Logger().Error(
"Unable to save file info when migrating post to use FileInfos",
mlog.String("post_id", post.Id),
@ -527,7 +527,7 @@ func (a *App) MigrateFilenamesToFileInfos(rctx request.CTX, post *model.Post) []
newPost.FileIds = fileIDs
// Update Posts to clear Filenames and set FileIds
if _, nErr = a.Srv().Store().Post().Update(newPost, post); nErr != nil {
if _, nErr = a.Srv().Store().Post().Update(rctx, newPost, post); nErr != nil {
rctx.Logger().Error(
"Unable to save migrated post when migrating to use FileInfos",
mlog.String("new_file_ids", strings.Join(newPost.FileIds, ",")),
@ -678,7 +678,7 @@ type UploadFileTask struct {
// Testing: overridable dependency functions
pluginsEnvironment *plugin.Environment
writeFile func(io.Reader, string) (int64, *model.AppError)
saveToDatabase func(*model.FileInfo) (*model.FileInfo, error)
saveToDatabase func(request.CTX, *model.FileInfo) (*model.FileInfo, error)
imgDecoder *imaging.Decoder
imgEncoder *imaging.Encoder
@ -722,7 +722,7 @@ func (t *UploadFileTask) init(a *App) {
// contained the last "good" FileInfo before the execution of that plugin.
func (a *App) UploadFileX(c request.CTX, channelID, name string, input io.Reader,
opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError) {
c.WithLogger(c.Logger().With(
c = c.WithLogger(c.Logger().With(
mlog.String("file_name", name),
))
@ -791,7 +791,7 @@ func (a *App) UploadFileX(c request.CTX, channelID, name string, input io.Reader
t.postprocessImage(file)
}
if _, err := t.saveToDatabase(t.fileinfo); err != nil {
if _, err := t.saveToDatabase(c, t.fileinfo); err != nil {
var appErr *model.AppError
switch {
case errors.As(err, &appErr):
@ -1042,7 +1042,7 @@ func (a *App) DoUploadFileExpectModification(c request.CTX, now time.Time, rawTe
return nil, data, err
}
if _, err := a.Srv().Store().FileInfo().Save(info); err != nil {
if _, err := a.Srv().Store().FileInfo().Save(c, info); err != nil {
var appErr *model.AppError
switch {
case errors.As(err, &appErr):
@ -1177,7 +1177,7 @@ func (a *App) generateMiniPreview(rctx request.CTX, fi *model.FileInfo) {
} else {
fi.MiniPreview = &miniPreview
}
if _, err = a.Srv().Store().FileInfo().Upsert(fi); err != nil {
if _, err = a.Srv().Store().FileInfo().Upsert(rctx, fi); err != nil {
rctx.Logger().Debug("Creating mini preview failed", mlog.Err(err))
} else {
a.Srv().Store().FileInfo().InvalidateFileInfosForPostCache(fi.PostId, false)
@ -1230,13 +1230,13 @@ func (a *App) GetFileInfo(rctx request.CTX, fileID string) (*model.FileInfo, *mo
return fileInfo, appErr
}
func (a *App) SetFileSearchableContent(fileID string, data string) *model.AppError {
func (a *App) SetFileSearchableContent(rctx request.CTX, fileID string, data string) *model.AppError {
fileInfo, appErr := a.Srv().getFileInfo(fileID)
if appErr != nil {
return appErr
}
err := a.Srv().Store().FileInfo().SetContent(fileInfo.Id, data)
err := a.Srv().Store().FileInfo().SetContent(rctx, fileInfo.Id, data)
if err != nil {
var nfErr *store.ErrNotFound
switch {
@ -1317,7 +1317,7 @@ func (a *App) getFileIgnoreCloudLimit(rctx request.CTX, fileID string) ([]byte,
return data, nil
}
func (a *App) CopyFileInfos(userID string, fileIDs []string) ([]string, *model.AppError) {
func (a *App) CopyFileInfos(rctx request.CTX, userID string, fileIDs []string) ([]string, *model.AppError) {
var newFileIds []string
now := model.GetMillis()
@ -1341,7 +1341,7 @@ func (a *App) CopyFileInfos(userID string, fileIDs []string) ([]string, *model.A
fileInfo.PostId = ""
fileInfo.ChannelId = ""
if _, err := a.Srv().Store().FileInfo().Save(fileInfo); err != nil {
if _, err := a.Srv().Store().FileInfo().Save(rctx, fileInfo); err != nil {
var appErr *model.AppError
switch {
case errors.As(err, &appErr):
@ -1428,8 +1428,8 @@ func (a *App) SearchFilesInTeamForUser(c request.CTX, terms string, userId strin
params.ExcludedChannels = a.convertChannelNamesToChannelIds(c, params.ExcludedChannels, userId, teamId, includeDeletedChannels)
// Convert usernames to user IDs
params.FromUsers = a.convertUserNameToUserIds(params.FromUsers)
params.ExcludedUsers = a.convertUserNameToUserIds(params.ExcludedUsers)
params.FromUsers = a.convertUserNameToUserIds(c, params.FromUsers)
params.ExcludedUsers = a.convertUserNameToUserIds(c, params.ExcludedUsers)
finalParamsList = append(finalParamsList, params)
}
@ -1440,7 +1440,7 @@ func (a *App) SearchFilesInTeamForUser(c request.CTX, terms string, userId strin
return model.NewFileInfoList(), nil
}
fileInfoSearchResults, nErr := a.Srv().Store().FileInfo().Search(finalParamsList, userId, teamId, page, perPage)
fileInfoSearchResults, nErr := a.Srv().Store().FileInfo().Search(c, finalParamsList, userId, teamId, page, perPage)
if nErr != nil {
var appErr *model.AppError
switch {
@ -1475,7 +1475,7 @@ func (a *App) ExtractContentFromFileInfo(rctx request.CTX, fileInfo *model.FileI
if len(text) > maxContentExtractionSize {
text = text[0:maxContentExtractionSize]
}
if storeErr := a.Srv().Store().FileInfo().SetContent(fileInfo.Id, text); storeErr != nil {
if storeErr := a.Srv().Store().FileInfo().SetContent(rctx, fileInfo.Id, text); storeErr != nil {
return errors.Wrap(storeErr, "failed to save the extracted file content")
}
reloadFileInfo, storeErr := a.Srv().Store().FileInfo().Get(fileInfo.Id)

View File

@ -87,7 +87,7 @@ func BenchmarkUploadFile(b *testing.B) {
if err != nil {
b.Fatal(err)
}
th.App.Srv().Store().FileInfo().PermanentDelete(info1.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info1.Id)
th.App.RemoveFile(info1.Path)
},
},
@ -105,7 +105,7 @@ func BenchmarkUploadFile(b *testing.B) {
if aerr != nil {
b.Fatal(aerr)
}
th.App.Srv().Store().FileInfo().PermanentDelete(info.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info.Id)
th.App.RemoveFile(info.Path)
},
},
@ -123,7 +123,7 @@ func BenchmarkUploadFile(b *testing.B) {
if aerr != nil {
b.Fatal(aerr)
}
th.App.Srv().Store().FileInfo().PermanentDelete(info.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info.Id)
th.App.RemoveFile(info.Path)
},
},
@ -140,7 +140,7 @@ func BenchmarkUploadFile(b *testing.B) {
if aerr != nil {
b.Fatal(aerr)
}
th.App.Srv().Store().FileInfo().PermanentDelete(info.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info.Id)
th.App.RemoveFile(info.Path)
},
},
@ -157,7 +157,7 @@ func BenchmarkUploadFile(b *testing.B) {
if aerr != nil {
b.Fatal(aerr)
}
th.App.Srv().Store().FileInfo().PermanentDelete(info.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info.Id)
th.App.RemoveFile(info.Path)
},
},

View File

@ -60,7 +60,7 @@ func TestDoUploadFile(t *testing.T) {
info1, err := th.App.DoUploadFile(th.Context, time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
require.Nil(t, err, "DoUploadFile should succeed with valid data")
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(info1.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info1.Id)
th.App.RemoveFile(info1.Path)
}()
@ -70,7 +70,7 @@ func TestDoUploadFile(t *testing.T) {
info2, err := th.App.DoUploadFile(th.Context, time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
require.Nil(t, err, "DoUploadFile should succeed with valid data")
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(info2.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info2.Id)
th.App.RemoveFile(info2.Path)
}()
@ -80,7 +80,7 @@ func TestDoUploadFile(t *testing.T) {
info3, err := th.App.DoUploadFile(th.Context, time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
require.Nil(t, err, "DoUploadFile should succeed with valid data")
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(info3.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info3.Id)
th.App.RemoveFile(info3.Path)
}()
@ -90,7 +90,7 @@ func TestDoUploadFile(t *testing.T) {
info4, err := th.App.DoUploadFile(th.Context, time.Date(2009, 3, 5, 1, 2, 3, 4, time.Local), "../../"+teamID, "../../"+channelID, "../../"+userID, "../../"+filename, data)
require.Nil(t, err, "DoUploadFile should succeed with valid data")
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(info4.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info4.Id)
th.App.RemoveFile(info4.Path)
}()
@ -117,7 +117,7 @@ func TestUploadFile(t *testing.T) {
info1, err = th.App.UploadFile(th.Context, data, channelID, filename)
require.Nil(t, err, "UploadFile should succeed with valid data")
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(info1.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info1.Id)
th.App.RemoveFile(info1.Path)
}()
@ -348,17 +348,17 @@ func TestCopyFileInfos(t *testing.T) {
info1, err := th.App.DoUploadFile(th.Context, time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
require.Nil(t, err)
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(info1.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info1.Id)
th.App.RemoveFile(info1.Path)
}()
infoIds, err := th.App.CopyFileInfos(userID, []string{info1.Id})
infoIds, err := th.App.CopyFileInfos(th.Context, userID, []string{info1.Id})
require.Nil(t, err)
info2, err := th.App.GetFileInfo(th.Context, infoIds[0])
require.Nil(t, err)
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(info2.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info2.Id)
th.App.RemoveFile(info2.Path)
}()
@ -404,15 +404,16 @@ func TestSearchFilesInTeamForUser(t *testing.T) {
fileInfos := make([]*model.FileInfo, 7)
for i := 0; i < cap(fileInfos); i++ {
fileInfo, err := th.App.Srv().Store().FileInfo().Save(&model.FileInfo{
CreatorId: th.BasicUser.Id,
PostId: th.BasicPost.Id,
ChannelId: th.BasicPost.ChannelId,
Name: searchTerm,
Path: searchTerm,
Extension: "jpg",
MimeType: "image/jpeg",
})
fileInfo, err := th.App.Srv().Store().FileInfo().Save(th.Context,
&model.FileInfo{
CreatorId: th.BasicUser.Id,
PostId: th.BasicPost.Id,
ChannelId: th.BasicPost.ChannelId,
Name: searchTerm,
Path: searchTerm,
Extension: "jpg",
MimeType: "image/jpeg",
})
time.Sleep(1 * time.Millisecond)
require.NoError(t, err)
@ -693,22 +694,23 @@ func TestSetFileSearchableContent(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
fileInfo, err := th.App.Srv().Store().FileInfo().Save(&model.FileInfo{
CreatorId: th.BasicUser.Id,
PostId: th.BasicPost.Id,
ChannelId: th.BasicPost.ChannelId,
Name: "test",
Path: "test",
Extension: "jpg",
MimeType: "image/jpeg",
})
fileInfo, err := th.App.Srv().Store().FileInfo().Save(th.Context,
&model.FileInfo{
CreatorId: th.BasicUser.Id,
PostId: th.BasicPost.Id,
ChannelId: th.BasicPost.ChannelId,
Name: "test",
Path: "test",
Extension: "jpg",
MimeType: "image/jpeg",
})
require.NoError(t, err)
result, appErr := th.App.SearchFilesInTeamForUser(th.Context, "searchable", th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, 0, 60)
require.Nil(t, appErr)
assert.Equal(t, 0, len(result.Order))
appErr = th.App.SetFileSearchableContent(fileInfo.Id, "searchable")
appErr = th.App.SetFileSearchableContent(th.Context, fileInfo.Id, "searchable")
require.Nil(t, appErr)
result, appErr = th.App.SearchFilesInTeamForUser(th.Context, "searchable", th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, 0, 60)

View File

@ -1216,7 +1216,7 @@ func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, po
fileIDs := a.uploadAttachments(rctx, replyData.Attachments, reply, teamID)
for _, fileID := range reply.FileIds {
if _, ok := fileIDs[fileID]; !ok {
a.Srv().Store().FileInfo().PermanentDelete(fileID)
a.Srv().Store().FileInfo().PermanentDelete(rctx, fileID)
}
}
reply.FileIds = make([]string, 0)
@ -1519,7 +1519,7 @@ func (a *App) importMultiplePostLines(rctx request.CTX, lines []imports.LineImpo
fileIDs := a.uploadAttachments(rctx, line.Post.Attachments, post, team.Id)
for _, fileID := range post.FileIds {
if _, ok := fileIDs[fileID]; !ok {
a.Srv().Store().FileInfo().PermanentDelete(fileID)
a.Srv().Store().FileInfo().PermanentDelete(rctx, fileID)
}
}
post.FileIds = make([]string, 0)
@ -1642,7 +1642,7 @@ func (a *App) uploadAttachments(rctx request.CTX, attachments *[]imports.Attachm
func (a *App) updateFileInfoWithPostId(rctx request.CTX, post *model.Post) {
for _, fileID := range post.FileIds {
if err := a.Srv().Store().FileInfo().AttachToPost(fileID, post.Id, post.ChannelId, post.UserId); err != nil {
if err := a.Srv().Store().FileInfo().AttachToPost(rctx, fileID, post.Id, post.ChannelId, post.UserId); err != nil {
rctx.Logger().Error("Error attaching files to post.", mlog.String("post_id", post.Id), mlog.Array("post_file_ids", post.FileIds), mlog.Err(err))
}
}
@ -1718,7 +1718,7 @@ func (a *App) importDirectChannel(rctx request.CTX, data *imports.DirectChannelI
if data.Header != nil {
channel.Header = *data.Header
if _, appErr := a.Srv().Store().Channel().Update(channel); appErr != nil {
if _, appErr := a.Srv().Store().Channel().Update(rctx, channel); appErr != nil {
return model.NewAppError("BulkImport", "app.import.import_direct_channel.update_header_failed.error", nil, "", http.StatusBadRequest).Wrap(appErr)
}
}
@ -1832,7 +1832,7 @@ func (a *App) importMultipleDirectPostLines(rctx request.CTX, lines []imports.Li
fileIDs := a.uploadAttachments(rctx, line.DirectPost.Attachments, post, "noteam")
for _, fileID := range post.FileIds {
if _, ok := fileIDs[fileID]; !ok {
a.Srv().Store().FileInfo().PermanentDelete(fileID)
a.Srv().Store().FileInfo().PermanentDelete(rctx, fileID)
}
}
post.FileIds = make([]string, 0)

View File

@ -456,7 +456,7 @@ func (a *App) doLocalWarnMetricsRequest(c request.CTX, rawURL string, upstreamRe
license := a.Srv().License()
if license != nil {
mlog.Debug("License is present, skip this call")
c.Logger().Debug("License is present, skip this call")
return nil
}
@ -554,7 +554,7 @@ func (a *App) buildWarnMetricMailtoLink(rctx request.CTX, warnMetricId string, u
registeredUsersCount, err := a.Srv().Store().User().Count(model.UserCountOptions{})
if err != nil {
mlog.Warn("Error retrieving the number of registered users", mlog.Err(err))
rctx.Logger().Warn("Error retrieving the number of registered users", mlog.Err(err))
} else {
mailBody += i18n.T("api.server.warn_metric.bot_response.mailto_registered_users_header", map[string]any{"NoRegisteredUsers": registeredUsersCount})
mailBody += "\r\n"

View File

@ -72,7 +72,7 @@ func (a *App) AuthenticateUserForLogin(c request.CTX, id, loginId, password, mfa
}
token, err := a.Srv().Store().Token().GetByToken(cwsToken)
if nfErr := new(store.ErrNotFound); err != nil && !errors.As(err, &nfErr) {
mlog.Debug("Error retrieving the cws token from the store", mlog.Err(err))
c.Logger().Debug("Error retrieving the cws token from the store", mlog.Err(err))
return nil, model.NewAppError("AuthenticateUserForLogin",
"api.user.login_by_cws.invalid_token.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -90,7 +90,7 @@ func (a *App) AuthenticateUserForLogin(c request.CTX, id, loginId, password, mfa
}
err := a.Srv().Store().Token().Save(token)
if err != nil {
mlog.Debug("Error storing the cws token in the store", mlog.Err(err))
c.Logger().Debug("Error storing the cws token in the store", mlog.Err(err))
return nil, model.NewAppError("AuthenticateUserForLogin",
"api.user.login_by_cws.invalid_token.app_error", nil, "", http.StatusInternalServerError)
}

View File

@ -139,7 +139,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
go func() {
_, err := a.sendOutOfChannelMentions(c, sender, post, channel, mentions.OtherPotentialMentions)
if err != nil {
mlog.Error("Failed to send warning for out of channel mentions", mlog.String("user_id", sender.Id), mlog.String("post_id", post.Id), mlog.Err(err))
c.Logger().Error("Failed to send warning for out of channel mentions", mlog.String("user_id", sender.Id), mlog.String("post_id", post.Id), mlog.Err(err))
}
}()
@ -262,7 +262,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
nErr := a.Srv().Store().Channel().IncrementMentionCount(post.ChannelId, mentionedUsersList, post.RootId == "", post.IsUrgent())
if nErr != nil {
mlog.Warn(
c.Logger().Warn(
"Failed to update mention count",
mlog.String("post_id", post.Id),
mlog.String("channel_id", post.ChannelId),
@ -273,7 +273,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
// Log the problems that might have occurred while auto following the thread
for _, mac := range mentionAutofollowChans {
if err := <-mac; err != nil {
mlog.Warn(
c.Logger().Warn(
"Failed to update thread autofollow from mention",
mlog.String("post_id", post.Id),
mlog.String("channel_id", post.ChannelId),
@ -317,7 +317,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
//If email verification is required and user email is not verified don't send email.
if *a.Config().EmailSettings.RequireEmailVerification && !profileMap[id].EmailVerified {
mlog.Debug("Skipped sending notification email, address not verified.", mlog.String("user_email", profileMap[id].Email), mlog.String("user_id", id))
c.Logger().Debug("Skipped sending notification email, address not verified.", mlog.String("user_email", profileMap[id].Email), mlog.String("user_id", id))
continue
}
@ -327,7 +327,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
a.Log().Warn("Unable to get the sender user profile image.", mlog.String("user_id", sender.Id), mlog.Err(err))
}
if err := a.sendNotificationEmail(c, notification, profileMap[id], team, senderProfileImage); err != nil {
mlog.Warn("Unable to send notification email.", mlog.Err(err))
c.Logger().Warn("Unable to send notification email.", mlog.Err(err))
}
}
}
@ -504,7 +504,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
var infos []*model.FileInfo
if fResult := <-fchan; fResult.NErr != nil {
mlog.Warn("Unable to get fileInfo for push notifications.", mlog.String("post_id", post.Id), mlog.Err(fResult.NErr))
c.Logger().Warn("Unable to get fileInfo for push notifications.", mlog.String("post_id", post.Id), mlog.Err(fResult.NErr))
} else {
infos = fResult.Data
}
@ -596,7 +596,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
payload, jsonErr := json.Marshal(userThread)
if jsonErr != nil {
mlog.Warn("Failed to encode thread to JSON")
c.Logger().Warn("Failed to encode thread to JSON")
}
message.Add("thread", string(payload))
message.Add("previous_unread_mentions", previousUnreadMentions)
@ -735,7 +735,7 @@ func (a *App) RemoveNotifications(c request.CTX, post *model.Post, channel *mode
payload, jsonErr := json.Marshal(userThread)
if jsonErr != nil {
mlog.Warn("Failed to encode thread to JSON")
c.Logger().Warn("Failed to encode thread to JSON")
}
message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, team.Id, "", userID, nil, "")
@ -849,7 +849,7 @@ func (a *App) userAllowsEmail(c request.CTX, user *model.User, channelMemberNoti
// Remove the user as recipient when the user has muted the channel.
if channelMuted, ok := channelMemberNotificationProps[model.MarkUnreadNotifyProp]; ok {
if channelMuted == model.ChannelMarkUnreadMention {
mlog.Debug("Channel muted for user", mlog.String("user_id", user.Id), mlog.String("channel_mute", channelMuted))
c.Logger().Debug("Channel muted for user", mlog.String("user_id", user.Id), mlog.String("channel_mute", channelMuted))
userAllowsEmails = false
}
}

View File

@ -133,7 +133,7 @@ func (a *App) sendNotificationEmail(c request.CTX, notification *PostNotificatio
a.Srv().Go(func() {
if nErr := a.Srv().EmailService.SendMailWithEmbeddedFiles(user.Email, html.UnescapeString(subjectText), bodyText, embeddedFiles, messageID, inReplyTo, references, "Notification"); nErr != nil {
mlog.Error("Error while sending the email", mlog.String("user_email", user.Email), mlog.Err(nErr))
c.Logger().Error("Error while sending the email", mlog.String("user_email", user.Email), mlog.Err(nErr))
}
})
@ -238,13 +238,13 @@ func (a *App) getNotificationEmailBody(c request.CTX, recipient *model.User, pos
postMessage = html.EscapeString(postMessage)
mdPostMessage, mdErr := utils.MarkdownToHTML(postMessage, a.GetSiteURL())
if mdErr != nil {
mlog.Warn("Encountered error while converting markdown to HTML", mlog.Err(mdErr))
c.Logger().Warn("Encountered error while converting markdown to HTML", mlog.Err(mdErr))
mdPostMessage = postMessage
}
normalizedPostMessage, err := a.generateHyperlinkForChannels(c, mdPostMessage, teamName, landingURL)
if err != nil {
mlog.Warn("Encountered error while generating hyperlink for channels", mlog.String("team_name", teamName), mlog.Err(err))
c.Logger().Warn("Encountered error while generating hyperlink for channels", mlog.String("team_name", teamName), mlog.Err(err))
normalizedPostMessage = mdPostMessage
}
pData.Message = template.HTML(normalizedPostMessage)

View File

@ -377,11 +377,11 @@ func (hub *PushNotificationsHub) start(c request.CTX) {
case notificationTypeUpdateBadge:
err = hub.app.updateMobileAppBadgeSync(c, notification.userID)
default:
mlog.Debug("Invalid notification type", mlog.String("notification_type", notification.notificationType))
c.Logger().Debug("Invalid notification type", mlog.String("notification_type", notification.notificationType))
}
if err != nil {
mlog.Error("Unable to send push notification", mlog.String("notification_type", notification.notificationType), mlog.Err(err))
c.Logger().Error("Unable to send push notification", mlog.String("notification_type", notification.notificationType), mlog.Err(err))
}
}(notification)
case <-hub.stopChan:
@ -717,7 +717,7 @@ func (a *App) buildFullPushNotificationMessage(c request.CTX, contentsConfig str
postMessage := post.Message
stripped, err := utils.StripMarkdown(postMessage)
if err != nil {
mlog.Warn("Failed parse to markdown", mlog.String("post_id", post.Id), mlog.Err(err))
c.Logger().Warn("Failed parse to markdown", mlog.String("post_id", post.Id), mlog.Err(err))
} else {
postMessage = stripped
}

View File

@ -220,7 +220,7 @@ func (a *App) AllowOAuthAppAccessToUser(c request.CTX, userID string, authReques
}
if err != nil {
mlog.Warn("error getting oauth redirect uri", mlog.Err(err))
c.Logger().Warn("error getting oauth redirect uri", mlog.Err(err))
return authRequest.RedirectURI + "?error=server_error&state=" + authRequest.State, nil
}
@ -233,7 +233,7 @@ func (a *App) AllowOAuthAppAccessToUser(c request.CTX, userID string, authReques
}
if nErr := a.Srv().Store().Preference().Save(model.Preferences{authorizedApp}); nErr != nil {
mlog.Warn("error saving store preference", mlog.Err(nErr))
c.Logger().Warn("error saving store preference", mlog.Err(nErr))
return authRequest.RedirectURI + "?error=server_error&state=" + authRequest.State, nil
}
@ -295,7 +295,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(c request.CTX, clientId, grantType,
if authData.IsExpired() {
if nErr = a.Srv().Store().OAuth().RemoveAuthData(authData.Code); nErr != nil {
mlog.Warn("unable to remove auth data", mlog.Err(nErr))
c.Logger().Warn("unable to remove auth data", mlog.Err(nErr))
}
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.expired_code.app_error", nil, "", http.StatusForbidden)
}
@ -358,7 +358,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(c request.CTX, clientId, grantType,
}
if nErr = a.Srv().Store().OAuth().RemoveAuthData(authData.Code); nErr != nil {
mlog.Warn("unable to remove auth data", mlog.Err(nErr))
c.Logger().Warn("unable to remove auth data", mlog.Err(nErr))
}
} else {
// When grantType is refresh_token
@ -406,7 +406,7 @@ func (a *App) newSession(c request.CTX, app *model.OAuthApp, user *model.User) (
func (a *App) newSessionUpdateToken(c request.CTX, app *model.OAuthApp, accessData *model.AccessData, user *model.User) (*model.AccessResponse, *model.AppError) {
// Remove the previous session
if err := a.Srv().Store().Session().Remove(accessData.Token); err != nil {
mlog.Warn("error removing access data token from session", mlog.Err(err))
c.Logger().Warn("error removing access data token from session", mlog.Err(err))
}
session, err := a.newSession(c, app, user)
@ -694,7 +694,7 @@ func (a *App) CompleteSwitchWithOAuth(c request.CTX, service string, userData io
a.Srv().Go(func() {
if err := a.Srv().EmailService.SendSignInChangeEmail(user.Email, strings.Title(service)+" SSO", user.Locale, a.GetSiteURL()); err != nil {
mlog.Error("error sending signin change email", mlog.Err(err))
c.Logger().Error("error sending signin change email", mlog.Err(err))
}
})
@ -837,7 +837,7 @@ func (a *App) AuthorizeOAuthUser(c request.CTX, w http.ResponseWriter, r *http.R
appErr = a.DeleteToken(expectedToken)
if appErr != nil {
mlog.Warn("error deleting token", mlog.Err(appErr))
c.Logger().Warn("error deleting token", mlog.Err(appErr))
}
subpath, _ := utils.GetSubpathFromConfig(a.Config())
@ -921,7 +921,7 @@ func (a *App) AuthorizeOAuthUser(c request.CTX, w http.ResponseWriter, r *http.R
bodyBytes, _ := io.ReadAll(resp.Body)
bodyString := string(bodyBytes)
mlog.Error("Error getting OAuth user", mlog.Int("response", resp.StatusCode), mlog.String("body_string", bodyString))
c.Logger().Error("Error getting OAuth user", mlog.Int("response", resp.StatusCode), mlog.String("body_string", bodyString))
if service == model.ServiceGitlab && resp.StatusCode == http.StatusForbidden && strings.Contains(bodyString, "Terms of Service") {
url, err := url.Parse(*sso.UserAPIEndpoint)

View File

@ -31,7 +31,7 @@ func (a *App) CompleteOnboarding(c request.CTX, request *model.CompleteOnboardin
isCloud := a.Srv().License() != nil && *a.Srv().License().Features.Cloud
if !isCloud && request.Organization == "" {
mlog.Error("No organization name provided for self hosted onboarding")
c.Logger().Error("No organization name provided for self hosted onboarding")
return model.NewAppError("CompleteOnboarding", "api.error_no_organization_name_provided_for_self_hosted_onboarding", nil, "", http.StatusBadRequest)
}
@ -59,19 +59,19 @@ func (a *App) CompleteOnboarding(c request.CTX, request *model.CompleteOnboardin
}
_, appErr := a.Channels().InstallMarketplacePlugin(installRequest)
if appErr != nil {
mlog.Error("Failed to install plugin for onboarding", mlog.String("id", id), mlog.Err(appErr))
c.Logger().Error("Failed to install plugin for onboarding", mlog.String("id", id), mlog.Err(appErr))
return
}
appErr = a.EnablePlugin(id)
if appErr != nil {
mlog.Error("Failed to enable plugin for onboarding", mlog.String("id", id), mlog.Err(appErr))
c.Logger().Error("Failed to enable plugin for onboarding", mlog.String("id", id), mlog.Err(appErr))
return
}
hooks, err := a.ch.HooksForPluginOrProduct(id)
if err != nil {
mlog.Warn("Getting hooks for plugin failed", mlog.String("plugin_id", id), mlog.Err(err))
c.Logger().Warn("Getting hooks for plugin failed", mlog.String("plugin_id", id), mlog.Err(err))
return
}
@ -79,7 +79,7 @@ func (a *App) CompleteOnboarding(c request.CTX, request *model.CompleteOnboardin
UserId: c.Session().UserId,
}
if err = hooks.OnInstall(pluginContext, event); err != nil {
mlog.Error("Plugin OnInstall hook failed", mlog.String("plugin_id", id), mlog.Err(err))
c.Logger().Error("Plugin OnInstall hook failed", mlog.String("plugin_id", id), mlog.Err(err))
}
}(pluginID)
}

View File

@ -881,7 +881,7 @@ func (a *OpenTracingAppLayer) AutocompleteChannelsForTeam(c request.CTX, teamID
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) AutocompleteUsersInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError) {
func (a *OpenTracingAppLayer) AutocompleteUsersInChannel(rctx request.CTX, teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.AutocompleteUsersInChannel")
@ -893,7 +893,7 @@ func (a *OpenTracingAppLayer) AutocompleteUsersInChannel(teamID string, channelI
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.AutocompleteUsersInChannel(teamID, channelID, term, options)
resultVar0, resultVar1 := a.app.AutocompleteUsersInChannel(rctx, teamID, channelID, term, options)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@ -903,7 +903,7 @@ func (a *OpenTracingAppLayer) AutocompleteUsersInChannel(teamID string, channelI
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) AutocompleteUsersInTeam(teamID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError) {
func (a *OpenTracingAppLayer) AutocompleteUsersInTeam(rctx request.CTX, teamID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.AutocompleteUsersInTeam")
@ -915,7 +915,7 @@ func (a *OpenTracingAppLayer) AutocompleteUsersInTeam(teamID string, term string
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.AutocompleteUsersInTeam(teamID, term, options)
resultVar0, resultVar1 := a.app.AutocompleteUsersInTeam(rctx, teamID, term, options)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@ -1862,7 +1862,7 @@ func (a *OpenTracingAppLayer) ConvertUserToBot(user *model.User) (*model.Bot, *m
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) CopyFileInfos(userID string, fileIDs []string) ([]string, *model.AppError) {
func (a *OpenTracingAppLayer) CopyFileInfos(rctx request.CTX, userID string, fileIDs []string) ([]string, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CopyFileInfos")
@ -1874,7 +1874,7 @@ func (a *OpenTracingAppLayer) CopyFileInfos(userID string, fileIDs []string) ([]
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.CopyFileInfos(userID, fileIDs)
resultVar0, resultVar1 := a.app.CopyFileInfos(rctx, userID, fileIDs)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@ -4063,7 +4063,7 @@ func (a *OpenTracingAppLayer) EnableUserAccessToken(c request.CTX, token *model.
return resultVar0
}
func (a *OpenTracingAppLayer) EnsureBot(c request.CTX, productID string, bot *model.Bot) (string, error) {
func (a *OpenTracingAppLayer) EnsureBot(rctx request.CTX, productID string, bot *model.Bot) (string, error) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.EnsureBot")
@ -4075,7 +4075,7 @@ func (a *OpenTracingAppLayer) EnsureBot(c request.CTX, productID string, bot *mo
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.EnsureBot(c, productID, bot)
resultVar0, resultVar1 := a.app.EnsureBot(rctx, productID, bot)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@ -12809,7 +12809,7 @@ func (a *OpenTracingAppLayer) OverrideIconURLIfEmoji(c request.CTX, post *model.
a.app.OverrideIconURLIfEmoji(c, post)
}
func (a *OpenTracingAppLayer) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError) {
func (a *OpenTracingAppLayer) PatchBot(rctx request.CTX, botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.PatchBot")
@ -12821,7 +12821,7 @@ func (a *OpenTracingAppLayer) PatchBot(botUserId string, botPatch *model.BotPatc
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.PatchBot(botUserId, botPatch)
resultVar0, resultVar1 := a.app.PatchBot(rctx, botUserId, botPatch)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@ -13461,7 +13461,7 @@ func (a *OpenTracingAppLayer) PublishUserTyping(userID string, channelID string,
return resultVar0
}
func (a *OpenTracingAppLayer) PurgeBleveIndexes() *model.AppError {
func (a *OpenTracingAppLayer) PurgeBleveIndexes(c request.CTX) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.PurgeBleveIndexes")
@ -13473,7 +13473,7 @@ func (a *OpenTracingAppLayer) PurgeBleveIndexes() *model.AppError {
}()
defer span.Finish()
resultVar0 := a.app.PurgeBleveIndexes()
resultVar0 := a.app.PurgeBleveIndexes(c)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
@ -13483,7 +13483,7 @@ func (a *OpenTracingAppLayer) PurgeBleveIndexes() *model.AppError {
return resultVar0
}
func (a *OpenTracingAppLayer) PurgeElasticsearchIndexes() *model.AppError {
func (a *OpenTracingAppLayer) PurgeElasticsearchIndexes(c request.CTX) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.PurgeElasticsearchIndexes")
@ -13495,7 +13495,7 @@ func (a *OpenTracingAppLayer) PurgeElasticsearchIndexes() *model.AppError {
}()
defer span.Finish()
resultVar0 := a.app.PurgeElasticsearchIndexes()
resultVar0 := a.app.PurgeElasticsearchIndexes(c)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
@ -15212,7 +15212,7 @@ func (a *OpenTracingAppLayer) SearchUserAccessTokens(term string) ([]*model.User
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) SearchUsers(props *model.UserSearch, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
func (a *OpenTracingAppLayer) SearchUsers(rctx request.CTX, props *model.UserSearch, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SearchUsers")
@ -15224,7 +15224,7 @@ func (a *OpenTracingAppLayer) SearchUsers(props *model.UserSearch, options *mode
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.SearchUsers(props, options)
resultVar0, resultVar1 := a.app.SearchUsers(rctx, props, options)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@ -15278,7 +15278,7 @@ func (a *OpenTracingAppLayer) SearchUsersInGroup(groupID string, term string, op
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) SearchUsersInTeam(teamID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
func (a *OpenTracingAppLayer) SearchUsersInTeam(rctx request.CTX, teamID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SearchUsersInTeam")
@ -15290,7 +15290,7 @@ func (a *OpenTracingAppLayer) SearchUsersInTeam(teamID string, term string, opti
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.SearchUsersInTeam(teamID, term, options)
resultVar0, resultVar1 := a.app.SearchUsersInTeam(rctx, teamID, term, options)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@ -16079,7 +16079,7 @@ func (a *OpenTracingAppLayer) SetDefaultProfileImage(c request.CTX, user *model.
return resultVar0
}
func (a *OpenTracingAppLayer) SetFileSearchableContent(fileID string, data string) *model.AppError {
func (a *OpenTracingAppLayer) SetFileSearchableContent(rctx request.CTX, fileID string, data string) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetFileSearchableContent")
@ -16091,7 +16091,7 @@ func (a *OpenTracingAppLayer) SetFileSearchableContent(fileID string, data strin
}()
defer span.Finish()
resultVar0 := a.app.SetFileSearchableContent(fileID, data)
resultVar0 := a.app.SetFileSearchableContent(rctx, fileID, data)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
@ -16833,7 +16833,7 @@ func (a *OpenTracingAppLayer) TelemetryId() string {
return resultVar0
}
func (a *OpenTracingAppLayer) TestElasticsearch(cfg *model.Config) *model.AppError {
func (a *OpenTracingAppLayer) TestElasticsearch(rctx request.CTX, cfg *model.Config) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.TestElasticsearch")
@ -16845,7 +16845,7 @@ func (a *OpenTracingAppLayer) TestElasticsearch(cfg *model.Config) *model.AppErr
}()
defer span.Finish()
resultVar0 := a.app.TestElasticsearch(cfg)
resultVar0 := a.app.TestElasticsearch(rctx, cfg)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))

View File

@ -5,7 +5,6 @@ package platform
import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
)
func (ps *PlatformService) StartSearchEngine() (string, string) {
@ -26,23 +25,23 @@ func (ps *PlatformService) StartSearchEngine() (string, string) {
if ps.SearchEngine.ElasticsearchEngine != nil && !*oldConfig.ElasticsearchSettings.EnableIndexing && *newConfig.ElasticsearchSettings.EnableIndexing {
ps.Go(func() {
if err := ps.SearchEngine.ElasticsearchEngine.Start(); err != nil {
mlog.Error(err.Error())
ps.Log().Error(err.Error())
}
})
} else if ps.SearchEngine.ElasticsearchEngine != nil && *oldConfig.ElasticsearchSettings.EnableIndexing && !*newConfig.ElasticsearchSettings.EnableIndexing {
ps.Go(func() {
if err := ps.SearchEngine.ElasticsearchEngine.Stop(); err != nil {
mlog.Error(err.Error())
ps.Log().Error(err.Error())
}
})
} else if ps.SearchEngine.ElasticsearchEngine != nil && *oldConfig.ElasticsearchSettings.Password != *newConfig.ElasticsearchSettings.Password || *oldConfig.ElasticsearchSettings.Username != *newConfig.ElasticsearchSettings.Username || *oldConfig.ElasticsearchSettings.ConnectionURL != *newConfig.ElasticsearchSettings.ConnectionURL || *oldConfig.ElasticsearchSettings.Sniff != *newConfig.ElasticsearchSettings.Sniff {
ps.Go(func() {
if *oldConfig.ElasticsearchSettings.EnableIndexing {
if err := ps.SearchEngine.ElasticsearchEngine.Stop(); err != nil {
mlog.Error(err.Error())
ps.Log().Error(err.Error())
}
if err := ps.SearchEngine.ElasticsearchEngine.Start(); err != nil {
mlog.Error(err.Error())
ps.Log().Error(err.Error())
}
}
})
@ -57,7 +56,7 @@ func (ps *PlatformService) StartSearchEngine() (string, string) {
if ps.SearchEngine.ElasticsearchEngine != nil && ps.SearchEngine.ElasticsearchEngine.IsActive() {
ps.Go(func() {
if err := ps.SearchEngine.ElasticsearchEngine.Start(); err != nil {
mlog.Error(err.Error())
ps.Log().Error(err.Error())
}
})
}
@ -65,7 +64,7 @@ func (ps *PlatformService) StartSearchEngine() (string, string) {
if ps.SearchEngine.ElasticsearchEngine != nil {
ps.Go(func() {
if err := ps.SearchEngine.ElasticsearchEngine.Stop(); err != nil {
mlog.Error(err.Error())
ps.Log().Error(err.Error())
}
})
}

View File

@ -205,7 +205,7 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
// |
// Cache layer
var err error
ps.sqlStore, err = sqlstore.New(ps.Config().SqlSettings, ps.metricsIFace)
ps.sqlStore, err = sqlstore.New(ps.Config().SqlSettings, ps.Log(), ps.metricsIFace)
if err != nil {
return nil, err
}

View File

@ -512,7 +512,7 @@ func (api *PluginAPI) SearchUsers(search *model.UserSearch) ([]*model.User, *mod
AllowInactive: search.AllowInactive,
Limit: search.Limit,
}
return api.app.SearchUsers(search, pluginSearchUsersOptions)
return api.app.SearchUsers(api.ctx, search, pluginSearchUsersOptions)
}
func (api *PluginAPI) SearchPostsInTeam(teamID string, paramsList []*model.SearchParams) ([]*model.Post, *model.AppError) {
@ -763,7 +763,7 @@ func (api *PluginAPI) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) {
}
func (api *PluginAPI) CopyFileInfos(userID string, fileIDs []string) ([]string, *model.AppError) {
return api.app.CopyFileInfos(userID, fileIDs)
return api.app.CopyFileInfos(api.ctx, userID, fileIDs)
}
func (api *PluginAPI) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
@ -771,7 +771,7 @@ func (api *PluginAPI) GetFileInfo(fileID string) (*model.FileInfo, *model.AppErr
}
func (api *PluginAPI) SetFileSearchableContent(fileID string, content string) *model.AppError {
return api.app.SetFileSearchableContent(fileID, content)
return api.app.SetFileSearchableContent(api.ctx, fileID, content)
}
func (api *PluginAPI) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
@ -1008,7 +1008,7 @@ func (api *PluginAPI) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
}
func (api *PluginAPI) PatchBot(userID string, botPatch *model.BotPatch) (*model.Bot, *model.AppError) {
return api.app.PatchBot(userID, botPatch)
return api.app.PatchBot(api.ctx, userID, botPatch)
}
func (api *PluginAPI) GetBot(userID string, includeDeleted bool) (*model.Bot, *model.AppError) {

View File

@ -564,7 +564,7 @@ func TestPluginAPIGetFile(t *testing.T) {
info, err := th.App.DoUploadFile(th.Context, uploadTime, th.BasicTeam.Id, th.BasicChannel.Id, th.BasicUser.Id, filename, fileData)
require.Nil(t, err)
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(info.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info.Id)
th.App.RemoveFile(info.Path)
}()
@ -593,7 +593,7 @@ func TestPluginAPIGetFileInfos(t *testing.T) {
)
require.Nil(t, err)
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(fileInfo1.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, fileInfo1.Id)
th.App.RemoveFile(fileInfo1.Path)
}()
@ -607,7 +607,7 @@ func TestPluginAPIGetFileInfos(t *testing.T) {
)
require.Nil(t, err)
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(fileInfo2.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, fileInfo2.Id)
th.App.RemoveFile(fileInfo2.Path)
}()
@ -621,7 +621,7 @@ func TestPluginAPIGetFileInfos(t *testing.T) {
)
require.Nil(t, err)
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(fileInfo3.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, fileInfo3.Id)
th.App.RemoveFile(fileInfo3.Path)
}()
@ -1354,7 +1354,7 @@ func TestPluginCreatePostWithUploadedFile(t *testing.T) {
fileInfo, err := api.UploadFile(data, channelID, filename)
require.Nil(t, err)
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(fileInfo.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, fileInfo.Id)
th.App.RemoveFile(fileInfo.Path)
}()

View File

@ -33,7 +33,7 @@ func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model
rctx := request.TestContext(p.t)
settings := p.API.GetUnsanitizedConfig().SqlSettings
settings.Trace = model.NewBool(false)
store, err := sqlstore.New(settings, nil)
store, err := sqlstore.New(settings, rctx.Logger(), nil)
if err != nil {
panic(err)
}

View File

@ -170,7 +170,7 @@ func (a *App) tryExecutePluginCommand(c request.CTX, args *model.CommandArgs) (*
// This is a response from the plugin, which may set an incorrect status code;
// e.g setting a status code of 0 will crash the server. So we always bucket everything under 500.
if appErr != nil && (appErr.StatusCode < 100 || appErr.StatusCode > 999) {
mlog.Warn("Invalid status code returned from plugin. Converting to internal server error.", mlog.String("plugin_id", matched.PluginId), mlog.Int("status_code", appErr.StatusCode))
c.Logger().Warn("Invalid status code returned from plugin. Converting to internal server error.", mlog.String("plugin_id", matched.PluginId), mlog.Int("status_code", appErr.StatusCode))
appErr.StatusCode = http.StatusInternalServerError
}

View File

@ -361,7 +361,7 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
}
if len(post.FileIds) > 0 {
if err = a.attachFilesToPost(post); err != nil {
if err = a.attachFilesToPost(c, post); err != nil {
c.Logger().Warn("Encountered error attaching files to post", mlog.String("post_id", post.Id), mlog.Array("file_ids", post.FileIds), mlog.Err(err))
}
@ -422,23 +422,23 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
return rpost, nil
}
func (a *App) addPostPreviewProp(post *model.Post) (*model.Post, error) {
func (a *App) addPostPreviewProp(rctx request.CTX, post *model.Post) (*model.Post, error) {
previewPost := post.GetPreviewPost()
if previewPost != nil {
updatedPost := post.Clone()
updatedPost.AddProp(model.PostPropsPreviewedPost, previewPost.PostID)
updatedPost, err := a.Srv().Store().Post().Update(updatedPost, post)
updatedPost, err := a.Srv().Store().Post().Update(rctx, updatedPost, post)
return updatedPost, err
}
return post, nil
}
func (a *App) attachFilesToPost(post *model.Post) *model.AppError {
func (a *App) attachFilesToPost(rctx request.CTX, post *model.Post) *model.AppError {
var attachedIds []string
for _, fileID := range post.FileIds {
err := a.Srv().Store().FileInfo().AttachToPost(fileID, post.Id, post.ChannelId, post.UserId)
err := a.Srv().Store().FileInfo().AttachToPost(rctx, fileID, post.Id, post.ChannelId, post.UserId)
if err != nil {
mlog.Warn("Failed to attach file to post", mlog.String("file_id", fileID), mlog.String("post_id", post.Id), mlog.Err(err))
rctx.Logger().Warn("Failed to attach file to post", mlog.String("file_id", fileID), mlog.String("post_id", post.Id), mlog.Err(err))
continue
}
@ -449,7 +449,7 @@ func (a *App) attachFilesToPost(post *model.Post) *model.AppError {
// We couldn't attach all files to the post, so ensure that post.FileIds reflects what was actually attached
post.FileIds = attachedIds
if _, err := a.Srv().Store().Post().Overwrite(post); err != nil {
if _, err := a.Srv().Store().Post().Overwrite(rctx, post); err != nil {
return model.NewAppError("attachFilesToPost", "app.post.overwrite.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
}
@ -483,7 +483,7 @@ func (a *App) FillInPostProps(c request.CTX, post *model.Post, channel *model.Ch
if mentioned.Type == model.ChannelTypeOpen {
team, err := a.Srv().Store().Team().Get(mentioned.TeamId)
if err != nil {
mlog.Warn("Failed to get team of the channel mention", mlog.String("team_id", channel.TeamId), mlog.String("channel_id", channel.Id), mlog.Err(err))
c.Logger().Warn("Failed to get team of the channel mention", mlog.String("team_id", channel.TeamId), mlog.String("channel_id", channel.Id), mlog.Err(err))
continue
}
channelMentionsProp[mentioned.Name] = map[string]any{
@ -579,7 +579,7 @@ func (a *App) SendEphemeralPost(c request.CTX, userID string, post *model.Post)
postJSON, jsonErr := post.ToJSON()
if jsonErr != nil {
mlog.Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
c.Logger().Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
}
message.Add("post", postJSON)
a.Publish(message)
@ -601,7 +601,7 @@ func (a *App) UpdateEphemeralPost(c request.CTX, userID string, post *model.Post
post = model.AddPostActionCookies(post, a.PostActionCookieSecret())
postJSON, jsonErr := post.ToJSON()
if jsonErr != nil {
mlog.Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
c.Logger().Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
}
message.Add("post", postJSON)
a.Publish(message)
@ -711,7 +711,7 @@ func (a *App) UpdatePost(c request.CTX, receivedUpdatedPost *model.Post, safeUpd
// the last known good.
newPost.Metadata = oldPost.Metadata
rpost, nErr := a.Srv().Store().Post().Update(newPost, oldPost)
rpost, nErr := a.Srv().Store().Post().Update(c, newPost, oldPost)
if nErr != nil {
var appErr *model.AppError
switch {
@ -738,7 +738,7 @@ func (a *App) UpdatePost(c request.CTX, receivedUpdatedPost *model.Post, safeUpd
// individually.
rpost.IsFollowing = nil
rpost, nErr = a.addPostPreviewProp(rpost)
rpost, nErr = a.addPostPreviewProp(c, rpost)
if nErr != nil {
return nil, model.NewAppError("UpdatePost", "app.post.update.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
}
@ -783,14 +783,14 @@ func (a *App) publishWebsocketEventForPermalinkPost(c request.CTX, post *model.P
}
if !model.IsValidId(previewedPostID) {
mlog.Warn("invalid post prop value", mlog.String("prop_key", model.PostPropsPreviewedPost), mlog.String("prop_value", previewedPostID))
c.Logger().Warn("invalid post prop value", mlog.String("prop_key", model.PostPropsPreviewedPost), mlog.String("prop_value", previewedPostID))
return false, nil
}
previewedPost, err := a.GetSinglePost(previewedPostID, false)
if err != nil {
if err.StatusCode == http.StatusNotFound {
mlog.Warn("permalinked post not found", mlog.String("referenced_post_id", previewedPostID))
c.Logger().Warn("permalinked post not found", mlog.String("referenced_post_id", previewedPostID))
return false, nil
}
return false, err
@ -804,7 +804,7 @@ func (a *App) publishWebsocketEventForPermalinkPost(c request.CTX, post *model.P
permalinkPreviewedChannel, err := a.GetChannel(c, previewedPost.ChannelId)
if err != nil {
if err.StatusCode == http.StatusNotFound {
mlog.Warn("channel containing permalinked post not found", mlog.String("referenced_channel_id", previewedPost.ChannelId))
c.Logger().Warn("channel containing permalinked post not found", mlog.String("referenced_channel_id", previewedPost.ChannelId))
return false, nil
}
return false, err
@ -830,7 +830,7 @@ func (a *App) publishWebsocketEventForPermalinkPost(c request.CTX, post *model.P
postJSON, jsonErr := postForUser.ToJSON()
if jsonErr != nil {
mlog.Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
c.Logger().Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
}
messageCopy.Add("post", postJSON)
a.Publish(messageCopy)
@ -1343,7 +1343,7 @@ func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post,
return nil, appErr
}
err = a.Srv().Store().Post().Delete(postID, model.GetMillis(), deleteByID)
err = a.Srv().Store().Post().Delete(c, postID, model.GetMillis(), deleteByID)
if err != nil {
var nfErr *store.ErrNotFound
switch {
@ -1378,13 +1378,13 @@ func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post,
if len(post.FileIds) > 0 {
a.Srv().Go(func() {
a.deletePostFiles(post.Id)
a.deletePostFiles(c, post.Id)
})
a.Srv().Store().FileInfo().InvalidateFileInfosForPostCache(postID, true)
a.Srv().Store().FileInfo().InvalidateFileInfosForPostCache(postID, false)
}
a.Srv().Go(func() {
a.deleteFlaggedPosts(post.Id)
a.deleteFlaggedPosts(c, post.Id)
})
pluginPost := post.ForPlugin()
@ -1407,16 +1407,16 @@ func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post,
return post, nil
}
func (a *App) deleteFlaggedPosts(postID string) {
func (a *App) deleteFlaggedPosts(c request.CTX, postID string) {
if err := a.Srv().Store().Preference().DeleteCategoryAndName(model.PreferenceCategoryFlaggedPost, postID); err != nil {
a.Log().Warn("Unable to delete flagged post preference when deleting post.", mlog.Err(err))
c.Logger().Warn("Unable to delete flagged post preference when deleting post.", mlog.Err(err))
return
}
}
func (a *App) deletePostFiles(postID string) {
if _, err := a.Srv().Store().FileInfo().DeleteForPost(postID); err != nil {
a.Log().Warn("Encountered error when deleting files for post", mlog.String("post_id", postID), mlog.Err(err))
func (a *App) deletePostFiles(c request.CTX, postID string) {
if _, err := a.Srv().Store().FileInfo().DeleteForPost(c, postID); err != nil {
c.Logger().Warn("Encountered error when deleting files for post", mlog.String("post_id", postID), mlog.Err(err))
}
}
@ -1500,7 +1500,7 @@ func (a *App) convertChannelNamesToChannelIds(c request.CTX, channels []string,
for idx, channelName := range channels {
channel, err := a.parseAndFetchChannelIdByNameFromInFilter(c, channelName, userID, teamID, includeDeletedChannels)
if err != nil {
a.Log().Warn("error getting channel id by name from in filter", mlog.Err(err))
c.Logger().Warn("error getting channel id by name from in filter", mlog.Err(err))
continue
}
channels[idx] = channel.Id
@ -1508,11 +1508,11 @@ func (a *App) convertChannelNamesToChannelIds(c request.CTX, channels []string,
return channels
}
func (a *App) convertUserNameToUserIds(usernames []string) []string {
func (a *App) convertUserNameToUserIds(c request.CTX, usernames []string) []string {
for idx, username := range usernames {
user, err := a.GetUserByUsername(username)
if err != nil {
a.Log().Warn("error getting user by username", mlog.String("user_name", username), mlog.Err(err))
c.Logger().Warn("error getting user by username", mlog.String("user_name", username), mlog.Err(err))
continue
}
usernames[idx] = user.Id
@ -1651,8 +1651,8 @@ func (a *App) SearchPostsForUser(c request.CTX, terms string, userID string, tea
params.ExcludedChannels = a.convertChannelNamesToChannelIds(c, params.ExcludedChannels, userID, teamID, includeDeletedChannels)
// Convert usernames to user IDs
params.FromUsers = a.convertUserNameToUserIds(params.FromUsers)
params.ExcludedUsers = a.convertUserNameToUserIds(params.ExcludedUsers)
params.FromUsers = a.convertUserNameToUserIds(c, params.FromUsers)
params.ExcludedUsers = a.convertUserNameToUserIds(c, params.ExcludedUsers)
finalParamsList = append(finalParamsList, params)
}
@ -1663,7 +1663,7 @@ func (a *App) SearchPostsForUser(c request.CTX, terms string, userID string, tea
return model.MakePostSearchResults(model.NewPostList(), nil), nil
}
postSearchResults, err := a.Srv().Store().Post().SearchPostsForUser(finalParamsList, userID, teamID, page, perPage)
postSearchResults, err := a.Srv().Store().Post().SearchPostsForUser(c, finalParamsList, userID, teamID, page, perPage)
if err != nil {
var appErr *model.AppError
switch {

View File

@ -102,7 +102,7 @@ func (a *App) OverrideIconURLIfEmoji(c request.CTX, post *model.Post) {
if emojiURL, err := a.GetEmojiStaticURL(c, emojiName); err == nil {
post.AddProp(model.PostPropsOverrideIconURL, emojiURL)
} else {
mlog.Warn("Failed to retrieve URL for overridden profile icon (emoji)", mlog.String("emojiName", emojiName), mlog.Err(err))
c.Logger().Warn("Failed to retrieve URL for overridden profile icon (emoji)", mlog.String("emojiName", emojiName), mlog.Err(err))
}
}
@ -181,7 +181,7 @@ func (a *App) getEmbedsAndImages(c request.CTX, post *model.Post, isNewPost bool
isNotFound := ok && appErr.StatusCode == http.StatusNotFound
// Ignore NotFound errors.
if !isNotFound {
mlog.Debug("Failed to get embedded content for a post", mlog.String("post_id", post.Id), mlog.Err(err))
c.Logger().Debug("Failed to get embedded content for a post", mlog.String("post_id", post.Id), mlog.Err(err))
}
} else if embed != nil {
post.Metadata.Embeds = append(post.Metadata.Embeds, embed)
@ -359,8 +359,10 @@ func (a *App) getImagesForPost(c request.CTX, post *model.Post, imageURLs []stri
case model.PostEmbedOpengraph:
openGraph, ok := embed.Data.(*opengraph.OpenGraph)
if !ok {
mlog.Warn("Could not read the image data: the data could not be casted to OpenGraph",
mlog.String("post_id", post.Id), mlog.String("data type", fmt.Sprintf("%t", embed.Data)))
c.Logger().Warn("Could not read the image data: the data could not be casted to OpenGraph",
mlog.String("post_id", post.Id),
mlog.String("data type", fmt.Sprintf("%t", embed.Data)),
)
continue
}
for _, image := range openGraph.Images {
@ -397,8 +399,11 @@ func (a *App) getImagesForPost(c request.CTX, post *model.Post, imageURLs []stri
isNotFound := ok && appErr.StatusCode == http.StatusNotFound
// Ignore NotFound errors.
if !isNotFound {
mlog.Debug("Failed to get dimensions of an image in a post",
mlog.String("post_id", post.Id), mlog.String("image_url", imageURL), mlog.Err(err))
c.Logger().Debug("Failed to get dimensions of an image in a post",
mlog.String("post_id", post.Id),
mlog.String("image_url", imageURL),
mlog.Err(err),
)
}
} else if image != nil {
images[imageURL] = image
@ -684,7 +689,7 @@ func (a *App) getLinkMetadata(c request.CTX, requestURL string, timestamp int64,
var res *http.Response
res, err = client.Do(request)
if err != nil {
mlog.Warn("error fetching OG image data", mlog.Err(err))
c.Logger().Warn("error fetching OG image data", mlog.Err(err))
}
if res != nil {

View File

@ -203,22 +203,24 @@ func TestAttachFilesToPost(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
info1, err := th.App.Srv().Store().FileInfo().Save(&model.FileInfo{
CreatorId: th.BasicUser.Id,
Path: "path.txt",
})
info1, err := th.App.Srv().Store().FileInfo().Save(th.Context,
&model.FileInfo{
CreatorId: th.BasicUser.Id,
Path: "path.txt",
})
require.NoError(t, err)
info2, err := th.App.Srv().Store().FileInfo().Save(&model.FileInfo{
CreatorId: th.BasicUser.Id,
Path: "path.txt",
})
info2, err := th.App.Srv().Store().FileInfo().Save(th.Context,
&model.FileInfo{
CreatorId: th.BasicUser.Id,
Path: "path.txt",
})
require.NoError(t, err)
post := th.BasicPost
post.FileIds = []string{info1.Id, info2.Id}
appErr := th.App.attachFilesToPost(post)
appErr := th.App.attachFilesToPost(th.Context, post)
assert.Nil(t, appErr)
infos, _, appErr := th.App.GetFileInfosForPost(th.Context, post.Id, false, false)
@ -230,23 +232,25 @@ func TestAttachFilesToPost(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
info1, err := th.App.Srv().Store().FileInfo().Save(&model.FileInfo{
CreatorId: th.BasicUser.Id,
Path: "path.txt",
PostId: model.NewId(),
})
info1, err := th.App.Srv().Store().FileInfo().Save(th.Context,
&model.FileInfo{
CreatorId: th.BasicUser.Id,
Path: "path.txt",
PostId: model.NewId(),
})
require.NoError(t, err)
info2, err := th.App.Srv().Store().FileInfo().Save(&model.FileInfo{
CreatorId: th.BasicUser.Id,
Path: "path.txt",
})
info2, err := th.App.Srv().Store().FileInfo().Save(th.Context,
&model.FileInfo{
CreatorId: th.BasicUser.Id,
Path: "path.txt",
})
require.NoError(t, err)
post := th.BasicPost
post.FileIds = []string{info1.Id, info2.Id}
appErr := th.App.attachFilesToPost(post)
appErr := th.App.attachFilesToPost(th.Context, post)
assert.Nil(t, appErr)
infos, _, appErr := th.App.GetFileInfosForPost(th.Context, post.Id, false, false)
@ -790,7 +794,7 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
info1, err := th.App.DoUploadFile(th.Context, time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
require.Nil(t, err)
defer func() {
th.App.Srv().Store().FileInfo().PermanentDelete(info1.Id)
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info1.Id)
th.App.RemoveFile(info1.Path)
}()
@ -2781,7 +2785,7 @@ func TestCollapsedThreadFetch(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
th.Server.Store().Post().PermanentDeleteByUser(user1.Id)
th.Server.Store().Post().PermanentDeleteByUser(th.Context, user1.Id)
}()
require.NotPanics(t, func() {

View File

@ -7,10 +7,11 @@ import (
"net/http"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/platform/services/searchengine"
)
func (a *App) TestElasticsearch(cfg *model.Config) *model.AppError {
func (a *App) TestElasticsearch(rctx request.CTX, cfg *model.Config) *model.AppError {
if *cfg.ElasticsearchSettings.Password == model.FakeSetting {
if *cfg.ElasticsearchSettings.ConnectionURL == *a.Config().ElasticsearchSettings.ConnectionURL && *cfg.ElasticsearchSettings.Username == *a.Config().ElasticsearchSettings.Username {
*cfg.ElasticsearchSettings.Password = *a.Config().ElasticsearchSettings.Password
@ -24,7 +25,7 @@ func (a *App) TestElasticsearch(cfg *model.Config) *model.AppError {
err := model.NewAppError("TestElasticsearch", "ent.elasticsearch.test_config.license.error", nil, "", http.StatusNotImplemented)
return err
}
if err := seI.TestConfig(cfg); err != nil {
if err := seI.TestConfig(rctx, cfg); err != nil {
return err
}
@ -35,27 +36,27 @@ func (a *App) SetSearchEngine(se *searchengine.Broker) {
a.ch.srv.platform.SearchEngine = se
}
func (a *App) PurgeElasticsearchIndexes() *model.AppError {
func (a *App) PurgeElasticsearchIndexes(c request.CTX) *model.AppError {
engine := a.SearchEngine().ElasticsearchEngine
if engine == nil {
err := model.NewAppError("PurgeElasticsearchIndexes", "ent.elasticsearch.test_config.license.error", nil, "", http.StatusNotImplemented)
return err
}
if err := engine.PurgeIndexes(); err != nil {
if err := engine.PurgeIndexes(c); err != nil {
return err
}
return nil
}
func (a *App) PurgeBleveIndexes() *model.AppError {
func (a *App) PurgeBleveIndexes(c request.CTX) *model.AppError {
engine := a.SearchEngine().BleveEngine
if engine == nil {
err := model.NewAppError("PurgeBleveIndexes", "searchengine.bleve.disabled.error", nil, "", http.StatusNotImplemented)
return err
}
if err := engine.PurgeIndexes(); err != nil {
if err := engine.PurgeIndexes(c); err != nil {
return err
}
return nil

View File

@ -274,13 +274,17 @@ func (a *App) ExtendSessionExpiryIfNeeded(rctx request.CTX, session *model.Sessi
newExpiry := now + sessionLength
if err := a.ch.srv.platform.ExtendSessionExpiry(session, newExpiry); err != nil {
mlog.Error("Failed to update ExpiresAt", mlog.String("user_id", session.UserId), mlog.String("session_id", session.Id), mlog.Err(err))
rctx.Logger().Error("Failed to update ExpiresAt", mlog.String("user_id", session.UserId), mlog.String("session_id", session.Id), mlog.Err(err))
auditRec.AddMeta("err", err.Error())
return false
}
mlog.Debug("Session extended", mlog.String("user_id", session.UserId), mlog.String("session_id", session.Id),
mlog.Int("newExpiry", newExpiry), mlog.Int("session_length", sessionLength))
rctx.Logger().Debug("Session extended",
mlog.String("user_id", session.UserId),
mlog.String("session_id", session.Id),
mlog.Int("newExpiry", newExpiry),
mlog.Int("session_length", sessionLength),
)
auditRec.Success()
auditRec.AddEventResultState(session)

View File

@ -127,7 +127,7 @@ func (cfg *AutoUserCreator) createRandomUser(c request.CTX) (*model.User, error)
return nil, appErr
}
teamMember.CreateAt = cfg.JoinTime
_, err := cfg.app.Srv().Store().Team().UpdateMember(teamMember)
_, err := cfg.app.Srv().Store().Team().UpdateMember(c, teamMember)
if err != nil {
return nil, err
}

View File

@ -10,7 +10,6 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/i18n"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/app"
)
@ -49,7 +48,7 @@ func (*CustomStatusProvider) DoCommand(a *app.App, c request.CTX, args *model.Co
message = strings.TrimSpace(message)
if message == CmdCustomStatusClear {
if err := a.RemoveCustomStatus(c, args.UserId); err != nil {
mlog.Debug(err.Error())
c.Logger().Debug(err.Error())
return &model.CommandResponse{Text: args.T("api.command_custom_status.clear.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
}
@ -62,7 +61,7 @@ func (*CustomStatusProvider) DoCommand(a *app.App, c request.CTX, args *model.Co
customStatus := GetCustomStatus(message)
customStatus.PreSave()
if err := a.SetCustomStatus(c, args.UserId, customStatus); err != nil {
mlog.Debug(err.Error())
c.Logger().Debug(err.Error())
return &model.CommandResponse{Text: args.T("api.command_custom_status.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
}

View File

@ -90,7 +90,7 @@ func (*EchoProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArg
time.Sleep(time.Duration(delay) * time.Second)
if _, err := a.CreatePostMissingChannel(c, post, true, true); err != nil {
mlog.Error("Unable to create /echo post.", mlog.Err(err))
c.Logger().Error("Unable to create /echo post.", mlog.Err(err))
}
})

View File

@ -9,7 +9,6 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/i18n"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/app"
)
@ -112,7 +111,7 @@ func (*groupmsgProvider) DoCommand(a *app.App, c request.CTX, args *model.Comman
if a.HasPermissionTo(args.UserId, model.PermissionCreateGroupChannel) {
groupChannel, channelErr = a.CreateGroupChannel(c, targetUsersSlice, args.UserId)
if channelErr != nil {
mlog.Error(channelErr.Error())
c.Logger().Error(channelErr.Error())
return &model.CommandResponse{Text: args.T("api.command_groupmsg.group_fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
}
} else {

View File

@ -312,7 +312,7 @@ func (i *InviteProvider) addUserToChannel(a *app.App, c request.CTX, args *model
err.Id == "api.channel.add_user.to.channel.failed.deleted.app_error" {
return UserNotInTeam
}
mlog.Warn("addUserToChannel had unexpected error.", mlog.String("UserId", userProfile.Id), mlog.Err(err))
c.Logger().Warn("addUserToChannel had unexpected error.", mlog.String("UserId", userProfile.Id), mlog.Err(err))
return Unknown
}

View File

@ -8,7 +8,6 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/i18n"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/app"
)
@ -77,7 +76,7 @@ func (*InvitePeopleProvider) DoCommand(a *app.App, c request.CTX, args *model.Co
}
if err := a.InviteNewUsersToTeam(emailList, args.TeamId, args.UserId); err != nil {
mlog.Error(err.Error())
c.Logger().Error(err.Error())
return &model.CommandResponse{ResponseType: model.CommandResponseTypeEphemeral, Text: args.T("api.command.invite_people.fail")}
}

View File

@ -9,7 +9,6 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/i18n"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/app"
"github.com/mattermost/mattermost/server/v8/channels/store"
@ -54,7 +53,7 @@ func (*msgProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs
userProfile, nErr := a.Srv().Store().User().GetByUsername(targetUsername)
if nErr != nil {
mlog.Error(nErr.Error())
c.Logger().Error(nErr.Error())
return &model.CommandResponse{Text: args.T("api.command_msg.missing.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
}
@ -64,7 +63,7 @@ func (*msgProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs
canSee, err := a.UserCanSeeOtherUser(c, args.UserId, userProfile.Id)
if err != nil {
mlog.Error(err.Error())
c.Logger().Error(err.Error())
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
}
if !canSee {
@ -84,12 +83,12 @@ func (*msgProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs
var directChannel *model.Channel
if directChannel, err = a.GetOrCreateDirectChannel(c, args.UserId, userProfile.Id); err != nil {
mlog.Error(err.Error())
c.Logger().Error(err.Error())
return &model.CommandResponse{Text: args.T(err.Id), ResponseType: model.CommandResponseTypeEphemeral}
}
targetChannelId = directChannel.Id
} else {
mlog.Error(channelErr.Error())
c.Logger().Error(channelErr.Error())
return &model.CommandResponse{Text: args.T("api.command_msg.dm_fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
}
} else {

View File

@ -8,7 +8,6 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/i18n"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/app"
)
@ -110,7 +109,7 @@ func doCommand(a *app.App, c request.CTX, args *model.CommandArgs, message strin
userProfile, nErr := a.Srv().Store().User().GetByUsername(targetUsername)
if nErr != nil {
mlog.Error(nErr.Error())
c.Logger().Error(nErr.Error())
return &model.CommandResponse{
Text: args.T("api.command_remove.missing.app_error"),
ResponseType: model.CommandResponseTypeEphemeral,

View File

@ -49,14 +49,14 @@ func TestCustomStatusErrors(t *testing.T) {
tests := map[string]struct {
customStatus string
successFn string
failFn string
getFails bool
updateFails bool
expectedErr string
}{
"set custom status fails on get user": {customStatus: "set", successFn: "Update", failFn: "Get", expectedErr: MissingAccountError},
"set custom status fails on update user": {customStatus: "set", successFn: "Get", failFn: "Update", expectedErr: "app.user.update.finding.app_error"},
"remove custom status fails on get user": {customStatus: "remove", successFn: "Update", failFn: "Get", expectedErr: MissingAccountError},
"remove custom status fails on update user": {customStatus: "remove", successFn: "Get", failFn: "Update", expectedErr: "app.user.update.finding.app_error"},
"set custom status fails on get user": {customStatus: "set", getFails: true, updateFails: false, expectedErr: MissingAccountError},
"set custom status fails on update user": {customStatus: "set", getFails: false, updateFails: true, expectedErr: "app.user.update.finding.app_error"},
"remove custom status fails on get user": {customStatus: "remove", getFails: true, updateFails: false, expectedErr: MissingAccountError},
"remove custom status fails on update user": {customStatus: "remove", getFails: false, updateFails: true, expectedErr: "app.user.update.finding.app_error"},
}
for name, tc := range tests {
@ -66,8 +66,17 @@ func TestCustomStatusErrors(t *testing.T) {
mockUserStore := mocks.UserStore{}
mockUserStore.On(tc.successFn, mock.Anything, mock.Anything).Return(mockUser, nil)
mockUserStore.On(tc.failFn, mock.Anything, mock.Anything).Return(nil, mockErr)
if tc.getFails {
mockUserStore.On("Get", mock.Anything, mock.Anything).Return(nil, mockErr)
} else {
mockUserStore.On("Get", mock.Anything, mock.Anything).Return(mockUser, nil)
}
if tc.updateFails {
mockUserStore.On("Update", mock.Anything, mock.Anything, mock.Anything).Return(nil, mockErr)
} else {
mockUserStore.On("Update", mock.Anything, mock.Anything, mock.Anything).Return(mockUser, nil)
}
var err error
mockSessionStore := mocks.SessionStore{}

View File

@ -484,7 +484,7 @@ func (a *App) UpdateTeamMemberRoles(c request.CTX, teamID string, userID string,
member.ExplicitRoles = strings.Join(newExplicitRoles, " ")
member, nErr = a.Srv().Store().Team().UpdateMember(member)
member, nErr = a.Srv().Store().Team().UpdateMember(c, member)
if nErr != nil {
var appErr *model.AppError
switch {
@ -523,7 +523,7 @@ func (a *App) UpdateTeamMemberSchemeRoles(c request.CTX, teamID string, userID s
member.ExplicitRoles = RemoveRoles([]string{model.TeamGuestRoleId, model.TeamUserRoleId, model.TeamAdminRoleId}, member.ExplicitRoles)
}
member, nErr := a.Srv().Store().Team().UpdateMember(member)
member, nErr := a.Srv().Store().Team().UpdateMember(c, member)
if nErr != nil {
var appErr *model.AppError
switch {
@ -699,13 +699,13 @@ func (a *App) AddUserToTeamByToken(c request.CTX, userID string, tokenID string)
for _, channel := range channels {
_, err := a.AddUserToChannel(c, user, channel, false)
if err != nil {
mlog.Warn("Error adding user to channel", mlog.Err(err))
c.Logger().Warn("Error adding user to channel", mlog.Err(err))
}
}
}
if err := a.DeleteToken(token); err != nil {
mlog.Warn("Error while deleting token", mlog.Err(err))
c.Logger().Warn("Error while deleting token", mlog.Err(err))
}
return team, teamMember, nil
@ -794,7 +794,7 @@ func (a *App) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User,
ExcludeTeam: false,
}
if _, err := a.createInitialSidebarCategories(c, user.Id, opts); err != nil {
mlog.Warn(
c.Logger().Warn(
"Encountered an issue creating default sidebar categories.",
mlog.String("user_id", user.Id),
mlog.String("team_id", team.Id),
@ -807,7 +807,7 @@ func (a *App) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User,
if !user.IsGuest() {
// Soft error if there is an issue joining the default channels
if err := a.JoinDefaultChannels(c, team.Id, user, shouldBeAdmin, userRequestorId); err != nil {
mlog.Warn(
c.Logger().Warn(
"Encountered an issue joining default channels.",
mlog.String("user_id", user.Id),
mlog.String("team_id", team.Id),
@ -1259,7 +1259,7 @@ func (a *App) LeaveTeam(c request.CTX, team *model.Team, user *model.User, reque
for _, channel := range channelList {
if !channel.IsGroupOrDirect() {
a.invalidateCacheForChannelMembers(channel.Id)
if nErr = a.Srv().Store().Channel().RemoveMember(channel.Id, user.Id); nErr != nil {
if nErr = a.Srv().Store().Channel().RemoveMember(c, channel.Id, user.Id); nErr != nil {
return model.NewAppError("LeaveTeam", "app.channel.remove_member.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
}
}
@ -1288,7 +1288,7 @@ func (a *App) LeaveTeam(c request.CTX, team *model.Team, user *model.User, reque
}
}
if err := a.ch.srv.teamService.RemoveTeamMember(teamMember); err != nil {
if err := a.ch.srv.teamService.RemoveTeamMember(c, teamMember); err != nil {
return model.NewAppError("RemoveTeamMemberFromTeam", "app.team.save_member.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}

View File

@ -327,14 +327,14 @@ func TestAddUserToTeamByToken(t *testing.T) {
)
guestEmail := rguest.Email
rguest.Email = "test@restricted.com"
_, err := th.App.Srv().Store().User().Update(rguest, false)
_, err := th.App.Srv().Store().User().Update(th.Context, rguest, false)
th.App.InvalidateCacheForUser(rguest.Id)
require.NoError(t, err)
require.NoError(t, th.App.Srv().Store().Token().Save(token))
_, _, appErr := th.App.AddUserToTeamByToken(th.Context, rguest.Id, token.Token)
require.Nil(t, appErr)
rguest.Email = guestEmail
_, err = th.App.Srv().Store().User().Update(rguest, false)
_, err = th.App.Srv().Store().User().Update(th.Context, rguest, false)
require.NoError(t, err)
})
@ -351,7 +351,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
TokenTypeGuestInvitation,
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
)
_, err = th.App.Srv().Store().User().Update(rguest, false)
_, err = th.App.Srv().Store().User().Update(th.Context, rguest, false)
require.NoError(t, err)
require.NoError(t, th.App.Srv().Store().Token().Save(token))
_, _, appErr := th.App.AddUserToTeamByToken(th.Context, rguest.Id, token.Token)
@ -1034,7 +1034,7 @@ func TestLeaveTeamPanic(t *testing.T) {
sqlstore.HasMaster(c.Context())
})
mockTeamStore.On("UpdateMember", mock.Anything).Return(nil, errors.New("repro error")) // This is the line that triggers the error
mockTeamStore.On("UpdateMember", mock.Anything, mock.Anything).Return(nil, errors.New("repro error")) // This is the line that triggers the error
mockStore.On("Channel").Return(&mockChannelStore)
mockStore.On("Preference").Return(&mockPreferenceStore)

View File

@ -179,7 +179,7 @@ func (ts *TeamService) JoinUserToTeam(c request.CTX, team *model.Team, user *mod
return nil, false, MaxMemberCountError
}
member, nErr := ts.store.UpdateMember(tm)
member, nErr := ts.store.UpdateMember(c, tm)
if nErr != nil {
return nil, false, nErr
}
@ -189,7 +189,7 @@ func (ts *TeamService) JoinUserToTeam(c request.CTX, team *model.Team, user *mod
// RemoveTeamMember removes the team member from the team. This method sends
// the websocket message before actually removing so the user being removed gets it.
func (ts *TeamService) RemoveTeamMember(teamMember *model.TeamMember) error {
func (ts *TeamService) RemoveTeamMember(rctx request.CTX, teamMember *model.TeamMember) error {
/*
MM-43850: send leave_team event to user using `ReliableClusterSend` to improve safety
*/
@ -212,7 +212,7 @@ func (ts *TeamService) RemoveTeamMember(teamMember *model.TeamMember) error {
teamMember.Roles = ""
teamMember.DeleteAt = model.GetMillis()
if _, nErr := ts.store.UpdateMember(teamMember); nErr != nil {
if _, nErr := ts.store.UpdateMember(rctx, teamMember); nErr != nil {
return nErr
}

View File

@ -84,7 +84,7 @@ func TestJoinUserToTeam(t *testing.T) {
member, _, err := th.service.JoinUserToTeam(th.Context, team, ruser)
require.NoError(t, err)
err = th.service.RemoveTeamMember(member)
err = th.service.RemoveTeamMember(th.Context, member)
require.NoError(t, err)
_, alreadyAdded, err := th.service.JoinUserToTeam(th.Context, team, ruser)
@ -120,7 +120,7 @@ func TestJoinUserToTeam(t *testing.T) {
member, _, err := th.service.JoinUserToTeam(th.Context, team, ruser1)
require.NoError(t, err)
err = th.service.RemoveTeamMember(member)
err = th.service.RemoveTeamMember(th.Context, member)
require.NoError(t, err)
_, _, err = th.service.JoinUserToTeam(th.Context, team, ruser2)
require.NoError(t, err)

View File

@ -115,7 +115,7 @@ func (a *App) runPluginsHook(c request.CTX, info *model.FileInfo, file io.Reader
}
} else {
if fileErr := a.RemoveFile(tmpPath); fileErr != nil {
mlog.Warn("Failed to remove file", mlog.Err(fileErr))
c.Logger().Warn("Failed to remove file", mlog.Err(fileErr))
}
}
@ -306,7 +306,7 @@ func (a *App) UploadData(c request.CTX, us *model.UploadSession, rd io.Reader) (
}
var storeErr error
if info, storeErr = a.Srv().Store().FileInfo().Save(info); storeErr != nil {
if info, storeErr = a.Srv().Store().FileInfo().Save(c, info); storeErr != nil {
var appErr *model.AppError
switch {
case errors.As(storeErr, &appErr):

View File

@ -885,7 +885,7 @@ func (a *App) SetProfileImageFromFile(c request.CTX, userID string, file io.Read
if err := a.Srv().Store().User().UpdateLastPictureUpdate(userID); err != nil {
c.Logger().Warn("Error with updating last picture update", mlog.Err(err))
}
a.invalidateUserCacheAndPublish(userID)
a.invalidateUserCacheAndPublish(c, userID)
a.onUserProfileChange(userID)
return nil
@ -937,7 +937,7 @@ func (a *App) userDeactivated(c request.CTX, userID string) *model.AppError {
}
if nErr := a.Srv().Store().OAuth().RemoveAuthDataByUserId(userID); nErr != nil {
mlog.Warn("unable to remove auth data by user id", mlog.Err(nErr))
c.Logger().Warn("unable to remove auth data by user id", mlog.Err(nErr))
}
return nil
@ -974,7 +974,7 @@ func (a *App) UpdateActive(c request.CTX, user *model.User, active bool) (*model
user.DeleteAt = user.UpdateAt
}
userUpdate, err := a.ch.srv.userService.UpdateUser(user, true)
userUpdate, err := a.ch.srv.userService.UpdateUser(c, user, true)
if err != nil {
var appErr *model.AppError
var invErr *store.ErrInvalidInput
@ -1222,7 +1222,7 @@ func (a *App) UpdateUser(c request.CTX, user *model.User, sendNotifications bool
}
}
userUpdate, err := a.ch.srv.userService.UpdateUser(user, false)
userUpdate, err := a.ch.srv.userService.UpdateUser(c, user, false)
if err != nil {
var appErr *model.AppError
var invErr *store.ErrInvalidInput
@ -1606,7 +1606,7 @@ func (a *App) UpdateUserRolesWithUser(c request.CTX, user *model.User, newRoles
user.Roles = newRoles
uchan := make(chan store.GenericStoreResult[*model.UserUpdate], 1)
go func() {
userUpdate, err := a.Srv().Store().User().Update(user, true)
userUpdate, err := a.Srv().Store().User().Update(c, user, true)
uchan <- store.GenericStoreResult[*model.UserUpdate]{Data: userUpdate, NErr: err}
close(uchan)
}()
@ -1689,7 +1689,7 @@ func (a *App) PermanentDeleteUser(c request.CTX, user *model.User) *model.AppErr
return model.NewAppError("PermanentDeleteUser", "app.preference.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
if err := a.Srv().Store().Channel().PermanentDeleteMembersByUser(user.Id); err != nil {
if err := a.Srv().Store().Channel().PermanentDeleteMembersByUser(c, user.Id); err != nil {
return model.NewAppError("PermanentDeleteUser", "app.channel.permanent_delete_members_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -1697,7 +1697,7 @@ func (a *App) PermanentDeleteUser(c request.CTX, user *model.User) *model.AppErr
return model.NewAppError("PermanentDeleteUser", "app.group.permanent_delete_members_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
if err := a.Srv().Store().Post().PermanentDeleteByUser(user.Id); err != nil {
if err := a.Srv().Store().Post().PermanentDeleteByUser(c, user.Id); err != nil {
return model.NewAppError("PermanentDeleteUser", "app.post.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -1756,7 +1756,7 @@ func (a *App) PermanentDeleteUser(c request.CTX, user *model.User) *model.AppErr
if errProfileImageExists != nil {
fileHandlingErrorsFound = true
mlog.Warn(
c.Logger().Warn(
"Error checking existence of profile image.",
mlog.String("path", profileImagePath),
mlog.Err(errProfileImageExists),
@ -1768,7 +1768,7 @@ func (a *App) PermanentDeleteUser(c request.CTX, user *model.User) *model.AppErr
if errRemoveDirectory != nil {
fileHandlingErrorsFound = true
mlog.Warn(
c.Logger().Warn(
"Unable to remove profile image directory",
mlog.String("path", profileImageDirectory),
mlog.Err(errRemoveDirectory),
@ -1776,7 +1776,7 @@ func (a *App) PermanentDeleteUser(c request.CTX, user *model.User) *model.AppErr
}
}
if _, err := a.Srv().Store().FileInfo().PermanentDeleteByUser(user.Id); err != nil {
if _, err := a.Srv().Store().FileInfo().PermanentDeleteByUser(c, user.Id); err != nil {
return model.NewAppError("PermanentDeleteUser", "app.file_info.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -1788,7 +1788,7 @@ func (a *App) PermanentDeleteUser(c request.CTX, user *model.User) *model.AppErr
return model.NewAppError("PermanentDeleteUser", "app.audit.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
if err := a.Srv().Store().Team().RemoveAllMembersByUser(user.Id); err != nil {
if err := a.Srv().Store().Team().RemoveAllMembersByUser(c, user.Id); err != nil {
return model.NewAppError("PermanentDeleteUser", "app.team.remove_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -1877,7 +1877,7 @@ func (a *App) VerifyEmailFromToken(c request.CTX, userSuppliedTokenString string
if user.Email != tokenData.Email {
a.Srv().Go(func() {
if err := a.Srv().EmailService.SendEmailChangeEmail(user.Email, tokenData.Email, user.Locale, a.GetSiteURL()); err != nil {
mlog.Error("Failed to send email change email", mlog.Err(err))
c.Logger().Error("Failed to send email change email", mlog.Err(err))
}
})
}
@ -1945,7 +1945,7 @@ func (a *App) VerifyUserEmail(userID, email string) *model.AppError {
return nil
}
func (a *App) SearchUsers(props *model.UserSearch, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
func (a *App) SearchUsers(rctx request.CTX, props *model.UserSearch, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
if props.WithoutTeam {
return a.SearchUsersWithoutTeam(props.Term, options)
}
@ -1964,7 +1964,7 @@ func (a *App) SearchUsers(props *model.UserSearch, options *model.UserSearchOpti
if props.NotInGroupId != "" {
return a.SearchUsersNotInGroup(props.NotInGroupId, props.Term, options)
}
return a.SearchUsersInTeam(props.TeamId, props.Term, options)
return a.SearchUsersInTeam(rctx, props.TeamId, props.Term, options)
}
func (a *App) SearchUsersInChannel(channelID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
@ -1994,10 +1994,10 @@ func (a *App) SearchUsersNotInChannel(teamID string, channelID string, term stri
return users, nil
}
func (a *App) SearchUsersInTeam(teamID, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
func (a *App) SearchUsersInTeam(rctx request.CTX, teamID, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
term = strings.TrimSpace(term)
users, err := a.Srv().Store().User().Search(teamID, term, options)
users, err := a.Srv().Store().User().Search(rctx, teamID, term, options)
if err != nil {
return nil, model.NewAppError("SearchUsersInTeam", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -2065,10 +2065,10 @@ func (a *App) SearchUsersNotInGroup(groupID string, term string, options *model.
return users, nil
}
func (a *App) AutocompleteUsersInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError) {
func (a *App) AutocompleteUsersInChannel(rctx request.CTX, teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError) {
term = strings.TrimSpace(term)
autocomplete, err := a.Srv().Store().User().AutocompleteUsersInChannel(teamID, channelID, term, options)
autocomplete, err := a.Srv().Store().User().AutocompleteUsersInChannel(rctx, teamID, channelID, term, options)
if err != nil {
return nil, model.NewAppError("AutocompleteUsersInChannel", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -2084,10 +2084,10 @@ func (a *App) AutocompleteUsersInChannel(teamID string, channelID string, term s
return autocomplete, nil
}
func (a *App) AutocompleteUsersInTeam(teamID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError) {
func (a *App) AutocompleteUsersInTeam(rctx request.CTX, teamID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError) {
term = strings.TrimSpace(term)
users, err := a.Srv().Store().User().Search(teamID, term, options)
users, err := a.Srv().Store().User().Search(rctx, teamID, term, options)
if err != nil {
return nil, model.NewAppError("AutocompleteUsersInTeam", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@ -2136,7 +2136,7 @@ func (a *App) UpdateOAuthUserAttrs(c request.CTX, userData io.Reader, user *mode
}
if userAttrsChanged {
users, err := a.Srv().Store().User().Update(user, true)
users, err := a.Srv().Store().User().Update(c, user, true)
if err != nil {
var appErr *model.AppError
var invErr *store.ErrInvalidInput
@ -2417,12 +2417,12 @@ func (a *App) PublishUserTyping(userID, channelID, parentId string) *model.AppEr
}
// invalidateUserCacheAndPublish Invalidates cache for a user and publishes user updated event
func (a *App) invalidateUserCacheAndPublish(userID string) {
func (a *App) invalidateUserCacheAndPublish(rctx request.CTX, userID string) {
a.InvalidateCacheForUser(userID)
user, userErr := a.GetUser(userID)
if userErr != nil {
mlog.Error("Error in getting users profile", mlog.String("user_id", userID), mlog.Err(userErr))
rctx.Logger().Error("Error in getting users profile", mlog.String("user_id", userID), mlog.Err(userErr))
return
}

View File

@ -131,7 +131,7 @@ func TestRestrictedViewMembers(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
options := model.UserSearchOptions{Limit: 100, ViewRestrictions: tc.Restrictions}
results, err := th.App.SearchUsers(&tc.Search, &options)
results, err := th.App.SearchUsers(th.Context, &tc.Search, &options)
require.Nil(t, err)
ids := []string{}
for _, result := range results {
@ -207,7 +207,7 @@ func TestRestrictedViewMembers(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
options := model.UserSearchOptions{Limit: 100, ViewRestrictions: tc.Restrictions}
results, err := th.App.SearchUsersInTeam(tc.TeamId, "test", &options)
results, err := th.App.SearchUsersInTeam(th.Context, tc.TeamId, "test", &options)
require.Nil(t, err)
ids := []string{}
for _, result := range results {
@ -283,7 +283,7 @@ func TestRestrictedViewMembers(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
options := model.UserSearchOptions{Limit: 100, ViewRestrictions: tc.Restrictions}
results, err := th.App.AutocompleteUsersInTeam(tc.TeamId, "tes", &options)
results, err := th.App.AutocompleteUsersInTeam(th.Context, tc.TeamId, "tes", &options)
require.Nil(t, err)
ids := []string{}
for _, result := range results.InTeam {
@ -367,7 +367,7 @@ func TestRestrictedViewMembers(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
options := model.UserSearchOptions{Limit: 100, ViewRestrictions: tc.Restrictions}
results, err := th.App.AutocompleteUsersInChannel(tc.TeamId, tc.ChannelId, "tes", &options)
results, err := th.App.AutocompleteUsersInChannel(th.Context, tc.TeamId, tc.ChannelId, "tes", &options)
require.Nil(t, err)
ids := []string{}
for _, result := range results.InChannel {

View File

@ -11,6 +11,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/i18n"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/platform/shared/mfa"
@ -197,8 +198,8 @@ func (us *UserService) GetUsersWithoutTeam(options *model.UserGetOptions) ([]*mo
return users, nil
}
func (us *UserService) UpdateUser(user *model.User, allowRoleUpdate bool) (*model.UserUpdate, error) {
return us.store.Update(user, allowRoleUpdate)
func (us *UserService) UpdateUser(rctx request.CTX, user *model.User, allowRoleUpdate bool) (*model.UserUpdate, error) {
return us.store.Update(rctx, user, allowRoleUpdate)
}
func (us *UserService) UpdateUserNotifyProps(userID string, props map[string]string) error {

View File

@ -12,6 +12,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/jobs"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/platform/services/configservice"
@ -33,6 +34,8 @@ func MakeWorker(jobServer *jobs.JobServer, app AppIface, s store.Store) *jobs.Si
execute := func(logger mlog.LoggerIFace, job *model.Job) error {
defer jobServer.HandleJobPanic(logger, job)
rctx := request.EmptyContext(logger)
importPath := *app.Config().ImportSettings.Directory
retentionTime := time.Duration(*app.Config().ImportSettings.RetentionDays) * 24 * time.Hour
imports, appErr := app.ListDirectory(importPath)
@ -76,7 +79,7 @@ func MakeWorker(jobServer *jobs.JobServer, app AppIface, s store.Store) *jobs.Si
multipleErrors.Append(storeErr)
continue
} else if storeErr == nil {
if storeErr = s.FileInfo().PermanentDelete(info.Id); storeErr != nil {
if storeErr = s.FileInfo().PermanentDelete(rctx, info.Id); storeErr != nil {
logger.Debug("Worker: Failed to delete FileInfo",
mlog.Err(storeErr), mlog.String("file_id", info.Id))
multipleErrors.Append(storeErr)

View File

@ -7,6 +7,7 @@ import (
"bytes"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
@ -253,8 +254,8 @@ func (s LocalCacheChannelStore) GetChannelsMemberCount(channelIDs []string) (_ m
return counts, nil
}
func (s LocalCacheChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
member, err := s.ChannelStore.UpdateMember(member)
func (s LocalCacheChannelStore) UpdateMember(rctx request.CTX, member *model.ChannelMember) (*model.ChannelMember, error) {
member, err := s.ChannelStore.UpdateMember(rctx, member)
if err != nil {
return nil, err
}
@ -273,8 +274,8 @@ func (s LocalCacheChannelStore) UpdateMultipleMembers(members []*model.ChannelMe
return members, nil
}
func (s LocalCacheChannelStore) RemoveMember(channelId, userId string) error {
err := s.ChannelStore.RemoveMember(channelId, userId)
func (s LocalCacheChannelStore) RemoveMember(rctx request.CTX, channelId, userId string) error {
err := s.ChannelStore.RemoveMember(rctx, channelId, userId)
if err != nil {
return err
}
@ -282,8 +283,8 @@ func (s LocalCacheChannelStore) RemoveMember(channelId, userId string) error {
return nil
}
func (s LocalCacheChannelStore) RemoveMembers(channelId string, userIds []string) error {
err := s.ChannelStore.RemoveMembers(channelId, userIds)
func (s LocalCacheChannelStore) RemoveMembers(rctx request.CTX, channelId string, userIds []string) error {
err := s.ChannelStore.RemoveMembers(rctx, channelId, userIds)
if err != nil {
return err
}

View File

@ -9,6 +9,7 @@ import (
"testing"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
@ -72,7 +73,7 @@ func StoreTestWithSqlStore(t *testing.T, f func(*testing.T, request.CTX, store.S
}
}
func initStores() {
func initStores(logger mlog.LoggerIFace) {
if testing.Short() {
return
}
@ -103,7 +104,7 @@ func initStores() {
eg.Go(func() error {
var err error
st.SqlStore, err = sqlstore.New(*st.SqlSettings, nil)
st.SqlStore, err = sqlstore.New(*st.SqlSettings, logger, nil)
if err != nil {
return err
}

View File

@ -184,7 +184,7 @@ func TestMain(m *testing.M) {
mainHelper = testlib.NewMainHelperWithOptions(nil)
defer mainHelper.Close()
initStores()
initStores(mainHelper.Logger)
mainHelper.Main(m)
tearDownStores()
}

View File

@ -651,7 +651,7 @@ func (s *OpenTracingLayerChannelStore) AnalyticsTypeCount(teamID string, channel
return result, err
}
func (s *OpenTracingLayerChannelStore) Autocomplete(userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelListWithTeamData, error) {
func (s *OpenTracingLayerChannelStore) Autocomplete(rctx request.CTX, userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelListWithTeamData, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.Autocomplete")
s.Root.Store.SetContext(newCtx)
@ -660,7 +660,7 @@ func (s *OpenTracingLayerChannelStore) Autocomplete(userID string, term string,
}()
defer span.Finish()
result, err := s.ChannelStore.Autocomplete(userID, term, includeDeleted, isGuest)
result, err := s.ChannelStore.Autocomplete(rctx, userID, term, includeDeleted, isGuest)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -669,7 +669,7 @@ func (s *OpenTracingLayerChannelStore) Autocomplete(userID string, term string,
return result, err
}
func (s *OpenTracingLayerChannelStore) AutocompleteInTeam(teamID string, userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelList, error) {
func (s *OpenTracingLayerChannelStore) AutocompleteInTeam(rctx request.CTX, teamID string, userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelList, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.AutocompleteInTeam")
s.Root.Store.SetContext(newCtx)
@ -678,7 +678,7 @@ func (s *OpenTracingLayerChannelStore) AutocompleteInTeam(teamID string, userID
}()
defer span.Finish()
result, err := s.ChannelStore.AutocompleteInTeam(teamID, userID, term, includeDeleted, isGuest)
result, err := s.ChannelStore.AutocompleteInTeam(rctx, teamID, userID, term, includeDeleted, isGuest)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -803,7 +803,7 @@ func (s *OpenTracingLayerChannelStore) CountUrgentPostsAfter(channelID string, t
return result, err
}
func (s *OpenTracingLayerChannelStore) CreateDirectChannel(userID *model.User, otherUserID *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error) {
func (s *OpenTracingLayerChannelStore) CreateDirectChannel(ctx request.CTX, userID *model.User, otherUserID *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.CreateDirectChannel")
s.Root.Store.SetContext(newCtx)
@ -812,7 +812,7 @@ func (s *OpenTracingLayerChannelStore) CreateDirectChannel(userID *model.User, o
}()
defer span.Finish()
result, err := s.ChannelStore.CreateDirectChannel(userID, otherUserID, channelOptions...)
result, err := s.ChannelStore.CreateDirectChannel(ctx, userID, otherUserID, channelOptions...)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -2090,7 +2090,7 @@ func (s *OpenTracingLayerChannelStore) MigrateChannelMembers(fromChannelID strin
return result, err
}
func (s *OpenTracingLayerChannelStore) PermanentDelete(channelID string) error {
func (s *OpenTracingLayerChannelStore) PermanentDelete(ctx request.CTX, channelID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDelete")
s.Root.Store.SetContext(newCtx)
@ -2099,7 +2099,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDelete(channelID string) error {
}()
defer span.Finish()
err := s.ChannelStore.PermanentDelete(channelID)
err := s.ChannelStore.PermanentDelete(ctx, channelID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -2126,7 +2126,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDeleteByTeam(teamID string) erro
return err
}
func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByChannel(channelID string) error {
func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByChannel(ctx request.CTX, channelID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDeleteMembersByChannel")
s.Root.Store.SetContext(newCtx)
@ -2135,7 +2135,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByChannel(channelID
}()
defer span.Finish()
err := s.ChannelStore.PermanentDeleteMembersByChannel(channelID)
err := s.ChannelStore.PermanentDeleteMembersByChannel(ctx, channelID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -2144,7 +2144,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByChannel(channelID
return err
}
func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByUser(userID string) error {
func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByUser(ctx request.CTX, userID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDeleteMembersByUser")
s.Root.Store.SetContext(newCtx)
@ -2153,7 +2153,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByUser(userID strin
}()
defer span.Finish()
err := s.ChannelStore.PermanentDeleteMembersByUser(userID)
err := s.ChannelStore.PermanentDeleteMembersByUser(ctx, userID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -2162,7 +2162,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByUser(userID strin
return err
}
func (s *OpenTracingLayerChannelStore) RemoveAllDeactivatedMembers(channelID string) error {
func (s *OpenTracingLayerChannelStore) RemoveAllDeactivatedMembers(ctx request.CTX, channelID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.RemoveAllDeactivatedMembers")
s.Root.Store.SetContext(newCtx)
@ -2171,7 +2171,7 @@ func (s *OpenTracingLayerChannelStore) RemoveAllDeactivatedMembers(channelID str
}()
defer span.Finish()
err := s.ChannelStore.RemoveAllDeactivatedMembers(channelID)
err := s.ChannelStore.RemoveAllDeactivatedMembers(ctx, channelID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -2180,7 +2180,7 @@ func (s *OpenTracingLayerChannelStore) RemoveAllDeactivatedMembers(channelID str
return err
}
func (s *OpenTracingLayerChannelStore) RemoveMember(channelID string, userID string) error {
func (s *OpenTracingLayerChannelStore) RemoveMember(ctx request.CTX, channelID string, userID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.RemoveMember")
s.Root.Store.SetContext(newCtx)
@ -2189,7 +2189,7 @@ func (s *OpenTracingLayerChannelStore) RemoveMember(channelID string, userID str
}()
defer span.Finish()
err := s.ChannelStore.RemoveMember(channelID, userID)
err := s.ChannelStore.RemoveMember(ctx, channelID, userID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -2198,7 +2198,7 @@ func (s *OpenTracingLayerChannelStore) RemoveMember(channelID string, userID str
return err
}
func (s *OpenTracingLayerChannelStore) RemoveMembers(channelID string, userIds []string) error {
func (s *OpenTracingLayerChannelStore) RemoveMembers(ctx request.CTX, channelID string, userIds []string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.RemoveMembers")
s.Root.Store.SetContext(newCtx)
@ -2207,7 +2207,7 @@ func (s *OpenTracingLayerChannelStore) RemoveMembers(channelID string, userIds [
}()
defer span.Finish()
err := s.ChannelStore.RemoveMembers(channelID, userIds)
err := s.ChannelStore.RemoveMembers(ctx, channelID, userIds)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -2270,7 +2270,7 @@ func (s *OpenTracingLayerChannelStore) Save(channel *model.Channel, maxChannelsP
return result, err
}
func (s *OpenTracingLayerChannelStore) SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error) {
func (s *OpenTracingLayerChannelStore) SaveDirectChannel(ctx request.CTX, channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.SaveDirectChannel")
s.Root.Store.SetContext(newCtx)
@ -2279,7 +2279,7 @@ func (s *OpenTracingLayerChannelStore) SaveDirectChannel(channel *model.Channel,
}()
defer span.Finish()
result, err := s.ChannelStore.SaveDirectChannel(channel, member1, member2)
result, err := s.ChannelStore.SaveDirectChannel(ctx, channel, member1, member2)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -2468,7 +2468,7 @@ func (s *OpenTracingLayerChannelStore) SetShared(channelId string, shared bool)
return err
}
func (s *OpenTracingLayerChannelStore) Update(channel *model.Channel) (*model.Channel, error) {
func (s *OpenTracingLayerChannelStore) Update(ctx request.CTX, channel *model.Channel) (*model.Channel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.Update")
s.Root.Store.SetContext(newCtx)
@ -2477,7 +2477,7 @@ func (s *OpenTracingLayerChannelStore) Update(channel *model.Channel) (*model.Ch
}()
defer span.Finish()
result, err := s.ChannelStore.Update(channel)
result, err := s.ChannelStore.Update(ctx, channel)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -2522,7 +2522,7 @@ func (s *OpenTracingLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.
return result, err
}
func (s *OpenTracingLayerChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
func (s *OpenTracingLayerChannelStore) UpdateMember(ctx request.CTX, member *model.ChannelMember) (*model.ChannelMember, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateMember")
s.Root.Store.SetContext(newCtx)
@ -2531,7 +2531,7 @@ func (s *OpenTracingLayerChannelStore) UpdateMember(member *model.ChannelMember)
}()
defer span.Finish()
result, err := s.ChannelStore.UpdateMember(member)
result, err := s.ChannelStore.UpdateMember(ctx, member)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -3579,7 +3579,7 @@ func (s *OpenTracingLayerEmojiStore) Search(name string, prefixOnly bool, limit
return result, err
}
func (s *OpenTracingLayerFileInfoStore) AttachToPost(fileID string, postID string, channelID string, creatorID string) error {
func (s *OpenTracingLayerFileInfoStore) AttachToPost(c request.CTX, fileID string, postID string, channelID string, creatorID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.AttachToPost")
s.Root.Store.SetContext(newCtx)
@ -3588,7 +3588,7 @@ func (s *OpenTracingLayerFileInfoStore) AttachToPost(fileID string, postID strin
}()
defer span.Finish()
err := s.FileInfoStore.AttachToPost(fileID, postID, channelID, creatorID)
err := s.FileInfoStore.AttachToPost(c, fileID, postID, channelID, creatorID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -3628,7 +3628,7 @@ func (s *OpenTracingLayerFileInfoStore) CountAll() (int64, error) {
return result, err
}
func (s *OpenTracingLayerFileInfoStore) DeleteForPost(postID string) (string, error) {
func (s *OpenTracingLayerFileInfoStore) DeleteForPost(c request.CTX, postID string) (string, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.DeleteForPost")
s.Root.Store.SetContext(newCtx)
@ -3637,7 +3637,7 @@ func (s *OpenTracingLayerFileInfoStore) DeleteForPost(postID string) (string, er
}()
defer span.Finish()
result, err := s.FileInfoStore.DeleteForPost(postID)
result, err := s.FileInfoStore.DeleteForPost(c, postID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -3839,7 +3839,7 @@ func (s *OpenTracingLayerFileInfoStore) InvalidateFileInfosForPostCache(postID s
}
func (s *OpenTracingLayerFileInfoStore) PermanentDelete(fileID string) error {
func (s *OpenTracingLayerFileInfoStore) PermanentDelete(c request.CTX, fileID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.PermanentDelete")
s.Root.Store.SetContext(newCtx)
@ -3848,7 +3848,7 @@ func (s *OpenTracingLayerFileInfoStore) PermanentDelete(fileID string) error {
}()
defer span.Finish()
err := s.FileInfoStore.PermanentDelete(fileID)
err := s.FileInfoStore.PermanentDelete(c, fileID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -3857,7 +3857,7 @@ func (s *OpenTracingLayerFileInfoStore) PermanentDelete(fileID string) error {
return err
}
func (s *OpenTracingLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
func (s *OpenTracingLayerFileInfoStore) PermanentDeleteBatch(ctx request.CTX, endTime int64, limit int64) (int64, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.PermanentDeleteBatch")
s.Root.Store.SetContext(newCtx)
@ -3866,7 +3866,7 @@ func (s *OpenTracingLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limi
}()
defer span.Finish()
result, err := s.FileInfoStore.PermanentDeleteBatch(endTime, limit)
result, err := s.FileInfoStore.PermanentDeleteBatch(ctx, endTime, limit)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -3875,7 +3875,7 @@ func (s *OpenTracingLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limi
return result, err
}
func (s *OpenTracingLayerFileInfoStore) PermanentDeleteByUser(userID string) (int64, error) {
func (s *OpenTracingLayerFileInfoStore) PermanentDeleteByUser(ctx request.CTX, userID string) (int64, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.PermanentDeleteByUser")
s.Root.Store.SetContext(newCtx)
@ -3884,7 +3884,7 @@ func (s *OpenTracingLayerFileInfoStore) PermanentDeleteByUser(userID string) (in
}()
defer span.Finish()
result, err := s.FileInfoStore.PermanentDeleteByUser(userID)
result, err := s.FileInfoStore.PermanentDeleteByUser(ctx, userID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -3893,7 +3893,7 @@ func (s *OpenTracingLayerFileInfoStore) PermanentDeleteByUser(userID string) (in
return result, err
}
func (s *OpenTracingLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, error) {
func (s *OpenTracingLayerFileInfoStore) Save(ctx request.CTX, info *model.FileInfo) (*model.FileInfo, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.Save")
s.Root.Store.SetContext(newCtx)
@ -3902,7 +3902,7 @@ func (s *OpenTracingLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileI
}()
defer span.Finish()
result, err := s.FileInfoStore.Save(info)
result, err := s.FileInfoStore.Save(ctx, info)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -3911,7 +3911,7 @@ func (s *OpenTracingLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileI
return result, err
}
func (s *OpenTracingLayerFileInfoStore) Search(paramsList []*model.SearchParams, userID string, teamID string, page int, perPage int) (*model.FileInfoList, error) {
func (s *OpenTracingLayerFileInfoStore) Search(ctx request.CTX, paramsList []*model.SearchParams, userID string, teamID string, page int, perPage int) (*model.FileInfoList, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.Search")
s.Root.Store.SetContext(newCtx)
@ -3920,7 +3920,7 @@ func (s *OpenTracingLayerFileInfoStore) Search(paramsList []*model.SearchParams,
}()
defer span.Finish()
result, err := s.FileInfoStore.Search(paramsList, userID, teamID, page, perPage)
result, err := s.FileInfoStore.Search(ctx, paramsList, userID, teamID, page, perPage)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -3929,7 +3929,7 @@ func (s *OpenTracingLayerFileInfoStore) Search(paramsList []*model.SearchParams,
return result, err
}
func (s *OpenTracingLayerFileInfoStore) SetContent(fileID string, content string) error {
func (s *OpenTracingLayerFileInfoStore) SetContent(ctx request.CTX, fileID string, content string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.SetContent")
s.Root.Store.SetContext(newCtx)
@ -3938,7 +3938,7 @@ func (s *OpenTracingLayerFileInfoStore) SetContent(fileID string, content string
}()
defer span.Finish()
err := s.FileInfoStore.SetContent(fileID, content)
err := s.FileInfoStore.SetContent(ctx, fileID, content)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -3947,7 +3947,7 @@ func (s *OpenTracingLayerFileInfoStore) SetContent(fileID string, content string
return err
}
func (s *OpenTracingLayerFileInfoStore) Upsert(info *model.FileInfo) (*model.FileInfo, error) {
func (s *OpenTracingLayerFileInfoStore) Upsert(rctx request.CTX, info *model.FileInfo) (*model.FileInfo, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.Upsert")
s.Root.Store.SetContext(newCtx)
@ -3956,7 +3956,7 @@ func (s *OpenTracingLayerFileInfoStore) Upsert(info *model.FileInfo) (*model.Fil
}()
defer span.Finish()
result, err := s.FileInfoStore.Upsert(info)
result, err := s.FileInfoStore.Upsert(rctx, info)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -6102,7 +6102,7 @@ func (s *OpenTracingLayerPostStore) ClearCaches() {
}
func (s *OpenTracingLayerPostStore) Delete(postID string, timestamp int64, deleteByID string) error {
func (s *OpenTracingLayerPostStore) Delete(rctx request.CTX, postID string, timestamp int64, deleteByID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.Delete")
s.Root.Store.SetContext(newCtx)
@ -6111,7 +6111,7 @@ func (s *OpenTracingLayerPostStore) Delete(postID string, timestamp int64, delet
}()
defer span.Finish()
err := s.PostStore.Delete(postID, timestamp, deleteByID)
err := s.PostStore.Delete(rctx, postID, timestamp, deleteByID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -6653,7 +6653,7 @@ func (s *OpenTracingLayerPostStore) InvalidateLastPostTimeCache(channelID string
}
func (s *OpenTracingLayerPostStore) Overwrite(post *model.Post) (*model.Post, error) {
func (s *OpenTracingLayerPostStore) Overwrite(rctx request.CTX, post *model.Post) (*model.Post, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.Overwrite")
s.Root.Store.SetContext(newCtx)
@ -6662,7 +6662,7 @@ func (s *OpenTracingLayerPostStore) Overwrite(post *model.Post) (*model.Post, er
}()
defer span.Finish()
result, err := s.PostStore.Overwrite(post)
result, err := s.PostStore.Overwrite(rctx, post)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -6725,7 +6725,7 @@ func (s *OpenTracingLayerPostStore) PermanentDeleteBatchForRetentionPolicies(now
return result, resultVar1, err
}
func (s *OpenTracingLayerPostStore) PermanentDeleteByChannel(channelID string) error {
func (s *OpenTracingLayerPostStore) PermanentDeleteByChannel(rctx request.CTX, channelID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.PermanentDeleteByChannel")
s.Root.Store.SetContext(newCtx)
@ -6734,7 +6734,7 @@ func (s *OpenTracingLayerPostStore) PermanentDeleteByChannel(channelID string) e
}()
defer span.Finish()
err := s.PostStore.PermanentDeleteByChannel(channelID)
err := s.PostStore.PermanentDeleteByChannel(rctx, channelID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -6743,7 +6743,7 @@ func (s *OpenTracingLayerPostStore) PermanentDeleteByChannel(channelID string) e
return err
}
func (s *OpenTracingLayerPostStore) PermanentDeleteByUser(userID string) error {
func (s *OpenTracingLayerPostStore) PermanentDeleteByUser(rctx request.CTX, userID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.PermanentDeleteByUser")
s.Root.Store.SetContext(newCtx)
@ -6752,7 +6752,7 @@ func (s *OpenTracingLayerPostStore) PermanentDeleteByUser(userID string) error {
}()
defer span.Finish()
err := s.PostStore.PermanentDeleteByUser(userID)
err := s.PostStore.PermanentDeleteByUser(rctx, userID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -6815,7 +6815,7 @@ func (s *OpenTracingLayerPostStore) Search(teamID string, userID string, params
return result, err
}
func (s *OpenTracingLayerPostStore) SearchPostsForUser(paramsList []*model.SearchParams, userID string, teamID string, page int, perPage int) (*model.PostSearchResults, error) {
func (s *OpenTracingLayerPostStore) SearchPostsForUser(rctx request.CTX, paramsList []*model.SearchParams, userID string, teamID string, page int, perPage int) (*model.PostSearchResults, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.SearchPostsForUser")
s.Root.Store.SetContext(newCtx)
@ -6824,7 +6824,7 @@ func (s *OpenTracingLayerPostStore) SearchPostsForUser(paramsList []*model.Searc
}()
defer span.Finish()
result, err := s.PostStore.SearchPostsForUser(paramsList, userID, teamID, page, perPage)
result, err := s.PostStore.SearchPostsForUser(rctx, paramsList, userID, teamID, page, perPage)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -6851,7 +6851,7 @@ func (s *OpenTracingLayerPostStore) SetPostReminder(reminder *model.PostReminder
return err
}
func (s *OpenTracingLayerPostStore) Update(newPost *model.Post, oldPost *model.Post) (*model.Post, error) {
func (s *OpenTracingLayerPostStore) Update(rctx request.CTX, newPost *model.Post, oldPost *model.Post) (*model.Post, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.Update")
s.Root.Store.SetContext(newCtx)
@ -6860,7 +6860,7 @@ func (s *OpenTracingLayerPostStore) Update(newPost *model.Post, oldPost *model.P
}()
defer span.Finish()
result, err := s.PostStore.Update(newPost, oldPost)
result, err := s.PostStore.Update(rctx, newPost, oldPost)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -10045,7 +10045,7 @@ func (s *OpenTracingLayerTeamStore) RemoveAllMembersByTeam(teamID string) error
return err
}
func (s *OpenTracingLayerTeamStore) RemoveAllMembersByUser(userID string) error {
func (s *OpenTracingLayerTeamStore) RemoveAllMembersByUser(ctx request.CTX, userID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.RemoveAllMembersByUser")
s.Root.Store.SetContext(newCtx)
@ -10054,7 +10054,7 @@ func (s *OpenTracingLayerTeamStore) RemoveAllMembersByUser(userID string) error
}()
defer span.Finish()
err := s.TeamStore.RemoveAllMembersByUser(userID)
err := s.TeamStore.RemoveAllMembersByUser(ctx, userID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -10063,7 +10063,7 @@ func (s *OpenTracingLayerTeamStore) RemoveAllMembersByUser(userID string) error
return err
}
func (s *OpenTracingLayerTeamStore) RemoveMember(teamID string, userID string) error {
func (s *OpenTracingLayerTeamStore) RemoveMember(rctx request.CTX, teamID string, userID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.RemoveMember")
s.Root.Store.SetContext(newCtx)
@ -10072,7 +10072,7 @@ func (s *OpenTracingLayerTeamStore) RemoveMember(teamID string, userID string) e
}()
defer span.Finish()
err := s.TeamStore.RemoveMember(teamID, userID)
err := s.TeamStore.RemoveMember(rctx, teamID, userID)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -10081,7 +10081,7 @@ func (s *OpenTracingLayerTeamStore) RemoveMember(teamID string, userID string) e
return err
}
func (s *OpenTracingLayerTeamStore) RemoveMembers(teamID string, userIds []string) error {
func (s *OpenTracingLayerTeamStore) RemoveMembers(rctx request.CTX, teamID string, userIds []string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.RemoveMembers")
s.Root.Store.SetContext(newCtx)
@ -10090,7 +10090,7 @@ func (s *OpenTracingLayerTeamStore) RemoveMembers(teamID string, userIds []strin
}()
defer span.Finish()
err := s.TeamStore.RemoveMembers(teamID, userIds)
err := s.TeamStore.RemoveMembers(rctx, teamID, userIds)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -10279,7 +10279,7 @@ func (s *OpenTracingLayerTeamStore) UpdateLastTeamIconUpdate(teamID string, curT
return err
}
func (s *OpenTracingLayerTeamStore) UpdateMember(member *model.TeamMember) (*model.TeamMember, error) {
func (s *OpenTracingLayerTeamStore) UpdateMember(rctx request.CTX, member *model.TeamMember) (*model.TeamMember, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.UpdateMember")
s.Root.Store.SetContext(newCtx)
@ -10288,7 +10288,7 @@ func (s *OpenTracingLayerTeamStore) UpdateMember(member *model.TeamMember) (*mod
}()
defer span.Finish()
result, err := s.TeamStore.UpdateMember(member)
result, err := s.TeamStore.UpdateMember(rctx, member)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -11174,7 +11174,7 @@ func (s *OpenTracingLayerUserStore) AnalyticsGetSystemAdminCount() (int64, error
return result, err
}
func (s *OpenTracingLayerUserStore) AutocompleteUsersInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error) {
func (s *OpenTracingLayerUserStore) AutocompleteUsersInChannel(rctx request.CTX, teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "UserStore.AutocompleteUsersInChannel")
s.Root.Store.SetContext(newCtx)
@ -11183,7 +11183,7 @@ func (s *OpenTracingLayerUserStore) AutocompleteUsersInChannel(teamID string, ch
}()
defer span.Finish()
result, err := s.UserStore.AutocompleteUsersInChannel(teamID, channelID, term, options)
result, err := s.UserStore.AutocompleteUsersInChannel(rctx, teamID, channelID, term, options)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -12129,7 +12129,7 @@ func (s *OpenTracingLayerUserStore) Save(user *model.User) (*model.User, error)
return result, err
}
func (s *OpenTracingLayerUserStore) Search(teamID string, term string, options *model.UserSearchOptions) ([]*model.User, error) {
func (s *OpenTracingLayerUserStore) Search(rctx request.CTX, teamID string, term string, options *model.UserSearchOptions) ([]*model.User, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "UserStore.Search")
s.Root.Store.SetContext(newCtx)
@ -12138,7 +12138,7 @@ func (s *OpenTracingLayerUserStore) Search(teamID string, term string, options *
}()
defer span.Finish()
result, err := s.UserStore.Search(teamID, term, options)
result, err := s.UserStore.Search(rctx, teamID, term, options)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@ -12255,7 +12255,7 @@ func (s *OpenTracingLayerUserStore) SearchWithoutTeam(term string, options *mode
return result, err
}
func (s *OpenTracingLayerUserStore) Update(user *model.User, allowRoleUpdate bool) (*model.UserUpdate, error) {
func (s *OpenTracingLayerUserStore) Update(rctx request.CTX, user *model.User, allowRoleUpdate bool) (*model.UserUpdate, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "UserStore.Update")
s.Root.Store.SetContext(newCtx)
@ -12264,7 +12264,7 @@ func (s *OpenTracingLayerUserStore) Update(user *model.User, allowRoleUpdate boo
}()
defer span.Finish()
result, err := s.UserStore.Update(user, allowRoleUpdate)
result, err := s.UserStore.Update(rctx, user, allowRoleUpdate)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)

View File

@ -701,11 +701,11 @@ func (s *RetryLayerChannelStore) AnalyticsTypeCount(teamID string, channelType m
}
func (s *RetryLayerChannelStore) Autocomplete(userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelListWithTeamData, error) {
func (s *RetryLayerChannelStore) Autocomplete(rctx request.CTX, userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelListWithTeamData, error) {
tries := 0
for {
result, err := s.ChannelStore.Autocomplete(userID, term, includeDeleted, isGuest)
result, err := s.ChannelStore.Autocomplete(rctx, userID, term, includeDeleted, isGuest)
if err == nil {
return result, nil
}
@ -722,11 +722,11 @@ func (s *RetryLayerChannelStore) Autocomplete(userID string, term string, includ
}
func (s *RetryLayerChannelStore) AutocompleteInTeam(teamID string, userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelList, error) {
func (s *RetryLayerChannelStore) AutocompleteInTeam(rctx request.CTX, teamID string, userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelList, error) {
tries := 0
for {
result, err := s.ChannelStore.AutocompleteInTeam(teamID, userID, term, includeDeleted, isGuest)
result, err := s.ChannelStore.AutocompleteInTeam(rctx, teamID, userID, term, includeDeleted, isGuest)
if err == nil {
return result, nil
}
@ -860,11 +860,11 @@ func (s *RetryLayerChannelStore) CountUrgentPostsAfter(channelID string, timesta
}
func (s *RetryLayerChannelStore) CreateDirectChannel(userID *model.User, otherUserID *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error) {
func (s *RetryLayerChannelStore) CreateDirectChannel(ctx request.CTX, userID *model.User, otherUserID *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error) {
tries := 0
for {
result, err := s.ChannelStore.CreateDirectChannel(userID, otherUserID, channelOptions...)
result, err := s.ChannelStore.CreateDirectChannel(ctx, userID, otherUserID, channelOptions...)
if err == nil {
return result, nil
}
@ -2279,11 +2279,11 @@ func (s *RetryLayerChannelStore) MigrateChannelMembers(fromChannelID string, fro
}
func (s *RetryLayerChannelStore) PermanentDelete(channelID string) error {
func (s *RetryLayerChannelStore) PermanentDelete(ctx request.CTX, channelID string) error {
tries := 0
for {
err := s.ChannelStore.PermanentDelete(channelID)
err := s.ChannelStore.PermanentDelete(ctx, channelID)
if err == nil {
return nil
}
@ -2321,11 +2321,11 @@ func (s *RetryLayerChannelStore) PermanentDeleteByTeam(teamID string) error {
}
func (s *RetryLayerChannelStore) PermanentDeleteMembersByChannel(channelID string) error {
func (s *RetryLayerChannelStore) PermanentDeleteMembersByChannel(ctx request.CTX, channelID string) error {
tries := 0
for {
err := s.ChannelStore.PermanentDeleteMembersByChannel(channelID)
err := s.ChannelStore.PermanentDeleteMembersByChannel(ctx, channelID)
if err == nil {
return nil
}
@ -2342,11 +2342,11 @@ func (s *RetryLayerChannelStore) PermanentDeleteMembersByChannel(channelID strin
}
func (s *RetryLayerChannelStore) PermanentDeleteMembersByUser(userID string) error {
func (s *RetryLayerChannelStore) PermanentDeleteMembersByUser(ctx request.CTX, userID string) error {
tries := 0
for {
err := s.ChannelStore.PermanentDeleteMembersByUser(userID)
err := s.ChannelStore.PermanentDeleteMembersByUser(ctx, userID)
if err == nil {
return nil
}
@ -2363,11 +2363,11 @@ func (s *RetryLayerChannelStore) PermanentDeleteMembersByUser(userID string) err
}
func (s *RetryLayerChannelStore) RemoveAllDeactivatedMembers(channelID string) error {
func (s *RetryLayerChannelStore) RemoveAllDeactivatedMembers(ctx request.CTX, channelID string) error {
tries := 0
for {
err := s.ChannelStore.RemoveAllDeactivatedMembers(channelID)
err := s.ChannelStore.RemoveAllDeactivatedMembers(ctx, channelID)
if err == nil {
return nil
}
@ -2384,11 +2384,11 @@ func (s *RetryLayerChannelStore) RemoveAllDeactivatedMembers(channelID string) e
}
func (s *RetryLayerChannelStore) RemoveMember(channelID string, userID string) error {
func (s *RetryLayerChannelStore) RemoveMember(ctx request.CTX, channelID string, userID string) error {
tries := 0
for {
err := s.ChannelStore.RemoveMember(channelID, userID)
err := s.ChannelStore.RemoveMember(ctx, channelID, userID)
if err == nil {
return nil
}
@ -2405,11 +2405,11 @@ func (s *RetryLayerChannelStore) RemoveMember(channelID string, userID string) e
}
func (s *RetryLayerChannelStore) RemoveMembers(channelID string, userIds []string) error {
func (s *RetryLayerChannelStore) RemoveMembers(ctx request.CTX, channelID string, userIds []string) error {
tries := 0
for {
err := s.ChannelStore.RemoveMembers(channelID, userIds)
err := s.ChannelStore.RemoveMembers(ctx, channelID, userIds)
if err == nil {
return nil
}
@ -2489,11 +2489,11 @@ func (s *RetryLayerChannelStore) Save(channel *model.Channel, maxChannelsPerTeam
}
func (s *RetryLayerChannelStore) SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error) {
func (s *RetryLayerChannelStore) SaveDirectChannel(ctx request.CTX, channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error) {
tries := 0
for {
result, err := s.ChannelStore.SaveDirectChannel(channel, member1, member2)
result, err := s.ChannelStore.SaveDirectChannel(ctx, channel, member1, member2)
if err == nil {
return result, nil
}
@ -2720,11 +2720,11 @@ func (s *RetryLayerChannelStore) SetShared(channelId string, shared bool) error
}
func (s *RetryLayerChannelStore) Update(channel *model.Channel) (*model.Channel, error) {
func (s *RetryLayerChannelStore) Update(ctx request.CTX, channel *model.Channel) (*model.Channel, error) {
tries := 0
for {
result, err := s.ChannelStore.Update(channel)
result, err := s.ChannelStore.Update(ctx, channel)
if err == nil {
return result, nil
}
@ -2783,11 +2783,11 @@ func (s *RetryLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post,
}
func (s *RetryLayerChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
func (s *RetryLayerChannelStore) UpdateMember(ctx request.CTX, member *model.ChannelMember) (*model.ChannelMember, error) {
tries := 0
for {
result, err := s.ChannelStore.UpdateMember(member)
result, err := s.ChannelStore.UpdateMember(ctx, member)
if err == nil {
return result, nil
}
@ -4007,11 +4007,11 @@ func (s *RetryLayerEmojiStore) Search(name string, prefixOnly bool, limit int) (
}
func (s *RetryLayerFileInfoStore) AttachToPost(fileID string, postID string, channelID string, creatorID string) error {
func (s *RetryLayerFileInfoStore) AttachToPost(c request.CTX, fileID string, postID string, channelID string, creatorID string) error {
tries := 0
for {
err := s.FileInfoStore.AttachToPost(fileID, postID, channelID, creatorID)
err := s.FileInfoStore.AttachToPost(c, fileID, postID, channelID, creatorID)
if err == nil {
return nil
}
@ -4055,11 +4055,11 @@ func (s *RetryLayerFileInfoStore) CountAll() (int64, error) {
}
func (s *RetryLayerFileInfoStore) DeleteForPost(postID string) (string, error) {
func (s *RetryLayerFileInfoStore) DeleteForPost(c request.CTX, postID string) (string, error) {
tries := 0
for {
result, err := s.FileInfoStore.DeleteForPost(postID)
result, err := s.FileInfoStore.DeleteForPost(c, postID)
if err == nil {
return result, nil
}
@ -4292,11 +4292,11 @@ func (s *RetryLayerFileInfoStore) InvalidateFileInfosForPostCache(postID string,
}
func (s *RetryLayerFileInfoStore) PermanentDelete(fileID string) error {
func (s *RetryLayerFileInfoStore) PermanentDelete(c request.CTX, fileID string) error {
tries := 0
for {
err := s.FileInfoStore.PermanentDelete(fileID)
err := s.FileInfoStore.PermanentDelete(c, fileID)
if err == nil {
return nil
}
@ -4313,11 +4313,11 @@ func (s *RetryLayerFileInfoStore) PermanentDelete(fileID string) error {
}
func (s *RetryLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
func (s *RetryLayerFileInfoStore) PermanentDeleteBatch(ctx request.CTX, endTime int64, limit int64) (int64, error) {
tries := 0
for {
result, err := s.FileInfoStore.PermanentDeleteBatch(endTime, limit)
result, err := s.FileInfoStore.PermanentDeleteBatch(ctx, endTime, limit)
if err == nil {
return result, nil
}
@ -4334,11 +4334,11 @@ func (s *RetryLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int6
}
func (s *RetryLayerFileInfoStore) PermanentDeleteByUser(userID string) (int64, error) {
func (s *RetryLayerFileInfoStore) PermanentDeleteByUser(ctx request.CTX, userID string) (int64, error) {
tries := 0
for {
result, err := s.FileInfoStore.PermanentDeleteByUser(userID)
result, err := s.FileInfoStore.PermanentDeleteByUser(ctx, userID)
if err == nil {
return result, nil
}
@ -4355,11 +4355,11 @@ func (s *RetryLayerFileInfoStore) PermanentDeleteByUser(userID string) (int64, e
}
func (s *RetryLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, error) {
func (s *RetryLayerFileInfoStore) Save(ctx request.CTX, info *model.FileInfo) (*model.FileInfo, error) {
tries := 0
for {
result, err := s.FileInfoStore.Save(info)
result, err := s.FileInfoStore.Save(ctx, info)
if err == nil {
return result, nil
}
@ -4376,11 +4376,11 @@ func (s *RetryLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, e
}
func (s *RetryLayerFileInfoStore) Search(paramsList []*model.SearchParams, userID string, teamID string, page int, perPage int) (*model.FileInfoList, error) {
func (s *RetryLayerFileInfoStore) Search(ctx request.CTX, paramsList []*model.SearchParams, userID string, teamID string, page int, perPage int) (*model.FileInfoList, error) {
tries := 0
for {
result, err := s.FileInfoStore.Search(paramsList, userID, teamID, page, perPage)
result, err := s.FileInfoStore.Search(ctx, paramsList, userID, teamID, page, perPage)
if err == nil {
return result, nil
}
@ -4397,11 +4397,11 @@ func (s *RetryLayerFileInfoStore) Search(paramsList []*model.SearchParams, userI
}
func (s *RetryLayerFileInfoStore) SetContent(fileID string, content string) error {
func (s *RetryLayerFileInfoStore) SetContent(ctx request.CTX, fileID string, content string) error {
tries := 0
for {
err := s.FileInfoStore.SetContent(fileID, content)
err := s.FileInfoStore.SetContent(ctx, fileID, content)
if err == nil {
return nil
}
@ -4418,11 +4418,11 @@ func (s *RetryLayerFileInfoStore) SetContent(fileID string, content string) erro
}
func (s *RetryLayerFileInfoStore) Upsert(info *model.FileInfo) (*model.FileInfo, error) {
func (s *RetryLayerFileInfoStore) Upsert(rctx request.CTX, info *model.FileInfo) (*model.FileInfo, error) {
tries := 0
for {
result, err := s.FileInfoStore.Upsert(info)
result, err := s.FileInfoStore.Upsert(rctx, info)
if err == nil {
return result, nil
}
@ -6923,11 +6923,11 @@ func (s *RetryLayerPostStore) ClearCaches() {
}
func (s *RetryLayerPostStore) Delete(postID string, timestamp int64, deleteByID string) error {
func (s *RetryLayerPostStore) Delete(rctx request.CTX, postID string, timestamp int64, deleteByID string) error {
tries := 0
for {
err := s.PostStore.Delete(postID, timestamp, deleteByID)
err := s.PostStore.Delete(rctx, postID, timestamp, deleteByID)
if err == nil {
return nil
}
@ -7529,11 +7529,11 @@ func (s *RetryLayerPostStore) InvalidateLastPostTimeCache(channelID string) {
}
func (s *RetryLayerPostStore) Overwrite(post *model.Post) (*model.Post, error) {
func (s *RetryLayerPostStore) Overwrite(rctx request.CTX, post *model.Post) (*model.Post, error) {
tries := 0
for {
result, err := s.PostStore.Overwrite(post)
result, err := s.PostStore.Overwrite(rctx, post)
if err == nil {
return result, nil
}
@ -7613,11 +7613,11 @@ func (s *RetryLayerPostStore) PermanentDeleteBatchForRetentionPolicies(now int64
}
func (s *RetryLayerPostStore) PermanentDeleteByChannel(channelID string) error {
func (s *RetryLayerPostStore) PermanentDeleteByChannel(rctx request.CTX, channelID string) error {
tries := 0
for {
err := s.PostStore.PermanentDeleteByChannel(channelID)
err := s.PostStore.PermanentDeleteByChannel(rctx, channelID)
if err == nil {
return nil
}
@ -7634,11 +7634,11 @@ func (s *RetryLayerPostStore) PermanentDeleteByChannel(channelID string) error {
}
func (s *RetryLayerPostStore) PermanentDeleteByUser(userID string) error {
func (s *RetryLayerPostStore) PermanentDeleteByUser(rctx request.CTX, userID string) error {
tries := 0
for {
err := s.PostStore.PermanentDeleteByUser(userID)
err := s.PostStore.PermanentDeleteByUser(rctx, userID)
if err == nil {
return nil
}
@ -7718,11 +7718,11 @@ func (s *RetryLayerPostStore) Search(teamID string, userID string, params *model
}
func (s *RetryLayerPostStore) SearchPostsForUser(paramsList []*model.SearchParams, userID string, teamID string, page int, perPage int) (*model.PostSearchResults, error) {
func (s *RetryLayerPostStore) SearchPostsForUser(rctx request.CTX, paramsList []*model.SearchParams, userID string, teamID string, page int, perPage int) (*model.PostSearchResults, error) {
tries := 0
for {
result, err := s.PostStore.SearchPostsForUser(paramsList, userID, teamID, page, perPage)
result, err := s.PostStore.SearchPostsForUser(rctx, paramsList, userID, teamID, page, perPage)
if err == nil {
return result, nil
}
@ -7760,11 +7760,11 @@ func (s *RetryLayerPostStore) SetPostReminder(reminder *model.PostReminder) erro
}
func (s *RetryLayerPostStore) Update(newPost *model.Post, oldPost *model.Post) (*model.Post, error) {
func (s *RetryLayerPostStore) Update(rctx request.CTX, newPost *model.Post, oldPost *model.Post) (*model.Post, error) {
tries := 0
for {
result, err := s.PostStore.Update(newPost, oldPost)
result, err := s.PostStore.Update(rctx, newPost, oldPost)
if err == nil {
return result, nil
}
@ -11468,11 +11468,11 @@ func (s *RetryLayerTeamStore) RemoveAllMembersByTeam(teamID string) error {
}
func (s *RetryLayerTeamStore) RemoveAllMembersByUser(userID string) error {
func (s *RetryLayerTeamStore) RemoveAllMembersByUser(ctx request.CTX, userID string) error {
tries := 0
for {
err := s.TeamStore.RemoveAllMembersByUser(userID)
err := s.TeamStore.RemoveAllMembersByUser(ctx, userID)
if err == nil {
return nil
}
@ -11489,11 +11489,11 @@ func (s *RetryLayerTeamStore) RemoveAllMembersByUser(userID string) error {
}
func (s *RetryLayerTeamStore) RemoveMember(teamID string, userID string) error {
func (s *RetryLayerTeamStore) RemoveMember(rctx request.CTX, teamID string, userID string) error {
tries := 0
for {
err := s.TeamStore.RemoveMember(teamID, userID)
err := s.TeamStore.RemoveMember(rctx, teamID, userID)
if err == nil {
return nil
}
@ -11510,11 +11510,11 @@ func (s *RetryLayerTeamStore) RemoveMember(teamID string, userID string) error {
}
func (s *RetryLayerTeamStore) RemoveMembers(teamID string, userIds []string) error {
func (s *RetryLayerTeamStore) RemoveMembers(rctx request.CTX, teamID string, userIds []string) error {
tries := 0
for {
err := s.TeamStore.RemoveMembers(teamID, userIds)
err := s.TeamStore.RemoveMembers(rctx, teamID, userIds)
if err == nil {
return nil
}
@ -11741,11 +11741,11 @@ func (s *RetryLayerTeamStore) UpdateLastTeamIconUpdate(teamID string, curTime in
}
func (s *RetryLayerTeamStore) UpdateMember(member *model.TeamMember) (*model.TeamMember, error) {
func (s *RetryLayerTeamStore) UpdateMember(rctx request.CTX, member *model.TeamMember) (*model.TeamMember, error) {
tries := 0
for {
result, err := s.TeamStore.UpdateMember(member)
result, err := s.TeamStore.UpdateMember(rctx, member)
if err == nil {
return result, nil
}
@ -12776,11 +12776,11 @@ func (s *RetryLayerUserStore) AnalyticsGetSystemAdminCount() (int64, error) {
}
func (s *RetryLayerUserStore) AutocompleteUsersInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error) {
func (s *RetryLayerUserStore) AutocompleteUsersInChannel(rctx request.CTX, teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error) {
tries := 0
for {
result, err := s.UserStore.AutocompleteUsersInChannel(teamID, channelID, term, options)
result, err := s.UserStore.AutocompleteUsersInChannel(rctx, teamID, channelID, term, options)
if err == nil {
return result, nil
}
@ -13826,11 +13826,11 @@ func (s *RetryLayerUserStore) Save(user *model.User) (*model.User, error) {
}
func (s *RetryLayerUserStore) Search(teamID string, term string, options *model.UserSearchOptions) ([]*model.User, error) {
func (s *RetryLayerUserStore) Search(rctx request.CTX, teamID string, term string, options *model.UserSearchOptions) ([]*model.User, error) {
tries := 0
for {
result, err := s.UserStore.Search(teamID, term, options)
result, err := s.UserStore.Search(rctx, teamID, term, options)
if err == nil {
return result, nil
}
@ -13973,11 +13973,11 @@ func (s *RetryLayerUserStore) SearchWithoutTeam(term string, options *model.User
}
func (s *RetryLayerUserStore) Update(user *model.User, allowRoleUpdate bool) (*model.UserUpdate, error) {
func (s *RetryLayerUserStore) Update(rctx request.CTX, user *model.User, allowRoleUpdate bool) (*model.UserUpdate, error) {
tries := 0
for {
result, err := s.UserStore.Update(user, allowRoleUpdate)
result, err := s.UserStore.Update(rctx, user, allowRoleUpdate)
if err == nil {
return result, nil
}

View File

@ -10,6 +10,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/platform/services/searchengine"
)
@ -19,149 +20,155 @@ type SearchChannelStore struct {
rootStore *SearchStore
}
func (c *SearchChannelStore) deleteChannelIndex(channel *model.Channel) {
func (c *SearchChannelStore) deleteChannelIndex(rctx request.CTX, channel *model.Channel) {
if channel.Type == model.ChannelTypeOpen {
for _, engine := range c.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteChannel(channel); err != nil {
mlog.Warn("Encountered error deleting channel", mlog.String("channel_id", channel.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
rctx.Logger().Warn("Encountered error deleting channel", mlog.String("channel_id", channel.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
mlog.Debug("Removed channel from index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("channel_id", channel.Id))
rctx.Logger().Debug("Removed channel from index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("channel_id", channel.Id))
})
}
}
}
}
func (c *SearchChannelStore) indexChannel(channel *model.Channel) {
func (c *SearchChannelStore) indexChannel(rctx request.CTX, channel *model.Channel) {
var userIDs, teamMemberIDs []string
var err error
if channel.Type == model.ChannelTypePrivate {
userIDs, err = c.GetAllChannelMemberIdsByChannelId(channel.Id)
if err != nil {
mlog.Warn("Encountered error while indexing channel", mlog.String("channel_id", channel.Id), mlog.Err(err))
rctx.Logger().Warn("Encountered error while indexing channel", mlog.String("channel_id", channel.Id), mlog.Err(err))
return
}
}
teamMemberIDs, err = c.GetTeamMembersForChannel(channel.Id)
if err != nil {
mlog.Warn("Encountered error while indexing channel", mlog.String("channel_id", channel.Id), mlog.Err(err))
rctx.Logger().Warn("Encountered error while indexing channel", mlog.String("channel_id", channel.Id), mlog.Err(err))
return
}
for _, engine := range c.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.IndexChannel(channel, userIDs, teamMemberIDs); err != nil {
mlog.Warn("Encountered error indexing channel", mlog.String("channel_id", channel.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.IndexChannel(rctx, channel, userIDs, teamMemberIDs); err != nil {
rctx.Logger().Warn("Encountered error indexing channel", mlog.String("channel_id", channel.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
mlog.Debug("Indexed channel in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("channel_id", channel.Id))
rctx.Logger().Debug("Indexed channel in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("channel_id", channel.Id))
})
}
}
}
func (c *SearchChannelStore) Save(channel *model.Channel, maxChannels int64) (*model.Channel, error) {
// TODO: Use the actuall request context from the App layer
// https://mattermost.atlassian.net/browse/MM-55733
rctx := request.EmptyContext(c.rootStore.Logger())
newChannel, err := c.ChannelStore.Save(channel, maxChannels)
if err == nil {
c.indexChannel(newChannel)
c.indexChannel(rctx, newChannel)
}
return newChannel, err
}
func (c *SearchChannelStore) Update(channel *model.Channel) (*model.Channel, error) {
updatedChannel, err := c.ChannelStore.Update(channel)
func (c *SearchChannelStore) Update(rctx request.CTX, channel *model.Channel) (*model.Channel, error) {
updatedChannel, err := c.ChannelStore.Update(rctx, channel)
if err == nil {
c.indexChannel(updatedChannel)
c.indexChannel(rctx, updatedChannel)
}
return updatedChannel, err
}
func (c *SearchChannelStore) UpdateMember(cm *model.ChannelMember) (*model.ChannelMember, error) {
member, err := c.ChannelStore.UpdateMember(cm)
func (c *SearchChannelStore) UpdateMember(rctx request.CTX, cm *model.ChannelMember) (*model.ChannelMember, error) {
member, err := c.ChannelStore.UpdateMember(rctx, cm)
if err == nil {
c.rootStore.indexUserFromID(cm.UserId)
c.rootStore.indexUserFromID(rctx, cm.UserId)
channel, channelErr := c.ChannelStore.Get(member.ChannelId, true)
if channelErr != nil {
mlog.Warn("Encountered error indexing user in channel", mlog.String("channel_id", member.ChannelId), mlog.Err(channelErr))
rctx.Logger().Warn("Encountered error indexing user in channel", mlog.String("channel_id", member.ChannelId), mlog.Err(channelErr))
} else {
c.indexChannel(channel)
c.rootStore.indexUserFromID(channel.CreatorId)
c.indexChannel(rctx, channel)
c.rootStore.indexUserFromID(rctx, channel.CreatorId)
}
}
return member, err
}
func (c *SearchChannelStore) SaveMember(cm *model.ChannelMember) (*model.ChannelMember, error) {
// TODO: Use the actuall request context from the App layer
// https://mattermost.atlassian.net/browse/MM-55734
rctx := request.EmptyContext(c.rootStore.Logger())
member, err := c.ChannelStore.SaveMember(cm)
if err == nil {
c.rootStore.indexUserFromID(cm.UserId)
c.rootStore.indexUserFromID(rctx, cm.UserId)
channel, channelErr := c.ChannelStore.Get(member.ChannelId, true)
if channelErr != nil {
mlog.Warn("Encountered error indexing user in channel", mlog.String("channel_id", member.ChannelId), mlog.Err(channelErr))
rctx.Logger().Warn("Encountered error indexing user in channel", mlog.String("channel_id", member.ChannelId), mlog.Err(channelErr))
} else {
c.indexChannel(channel)
c.rootStore.indexUserFromID(channel.CreatorId)
c.indexChannel(rctx, channel)
c.rootStore.indexUserFromID(rctx, channel.CreatorId)
}
}
return member, err
}
func (c *SearchChannelStore) RemoveMember(channelID, userIdToRemove string) error {
err := c.ChannelStore.RemoveMember(channelID, userIdToRemove)
func (c *SearchChannelStore) RemoveMember(rctx request.CTX, channelID, userIdToRemove string) error {
err := c.ChannelStore.RemoveMember(rctx, channelID, userIdToRemove)
if err == nil {
c.rootStore.indexUserFromID(userIdToRemove)
c.rootStore.indexUserFromID(rctx, userIdToRemove)
}
channel, err := c.ChannelStore.Get(channelID, true)
if err == nil {
c.indexChannel(channel)
c.indexChannel(rctx, channel)
}
return err
}
func (c *SearchChannelStore) RemoveMembers(channelID string, userIds []string) error {
if err := c.ChannelStore.RemoveMembers(channelID, userIds); err != nil {
func (c *SearchChannelStore) RemoveMembers(rctx request.CTX, channelID string, userIds []string) error {
if err := c.ChannelStore.RemoveMembers(rctx, channelID, userIds); err != nil {
return err
}
channel, err := c.ChannelStore.Get(channelID, true)
if err == nil {
c.indexChannel(channel)
c.indexChannel(rctx, channel)
}
for _, uid := range userIds {
c.rootStore.indexUserFromID(uid)
c.rootStore.indexUserFromID(rctx, uid)
}
return nil
}
func (c *SearchChannelStore) CreateDirectChannel(user *model.User, otherUser *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error) {
channel, err := c.ChannelStore.CreateDirectChannel(user, otherUser, channelOptions...)
func (c *SearchChannelStore) CreateDirectChannel(rctx request.CTX, user *model.User, otherUser *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error) {
channel, err := c.ChannelStore.CreateDirectChannel(rctx, user, otherUser, channelOptions...)
if err == nil {
c.rootStore.indexUserFromID(user.Id)
c.rootStore.indexUserFromID(otherUser.Id)
c.indexChannel(channel)
c.rootStore.indexUserFromID(rctx, user.Id)
c.rootStore.indexUserFromID(rctx, otherUser.Id)
c.indexChannel(rctx, channel)
}
return channel, err
}
func (c *SearchChannelStore) SaveDirectChannel(directchannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error) {
channel, err := c.ChannelStore.SaveDirectChannel(directchannel, member1, member2)
func (c *SearchChannelStore) SaveDirectChannel(rctx request.CTX, directchannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error) {
channel, err := c.ChannelStore.SaveDirectChannel(rctx, directchannel, member1, member2)
if err == nil {
c.rootStore.indexUserFromID(member1.UserId)
c.rootStore.indexUserFromID(member2.UserId)
c.indexChannel(channel)
c.rootStore.indexUserFromID(rctx, member1.UserId)
c.rootStore.indexUserFromID(rctx, member2.UserId)
c.indexChannel(rctx, channel)
}
return channel, err
}
func (c *SearchChannelStore) Autocomplete(userID, term string, includeDeleted, isGuest bool) (model.ChannelListWithTeamData, error) {
func (c *SearchChannelStore) Autocomplete(rctx request.CTX, userID, term string, includeDeleted, isGuest bool) (model.ChannelListWithTeamData, error) {
var channelList model.ChannelListWithTeamData
var err error
@ -170,18 +177,18 @@ func (c *SearchChannelStore) Autocomplete(userID, term string, includeDeleted, i
if engine.IsAutocompletionEnabled() {
channelList, err = c.searchAutocompleteChannelsAllTeams(engine, userID, term, includeDeleted, isGuest)
if err != nil {
mlog.Warn("Encountered error on AutocompleteChannels through SearchEngine. Falling back to default autocompletion.", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
rctx.Logger().Warn("Encountered error on AutocompleteChannels through SearchEngine. Falling back to default autocompletion.", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
continue
}
allFailed = false
mlog.Debug("Using the first available search engine", mlog.String("search_engine", engine.GetName()))
rctx.Logger().Debug("Using the first available search engine", mlog.String("search_engine", engine.GetName()))
break
}
}
if allFailed {
mlog.Debug("Using database search because no other search engine is available")
channelList, err = c.ChannelStore.Autocomplete(userID, term, includeDeleted, isGuest)
rctx.Logger().Debug("Using database search because no other search engine is available")
channelList, err = c.ChannelStore.Autocomplete(rctx, userID, term, includeDeleted, isGuest)
if err != nil {
return nil, errors.Wrap(err, "Failed to autocomplete channels in team")
}
@ -194,7 +201,7 @@ func (c *SearchChannelStore) Autocomplete(userID, term string, includeDeleted, i
return channelList, nil
}
func (c *SearchChannelStore) AutocompleteInTeam(teamID, userID, term string, includeDeleted, isGuest bool) (model.ChannelList, error) {
func (c *SearchChannelStore) AutocompleteInTeam(rctx request.CTX, teamID, userID, term string, includeDeleted, isGuest bool) (model.ChannelList, error) {
var channelList model.ChannelList
var err error
@ -203,18 +210,18 @@ func (c *SearchChannelStore) AutocompleteInTeam(teamID, userID, term string, inc
if engine.IsAutocompletionEnabled() {
channelList, err = c.searchAutocompleteChannels(engine, teamID, userID, term, includeDeleted, isGuest)
if err != nil {
mlog.Warn("Encountered error on AutocompleteChannels through SearchEngine. Falling back to default autocompletion.", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
rctx.Logger().Warn("Encountered error on AutocompleteChannels through SearchEngine. Falling back to default autocompletion.", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
continue
}
allFailed = false
mlog.Debug("Using the first available search engine", mlog.String("search_engine", engine.GetName()))
rctx.Logger().Debug("Using the first available search engine", mlog.String("search_engine", engine.GetName()))
break
}
}
if allFailed {
mlog.Debug("Using database search because no other search engine is available")
channelList, err = c.ChannelStore.AutocompleteInTeam(teamID, userID, term, includeDeleted, isGuest)
rctx.Logger().Debug("Using database search because no other search engine is available")
channelList, err = c.ChannelStore.AutocompleteInTeam(rctx, teamID, userID, term, includeDeleted, isGuest)
if err != nil {
return nil, errors.Wrap(err, "Failed to autocomplete channels in team")
}
@ -263,18 +270,18 @@ func (c *SearchChannelStore) searchAutocompleteChannelsAllTeams(engine searcheng
return channelList, nil
}
func (c *SearchChannelStore) PermanentDeleteMembersByUser(userId string) error {
func (c *SearchChannelStore) PermanentDeleteMembersByUser(rctx request.CTX, userId string) error {
channels, errGetChannels := c.ChannelStore.GetChannelsByUser(userId, false, 0, -1, "")
if errGetChannels != nil {
mlog.Warn("Encountered error indexing channel after removing user", mlog.String("user_id", userId), mlog.Err(errGetChannels))
rctx.Logger().Warn("Encountered error indexing channel after removing user", mlog.String("user_id", userId), mlog.Err(errGetChannels))
}
err := c.ChannelStore.PermanentDeleteMembersByUser(userId)
err := c.ChannelStore.PermanentDeleteMembersByUser(rctx, userId)
if err == nil {
c.rootStore.indexUserFromID(userId)
c.rootStore.indexUserFromID(rctx, userId)
if errGetChannels == nil {
for _, ch := range channels {
c.indexChannel(ch)
c.indexChannel(rctx, ch)
}
}
}
@ -282,46 +289,46 @@ func (c *SearchChannelStore) PermanentDeleteMembersByUser(userId string) error {
return err
}
func (c *SearchChannelStore) RemoveAllDeactivatedMembers(channelId string) error {
func (c *SearchChannelStore) RemoveAllDeactivatedMembers(rctx request.CTX, channelId string) error {
profiles, errProfiles := c.rootStore.User().GetAllProfilesInChannel(context.Background(), channelId, true)
if errProfiles != nil {
mlog.Warn("Encountered error indexing users for channel", mlog.String("channel_id", channelId), mlog.Err(errProfiles))
rctx.Logger().Warn("Encountered error indexing users for channel", mlog.String("channel_id", channelId), mlog.Err(errProfiles))
}
err := c.ChannelStore.RemoveAllDeactivatedMembers(channelId)
err := c.ChannelStore.RemoveAllDeactivatedMembers(rctx, channelId)
if err == nil && errProfiles == nil {
for _, user := range profiles {
if user.DeleteAt != 0 {
c.rootStore.indexUser(user)
c.rootStore.indexUser(rctx, user)
}
}
}
return err
}
func (c *SearchChannelStore) PermanentDeleteMembersByChannel(channelId string) error {
func (c *SearchChannelStore) PermanentDeleteMembersByChannel(rctx request.CTX, channelId string) error {
profiles, errProfiles := c.rootStore.User().GetAllProfilesInChannel(context.Background(), channelId, true)
if errProfiles != nil {
mlog.Warn("Encountered error indexing users for channel", mlog.String("channel_id", channelId), mlog.Err(errProfiles))
rctx.Logger().Warn("Encountered error indexing users for channel", mlog.String("channel_id", channelId), mlog.Err(errProfiles))
}
err := c.ChannelStore.PermanentDeleteMembersByChannel(channelId)
err := c.ChannelStore.PermanentDeleteMembersByChannel(rctx, channelId)
if err == nil && errProfiles == nil {
for _, user := range profiles {
c.rootStore.indexUser(user)
c.rootStore.indexUser(rctx, user)
}
}
return err
}
func (c *SearchChannelStore) PermanentDelete(channelId string) error {
func (c *SearchChannelStore) PermanentDelete(rctx request.CTX, channelId string) error {
channel, channelErr := c.ChannelStore.Get(channelId, true)
if channelErr != nil {
mlog.Warn("Encountered error deleting channel", mlog.String("channel_id", channelId), mlog.Err(channelErr))
rctx.Logger().Warn("Encountered error deleting channel", mlog.String("channel_id", channelId), mlog.Err(channelErr))
}
err := c.ChannelStore.PermanentDelete(channelId)
err := c.ChannelStore.PermanentDelete(rctx, channelId)
if err == nil && channelErr == nil {
c.deleteChannelIndex(channel)
c.deleteChannelIndex(rctx, channel)
}
return err
}

View File

@ -6,6 +6,7 @@ package searchlayer
import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/platform/services/searchengine"
)
@ -15,21 +16,21 @@ type SearchFileInfoStore struct {
rootStore *SearchStore
}
func (s SearchFileInfoStore) indexFile(file *model.FileInfo) {
func (s SearchFileInfoStore) indexFile(rctx request.CTX, file *model.FileInfo) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if file.PostId == "" {
return
}
post, postErr := s.rootStore.Post().GetSingle(file.PostId, false)
if postErr != nil {
mlog.Error("Couldn't get post for file for SearchEngine indexing.", mlog.String("post_id", file.PostId), mlog.String("search_engine", engineCopy.GetName()), mlog.String("file_info_id", file.Id), mlog.Err(postErr))
rctx.Logger().Error("Couldn't get post for file for SearchEngine indexing.", mlog.String("post_id", file.PostId), mlog.String("search_engine", engineCopy.GetName()), mlog.String("file_info_id", file.Id), mlog.Err(postErr))
return
}
if err := engineCopy.IndexFile(file, post.ChannelId); err != nil {
mlog.Error("Encountered error indexing file", mlog.String("file_info_id", file.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
rctx.Logger().Error("Encountered error indexing file", mlog.String("file_info_id", file.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
})
@ -37,12 +38,12 @@ func (s SearchFileInfoStore) indexFile(file *model.FileInfo) {
}
}
func (s SearchFileInfoStore) deleteFileIndex(fileID string) {
func (s SearchFileInfoStore) deleteFileIndex(rctx request.CTX, fileID string) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteFile(fileID); err != nil {
mlog.Error("Encountered error deleting file", mlog.String("file_info_id", fileID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
rctx.Logger().Error("Encountered error deleting file", mlog.String("file_info_id", fileID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
})
@ -50,112 +51,112 @@ func (s SearchFileInfoStore) deleteFileIndex(fileID string) {
}
}
func (s SearchFileInfoStore) deleteFileIndexForUser(userID string) {
func (s SearchFileInfoStore) deleteFileIndexForUser(rctx request.CTX, userID string) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteUserFiles(userID); err != nil {
mlog.Error("Encountered error deleting files for user", mlog.String("user_id", userID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteUserFiles(rctx, userID); err != nil {
rctx.Logger().Error("Encountered error deleting files for user", mlog.String("user_id", userID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
mlog.Debug("Removed user's files from the index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("user_id", userID))
rctx.Logger().Debug("Removed user's files from the index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("user_id", userID))
})
}
}
}
func (s SearchFileInfoStore) deleteFileIndexForPost(postID string) {
func (s SearchFileInfoStore) deleteFileIndexForPost(rctx request.CTX, postID string) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeletePostFiles(postID); err != nil {
mlog.Error("Encountered error deleting files for post", mlog.String("post_id", postID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeletePostFiles(rctx, postID); err != nil {
rctx.Logger().Error("Encountered error deleting files for post", mlog.String("post_id", postID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
mlog.Debug("Removed post's files from the index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("post_id", postID))
rctx.Logger().Debug("Removed post's files from the index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("post_id", postID))
})
}
}
}
func (s SearchFileInfoStore) deleteFileIndexBatch(endTime, limit int64) {
func (s SearchFileInfoStore) deleteFileIndexBatch(rctx request.CTX, endTime, limit int64) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteFilesBatch(endTime, limit); err != nil {
mlog.Error("Encountered error deleting a batch of files", mlog.Int("limit", limit), mlog.Int("end_time", endTime), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteFilesBatch(rctx, endTime, limit); err != nil {
rctx.Logger().Error("Encountered error deleting a batch of files", mlog.Int("limit", limit), mlog.Int("end_time", endTime), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
mlog.Debug("Removed batch of files from the index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.Int("end_time", endTime), mlog.Int("limit", limit))
rctx.Logger().Debug("Removed batch of files from the index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.Int("end_time", endTime), mlog.Int("limit", limit))
})
}
}
}
func (s SearchFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, error) {
nfile, err := s.FileInfoStore.Save(info)
func (s SearchFileInfoStore) Save(rctx request.CTX, info *model.FileInfo) (*model.FileInfo, error) {
nfile, err := s.FileInfoStore.Save(rctx, info)
if err == nil {
s.indexFile(nfile)
s.indexFile(rctx, nfile)
}
return nfile, err
}
func (s SearchFileInfoStore) SetContent(fileID, content string) error {
err := s.FileInfoStore.SetContent(fileID, content)
func (s SearchFileInfoStore) SetContent(rctx request.CTX, fileID, content string) error {
err := s.FileInfoStore.SetContent(rctx, fileID, content)
if err == nil {
nfile, err2 := s.FileInfoStore.GetFromMaster(fileID)
if err2 == nil {
nfile.Content = content
s.indexFile(nfile)
s.indexFile(rctx, nfile)
}
}
return err
}
func (s SearchFileInfoStore) AttachToPost(fileId, postId, channelId, creatorId string) error {
err := s.FileInfoStore.AttachToPost(fileId, postId, channelId, creatorId)
func (s SearchFileInfoStore) AttachToPost(rctx request.CTX, fileId, postId, channelId, creatorId string) error {
err := s.FileInfoStore.AttachToPost(rctx, fileId, postId, channelId, creatorId)
if err == nil {
nFileInfo, err2 := s.FileInfoStore.GetFromMaster(fileId)
if err2 == nil {
s.indexFile(nFileInfo)
s.indexFile(rctx, nFileInfo)
}
}
return err
}
func (s SearchFileInfoStore) DeleteForPost(postId string) (string, error) {
result, err := s.FileInfoStore.DeleteForPost(postId)
func (s SearchFileInfoStore) DeleteForPost(rctx request.CTX, postId string) (string, error) {
result, err := s.FileInfoStore.DeleteForPost(rctx, postId)
if err == nil {
s.deleteFileIndexForPost(postId)
s.deleteFileIndexForPost(rctx, postId)
}
return result, err
}
func (s SearchFileInfoStore) PermanentDelete(fileId string) error {
err := s.FileInfoStore.PermanentDelete(fileId)
func (s SearchFileInfoStore) PermanentDelete(rctx request.CTX, fileId string) error {
err := s.FileInfoStore.PermanentDelete(rctx, fileId)
if err == nil {
s.deleteFileIndex(fileId)
s.deleteFileIndex(rctx, fileId)
}
return err
}
func (s SearchFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
result, err := s.FileInfoStore.PermanentDeleteBatch(endTime, limit)
func (s SearchFileInfoStore) PermanentDeleteBatch(rctx request.CTX, endTime int64, limit int64) (int64, error) {
result, err := s.FileInfoStore.PermanentDeleteBatch(rctx, endTime, limit)
if err == nil {
s.deleteFileIndexBatch(endTime, limit)
s.deleteFileIndexBatch(rctx, endTime, limit)
}
return result, err
}
func (s SearchFileInfoStore) PermanentDeleteByUser(userId string) (int64, error) {
result, err := s.FileInfoStore.PermanentDeleteByUser(userId)
func (s SearchFileInfoStore) PermanentDeleteByUser(rctx request.CTX, userId string) (int64, error) {
result, err := s.FileInfoStore.PermanentDeleteByUser(rctx, userId)
if err == nil {
s.deleteFileIndexForUser(userId)
s.deleteFileIndexForUser(rctx, userId)
}
return result, err
}
func (s SearchFileInfoStore) Search(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.FileInfoList, error) {
func (s SearchFileInfoStore) Search(rctx request.CTX, paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.FileInfoList, error) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsSearchEnabled() {
userChannels, nErr := s.rootStore.Channel().GetChannels(teamId, userId, &model.ChannelSearchOpts{
@ -167,7 +168,7 @@ func (s SearchFileInfoStore) Search(paramsList []*model.SearchParams, userId, te
}
fileIds, appErr := engine.SearchFiles(userChannels, paramsList, page, perPage)
if appErr != nil {
mlog.Error("Encountered error on Search.", mlog.String("search_engine", engine.GetName()), mlog.Err(appErr))
rctx.Logger().Error("Encountered error on Search.", mlog.String("search_engine", engine.GetName()), mlog.Err(appErr))
continue
}
@ -191,5 +192,5 @@ func (s SearchFileInfoStore) Search(paramsList []*model.SearchParams, userId, te
return model.NewFileInfoList(), nil
}
return s.FileInfoStore.Search(paramsList, userId, teamId, page, perPage)
return s.FileInfoStore.Search(rctx, paramsList, userId, teamId, page, perPage)
}

View File

@ -4,11 +4,11 @@
package searchlayer
import (
"context"
"sync/atomic"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/platform/services/searchengine"
)
@ -67,21 +67,21 @@ func (s *SearchStore) User() store.UserStore {
return s.user
}
func (s *SearchStore) indexUserFromID(userId string) {
user, err := s.User().Get(context.Background(), userId)
func (s *SearchStore) indexUserFromID(rctx request.CTX, userId string) {
user, err := s.User().Get(rctx.Context(), userId)
if err != nil {
return
}
s.indexUser(user)
s.indexUser(rctx, user)
}
func (s *SearchStore) indexUser(user *model.User) {
func (s *SearchStore) indexUser(rctx request.CTX, user *model.User) {
for _, engine := range s.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
userTeams, nErr := s.Team().GetTeamsByUserId(user.Id)
if nErr != nil {
mlog.Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(nErr))
rctx.Logger().Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(nErr))
return
}
@ -92,7 +92,7 @@ func (s *SearchStore) indexUser(user *model.User) {
userChannelMembers, err := s.Channel().GetAllChannelMembersForUser(user.Id, false, true)
if err != nil {
mlog.Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
rctx.Logger().Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
@ -101,22 +101,22 @@ func (s *SearchStore) indexUser(user *model.User) {
userChannelsIds = append(userChannelsIds, channelId)
}
if err := engineCopy.IndexUser(user, userTeamsIds, userChannelsIds); err != nil {
mlog.Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
if err := engineCopy.IndexUser(rctx, user, userTeamsIds, userChannelsIds); err != nil {
rctx.Logger().Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
mlog.Debug("Indexed user in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("user_id", user.Id))
rctx.Logger().Debug("Indexed user in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("user_id", user.Id))
})
}
}
}
// Runs an indexing function synchronously or asynchronously depending on the engine
func runIndexFn(engine searchengine.SearchEngineInterface, indexFn func(searchengine.SearchEngineInterface)) {
func runIndexFn(rctx request.CTX, engine searchengine.SearchEngineInterface, indexFn func(searchengine.SearchEngineInterface)) {
if engine.IsIndexingSync() {
indexFn(engine)
if err := engine.RefreshIndexes(); err != nil {
mlog.Error("Encountered error refresh the indexes", mlog.Err(err))
if err := engine.RefreshIndexes(rctx); err != nil {
rctx.Logger().Error("Encountered error refresh the indexes", mlog.Err(err))
}
} else {
go (func(engineCopy searchengine.SearchEngineInterface) {

View File

@ -9,6 +9,7 @@ import (
"testing"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/v8/channels/store/searchlayer"
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
@ -20,12 +21,14 @@ import (
// Test to verify race condition on UpdateConfig. The test must run with -race flag in order to verify
// that there is no race. Ref: (#MM-30868)
func TestUpdateConfigRace(t *testing.T) {
logger := mlog.CreateTestLogger(t)
driverName := os.Getenv("MM_SQLSETTINGS_DRIVERNAME")
if driverName == "" {
driverName = model.DatabaseDriverPostgres
}
settings := storetest.MakeSqlSettings(driverName, false)
store, err := sqlstore.New(*settings, nil)
store, err := sqlstore.New(*settings, logger, nil)
require.NoError(t, err)
cfg := &model.Config{}

View File

@ -10,6 +10,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/platform/services/searchengine"
)
@ -19,17 +20,17 @@ type SearchPostStore struct {
rootStore *SearchStore
}
func (s SearchPostStore) indexPost(post *model.Post) {
func (s SearchPostStore) indexPost(rctx request.CTX, post *model.Post) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
channel, chanErr := s.rootStore.Channel().Get(post.ChannelId, true)
if chanErr != nil {
mlog.Error("Couldn't get channel for post for SearchEngine indexing.", mlog.String("channel_id", post.ChannelId), mlog.String("search_engine", engineCopy.GetName()), mlog.String("post_id", post.Id), mlog.Err(chanErr))
rctx.Logger().Error("Couldn't get channel for post for SearchEngine indexing.", mlog.String("channel_id", post.ChannelId), mlog.String("search_engine", engineCopy.GetName()), mlog.String("post_id", post.Id), mlog.Err(chanErr))
return
}
if err := engineCopy.IndexPost(post, channel.TeamId); err != nil {
mlog.Warn("Encountered error indexing post", mlog.String("post_id", post.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
rctx.Logger().Warn("Encountered error indexing post", mlog.String("post_id", post.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
})
@ -37,12 +38,12 @@ func (s SearchPostStore) indexPost(post *model.Post) {
}
}
func (s SearchPostStore) deletePostIndex(post *model.Post) {
func (s SearchPostStore) deletePostIndex(rctx request.CTX, post *model.Post) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeletePost(post); err != nil {
mlog.Warn("Encountered error deleting post", mlog.String("post_id", post.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
rctx.Logger().Warn("Encountered error deleting post", mlog.String("post_id", post.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
})
@ -50,62 +51,65 @@ func (s SearchPostStore) deletePostIndex(post *model.Post) {
}
}
func (s SearchPostStore) deleteChannelPostsIndex(channelID string) {
func (s SearchPostStore) deleteChannelPostsIndex(rctx request.CTX, channelID string) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteChannelPosts(channelID); err != nil {
mlog.Warn("Encountered error deleting channel posts", mlog.String("channel_id", channelID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteChannelPosts(rctx, channelID); err != nil {
rctx.Logger().Warn("Encountered error deleting channel posts", mlog.String("channel_id", channelID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
mlog.Debug("Removed all channel posts from the index in search engine", mlog.String("channel_id", channelID), mlog.String("search_engine", engineCopy.GetName()))
rctx.Logger().Debug("Removed all channel posts from the index in search engine", mlog.String("channel_id", channelID), mlog.String("search_engine", engineCopy.GetName()))
})
}
}
}
func (s SearchPostStore) deleteUserPostsIndex(userID string) {
func (s SearchPostStore) deleteUserPostsIndex(rctx request.CTX, userID string) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteUserPosts(userID); err != nil {
mlog.Warn("Encountered error deleting user posts", mlog.String("user_id", userID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteUserPosts(rctx, userID); err != nil {
rctx.Logger().Warn("Encountered error deleting user posts", mlog.String("user_id", userID), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
mlog.Debug("Removed all user posts from the index in search engine", mlog.String("user_id", userID), mlog.String("search_engine", engineCopy.GetName()))
rctx.Logger().Debug("Removed all user posts from the index in search engine", mlog.String("user_id", userID), mlog.String("search_engine", engineCopy.GetName()))
})
}
}
}
func (s SearchPostStore) Update(newPost, oldPost *model.Post) (*model.Post, error) {
post, err := s.PostStore.Update(newPost, oldPost)
func (s SearchPostStore) Update(rctx request.CTX, newPost, oldPost *model.Post) (*model.Post, error) {
post, err := s.PostStore.Update(rctx, newPost, oldPost)
if err == nil {
s.indexPost(post)
s.indexPost(rctx, post)
}
return post, err
}
func (s *SearchPostStore) Overwrite(post *model.Post) (*model.Post, error) {
post, err := s.PostStore.Overwrite(post)
func (s *SearchPostStore) Overwrite(rctx request.CTX, post *model.Post) (*model.Post, error) {
post, err := s.PostStore.Overwrite(rctx, post)
if err == nil {
s.indexPost(post)
s.indexPost(rctx, post)
}
return post, err
}
func (s SearchPostStore) Save(post *model.Post) (*model.Post, error) {
// TODO: Use the actuall request context from the App layer
// https://mattermost.atlassian.net/browse/MM-55735
rctx := request.EmptyContext(s.rootStore.Logger())
npost, err := s.PostStore.Save(post)
if err == nil {
s.indexPost(npost)
s.indexPost(rctx, npost)
}
return npost, err
}
func (s SearchPostStore) Delete(postId string, date int64, deletedByID string) error {
err := s.PostStore.Delete(postId, date, deletedByID)
func (s SearchPostStore) Delete(rctx request.CTX, postId string, date int64, deletedByID string) error {
err := s.PostStore.Delete(rctx, postId, date, deletedByID)
if err == nil {
opts := model.GetPostsOptions{
@ -114,25 +118,25 @@ func (s SearchPostStore) Delete(postId string, date int64, deletedByID string) e
postList, err2 := s.PostStore.Get(context.Background(), postId, opts, "", map[string]bool{})
if postList != nil && len(postList.Order) > 0 {
if err2 != nil {
s.deletePostIndex(postList.Posts[postList.Order[0]])
s.deletePostIndex(rctx, postList.Posts[postList.Order[0]])
}
}
}
return err
}
func (s SearchPostStore) PermanentDeleteByUser(userID string) error {
err := s.PostStore.PermanentDeleteByUser(userID)
func (s SearchPostStore) PermanentDeleteByUser(rctx request.CTX, userID string) error {
err := s.PostStore.PermanentDeleteByUser(rctx, userID)
if err == nil {
s.deleteUserPostsIndex(userID)
s.deleteUserPostsIndex(rctx, userID)
}
return err
}
func (s SearchPostStore) PermanentDeleteByChannel(channelID string) error {
err := s.PostStore.PermanentDeleteByChannel(channelID)
func (s SearchPostStore) PermanentDeleteByChannel(rctx request.CTX, channelID string) error {
err := s.PostStore.PermanentDeleteByChannel(rctx, channelID)
if err == nil {
s.deleteChannelPostsIndex(channelID)
s.deleteChannelPostsIndex(rctx, channelID)
}
return err
}
@ -175,12 +179,12 @@ func (s SearchPostStore) searchPostsForUserByEngine(engine searchengine.SearchEn
return model.MakePostSearchResults(postList, matches), nil
}
func (s SearchPostStore) SearchPostsForUser(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, error) {
func (s SearchPostStore) SearchPostsForUser(rctx request.CTX, paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, error) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsSearchEnabled() {
results, err := s.searchPostsForUserByEngine(engine, paramsList, userId, teamId, page, perPage)
if err != nil {
mlog.Warn("Encountered error on SearchPostsInTeamForUser.", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
rctx.Logger().Warn("Encountered error on SearchPostsInTeamForUser.", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
continue
}
return results, err
@ -191,5 +195,5 @@ func (s SearchPostStore) SearchPostsForUser(paramsList []*model.SearchParams, us
return &model.PostSearchResults{PostList: model.NewPostList(), Matches: model.PostSearchMatches{}}, nil
}
return s.PostStore.SearchPostsForUser(paramsList, userId, teamId, page, perPage)
return s.PostStore.SearchPostsForUser(rctx, paramsList, userId, teamId, page, perPage)
}

View File

@ -5,6 +5,7 @@ package searchlayer
import (
model "github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
store "github.com/mattermost/mattermost/server/v8/channels/store"
)
@ -14,33 +15,36 @@ type SearchTeamStore struct {
}
func (s SearchTeamStore) SaveMember(teamMember *model.TeamMember, maxUsersPerTeam int) (*model.TeamMember, error) {
// TODO: Use the actuall request context from the App layer
// https://mattermost.atlassian.net/browse/MM-55736
rctx := request.EmptyContext(s.rootStore.Logger())
member, err := s.TeamStore.SaveMember(teamMember, maxUsersPerTeam)
if err == nil {
s.rootStore.indexUserFromID(member.UserId)
s.rootStore.indexUserFromID(rctx, member.UserId)
}
return member, err
}
func (s SearchTeamStore) UpdateMember(teamMember *model.TeamMember) (*model.TeamMember, error) {
member, err := s.TeamStore.UpdateMember(teamMember)
func (s SearchTeamStore) UpdateMember(rctx request.CTX, teamMember *model.TeamMember) (*model.TeamMember, error) {
member, err := s.TeamStore.UpdateMember(rctx, teamMember)
if err == nil {
s.rootStore.indexUserFromID(member.UserId)
s.rootStore.indexUserFromID(rctx, member.UserId)
}
return member, err
}
func (s SearchTeamStore) RemoveMember(teamId string, userId string) error {
err := s.TeamStore.RemoveMember(teamId, userId)
func (s SearchTeamStore) RemoveMember(rctx request.CTX, teamId string, userId string) error {
err := s.TeamStore.RemoveMember(rctx, teamId, userId)
if err == nil {
s.rootStore.indexUserFromID(userId)
s.rootStore.indexUserFromID(rctx, userId)
}
return err
}
func (s SearchTeamStore) RemoveAllMembersByUser(userId string) error {
err := s.TeamStore.RemoveAllMembersByUser(userId)
func (s SearchTeamStore) RemoveAllMembersByUser(rctx request.CTX, userId string) error {
err := s.TeamStore.RemoveAllMembersByUser(rctx, userId)
if err == nil {
s.rootStore.indexUserFromID(userId)
s.rootStore.indexUserFromID(rctx, userId)
}
return err
}

View File

@ -11,6 +11,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/platform/services/searchengine"
)
@ -20,26 +21,26 @@ type SearchUserStore struct {
rootStore *SearchStore
}
func (s *SearchUserStore) deleteUserIndex(user *model.User) {
func (s *SearchUserStore) deleteUserIndex(rctx request.CTX, user *model.User) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {
runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) {
if err := engineCopy.DeleteUser(user); err != nil {
mlog.Error("Encountered error deleting user", mlog.String("user_id", user.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
rctx.Logger().Error("Encountered error deleting user", mlog.String("user_id", user.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err))
return
}
mlog.Debug("Removed user from the index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("user_id", user.Id))
rctx.Logger().Debug("Removed user from the index in search engine", mlog.String("search_engine", engineCopy.GetName()), mlog.String("user_id", user.Id))
})
}
}
}
func (s *SearchUserStore) Search(teamId, term string, options *model.UserSearchOptions) ([]*model.User, error) {
func (s *SearchUserStore) Search(rctx request.CTX, teamId, term string, options *model.UserSearchOptions) ([]*model.User, error) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsSearchEnabled() {
listOfAllowedChannels, nErr := s.getListOfAllowedChannels(teamId, "", options.ViewRestrictions)
if nErr != nil {
mlog.Warn("Encountered error on Search.", mlog.String("search_engine", engine.GetName()), mlog.Err(nErr))
rctx.Logger().Warn("Encountered error on Search.", mlog.String("search_engine", engine.GetName()), mlog.Err(nErr))
continue
}
@ -51,52 +52,58 @@ func (s *SearchUserStore) Search(teamId, term string, options *model.UserSearchO
usersIds, err := engine.SearchUsersInTeam(teamId, listOfAllowedChannels, sanitizedTerm, options)
if err != nil {
mlog.Warn("Encountered error on Search", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
rctx.Logger().Warn("Encountered error on Search", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
continue
}
users, nErr := s.UserStore.GetProfileByIds(context.Background(), usersIds, nil, false)
if nErr != nil {
mlog.Warn("Encountered error on Search", mlog.String("search_engine", engine.GetName()), mlog.Err(nErr))
rctx.Logger().Warn("Encountered error on Search", mlog.String("search_engine", engine.GetName()), mlog.Err(nErr))
continue
}
mlog.Debug("Using the first available search engine", mlog.String("search_engine", engine.GetName()))
rctx.Logger().Debug("Using the first available search engine", mlog.String("search_engine", engine.GetName()))
return users, nil
}
}
mlog.Debug("Using database search because no other search engine is available")
rctx.Logger().Debug("Using database search because no other search engine is available")
return s.UserStore.Search(teamId, term, options)
return s.UserStore.Search(rctx, teamId, term, options)
}
func (s *SearchUserStore) Update(user *model.User, trustedUpdateData bool) (*model.UserUpdate, error) {
userUpdate, err := s.UserStore.Update(user, trustedUpdateData)
func (s *SearchUserStore) Update(rctx request.CTX, user *model.User, trustedUpdateData bool) (*model.UserUpdate, error) {
userUpdate, err := s.UserStore.Update(rctx, user, trustedUpdateData)
if err == nil {
s.rootStore.indexUser(userUpdate.New)
s.rootStore.indexUser(rctx, userUpdate.New)
}
return userUpdate, err
}
func (s *SearchUserStore) Save(user *model.User) (*model.User, error) {
// TODO: Use the actuall request context from the App layer
// https://mattermost.atlassian.net/browse/MM-55737
rctx := request.EmptyContext(s.rootStore.Logger())
nuser, err := s.UserStore.Save(user)
if err == nil {
s.rootStore.indexUser(nuser)
s.rootStore.indexUser(rctx, nuser)
}
return nuser, err
}
func (s *SearchUserStore) PermanentDelete(userId string) error {
// TODO: Use the actuall request context from the App layer
// https://mattermost.atlassian.net/browse/MM-55738
rctx := request.EmptyContext(s.rootStore.Logger())
user, userErr := s.UserStore.Get(context.Background(), userId)
if userErr != nil {
mlog.Warn("Encountered error deleting user", mlog.String("user_id", userId), mlog.Err(userErr))
rctx.Logger().Warn("Encountered error deleting user", mlog.String("user_id", userId), mlog.Err(userErr))
}
err := s.UserStore.PermanentDelete(userId)
if err == nil && userErr == nil {
s.deleteUserIndex(user)
s.deleteUserIndex(rctx, user)
}
return err
}
@ -206,12 +213,12 @@ func (s *SearchUserStore) getListOfAllowedChannels(teamId, channelId string, vie
return []string{}, nil
}
func (s *SearchUserStore) AutocompleteUsersInChannel(teamId, channelId, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error) {
func (s *SearchUserStore) AutocompleteUsersInChannel(rctx request.CTX, teamId, channelId, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsAutocompletionEnabled() {
listOfAllowedChannels, nErr := s.getListOfAllowedChannels(teamId, channelId, options.ViewRestrictions)
if nErr != nil {
mlog.Warn("Encountered error on AutocompleteUsersInChannel.", mlog.String("search_engine", engine.GetName()), mlog.Err(nErr))
rctx.Logger().Warn("Encountered error on AutocompleteUsersInChannel.", mlog.String("search_engine", engine.GetName()), mlog.Err(nErr))
continue
}
if listOfAllowedChannels != nil && len(listOfAllowedChannels) == 0 {
@ -221,14 +228,14 @@ func (s *SearchUserStore) AutocompleteUsersInChannel(teamId, channelId, term str
autocomplete, nErr := s.autocompleteUsersInChannelByEngine(engine, teamId, channelId, term, options)
if nErr != nil {
mlog.Warn("Encountered error on AutocompleteUsersInChannel.", mlog.String("search_engine", engine.GetName()), mlog.Err(nErr))
rctx.Logger().Warn("Encountered error on AutocompleteUsersInChannel.", mlog.String("search_engine", engine.GetName()), mlog.Err(nErr))
continue
}
mlog.Debug("Using the first available search engine", mlog.String("search_engine", engine.GetName()))
rctx.Logger().Debug("Using the first available search engine", mlog.String("search_engine", engine.GetName()))
return autocomplete, nil
}
}
mlog.Debug("Using database search because no other search engine is available")
return s.UserStore.AutocompleteUsersInChannel(teamId, channelId, term, options)
rctx.Logger().Debug("Using database search because no other search engine is available")
return s.UserStore.AutocompleteUsersInChannel(rctx, teamId, channelId, term, options)
}

View File

@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
@ -77,7 +78,8 @@ var searchChannelStoreTests = []searchTest{
func TestSearchChannelStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) {
th := &SearchTestHelper{
Store: s,
Context: request.TestContext(t),
Store: s,
}
err := th.SetupBasicFixtures()
require.NoError(t, err)
@ -94,11 +96,11 @@ func testAutocompleteChannelByName(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
defer th.deleteChannel(private)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-a", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id, private.Id}, res)
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "channel-a", false, false)
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "channel-a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelBasic.Id, alternate.Id, private.Id, th.ChannelAnotherTeam.Id}, res2)
}
@ -107,7 +109,7 @@ func testAutocompleteChannelByNamePostgres(t *testing.T, th *SearchTestHelper) {
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "Channel Alternate", "Channel Alternate", model.ChannelTypeOpen, th.User, false)
require.NoError(t, err)
defer th.deleteChannel(alternate)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-a", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res)
}
@ -121,11 +123,11 @@ func testAutocompleteChannelByDisplayName(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
defer th.deleteChannel(private)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "ChannelA", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "ChannelA", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id, private.Id}, res)
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "ChannelA", false, false)
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "ChannelA", false, false)
require.NoError(t, err)
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelBasic.Id, alternate.Id, private.Id, th.ChannelAnotherTeam.Id}, res2)
}
@ -134,7 +136,7 @@ func testAutocompleteChannelByNameSplittedWithDashChar(t *testing.T, th *SearchT
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
require.NoError(t, err)
defer th.deleteChannel(alternate)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-a", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res)
}
@ -143,7 +145,7 @@ func testAutocompleteChannelByNameSplittedWithDashCharPostgres(t *testing.T, th
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
require.NoError(t, err)
defer th.deleteChannel(alternate)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-a", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res)
}
@ -152,11 +154,11 @@ func testAutocompleteChannelByNameSplittedWithUnderscoreChar(t *testing.T, th *S
alternate, err := th.createChannel(th.Team.Id, "channel_alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
require.NoError(t, err)
defer th.deleteChannel(alternate)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel_a", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel_a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{alternate.Id}, res)
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "channel_a", false, false)
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "channel_a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatchWithTeamData(t, []string{alternate.Id}, res2)
}
@ -166,7 +168,7 @@ func testAutocompleteChannelByDisplayNameSplittedByWhitespaces(t *testing.T, th
require.NoError(t, err)
defer th.deleteChannel(alternate)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "Channel A", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "Channel A", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{alternate.Id}, res)
}
@ -177,7 +179,7 @@ func testAutocompleteAllChannelsIfTermIsEmpty(t *testing.T, th *SearchTestHelper
require.NoError(t, err)
defer th.deleteChannel(alternate)
defer th.deleteChannel(other)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id, other.Id}, res)
}
@ -186,17 +188,17 @@ func testSearchChannelsInCaseInsensitiveManner(t *testing.T, th *SearchTestHelpe
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
require.NoError(t, err)
defer th.deleteChannel(alternate)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channela", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channela", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res)
res, err = th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "ChAnNeL-a", false, false)
res, err = th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "ChAnNeL-a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res)
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "channela", false, false)
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "channela", false, false)
require.NoError(t, err)
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelAnotherTeam.Id, th.ChannelBasic.Id, alternate.Id}, res2)
res2, err = th.Store.Channel().Autocomplete(th.User.Id, "ChAnNeL-a", false, false)
res2, err = th.Store.Channel().Autocomplete(th.Context, th.User.Id, "ChAnNeL-a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelAnotherTeam.Id, th.ChannelBasic.Id, alternate.Id}, res2)
}
@ -205,10 +207,10 @@ func testSearchChannelsInCaseInsensitiveMannerPostgres(t *testing.T, th *SearchT
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
require.NoError(t, err)
defer th.deleteChannel(alternate)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channela", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channela", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res)
res, err = th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "ChAnNeL-a", false, false)
res, err = th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "ChAnNeL-a", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res)
}
@ -217,17 +219,17 @@ func testSearchShouldSupportHavingHyphenAsLastCharacter(t *testing.T, th *Search
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
require.NoError(t, err)
defer th.deleteChannel(alternate)
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-", false, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-", false, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res)
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "channel-", false, false)
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "channel-", false, false)
require.NoError(t, err)
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelAnotherTeam.Id, th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res2)
}
func testSearchShouldSupportAutocompleteWithArchivedChannels(t *testing.T, th *SearchTestHelper) {
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-", true, false)
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-", true, false)
require.NoError(t, err)
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, th.ChannelDeleted.Id}, res)
}

View File

@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
@ -186,7 +187,8 @@ var searchFileInfoStoreTests = []searchTest{
func TestSearchFileInfoStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) {
th := &SearchTestHelper{
Store: s,
Context: request.TestContext(t),
Store: s,
}
err := th.SetupBasicFixtures()
require.NoError(t, err)
@ -217,7 +219,7 @@ func testFileInfoSearchFileInfosIncludingDMs(t *testing.T, th *SearchTestHelper)
t.Run("by-name", func(t *testing.T) {
params := &model.SearchParams{Terms: "test"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -227,7 +229,7 @@ func testFileInfoSearchFileInfosIncludingDMs(t *testing.T, th *SearchTestHelper)
t.Run("by-content", func(t *testing.T) {
params := &model.SearchParams{Terms: "contenttest"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -258,13 +260,13 @@ func testFileInfoSearchFileInfosWithPagination(t *testing.T, th *SearchTestHelpe
t.Run("by-name", func(t *testing.T) {
params := &model.SearchParams{Terms: "test"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -273,13 +275,13 @@ func testFileInfoSearchFileInfosWithPagination(t *testing.T, th *SearchTestHelpe
t.Run("by-content", func(t *testing.T) {
params := &model.SearchParams{Terms: "contenttest"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -300,7 +302,7 @@ func testFileInfoSearchExactPhraseInQuotes(t *testing.T, th *SearchTestHelper) {
t.Run("by-name", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"channel test 1 2 3\""}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -309,7 +311,7 @@ func testFileInfoSearchExactPhraseInQuotes(t *testing.T, th *SearchTestHelper) {
t.Run("by-content", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"channel content test 1 2 3\""}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -331,7 +333,7 @@ func testFileInfoSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
t.Run("by-name", func(t *testing.T) {
t.Run("Should search email addresses enclosed by quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"test@test.com\""}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -340,7 +342,7 @@ func testFileInfoSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
t.Run("Should search email addresses without quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "test@test.com"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -350,7 +352,7 @@ func testFileInfoSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
t.Run("by-content", func(t *testing.T) {
t.Run("Should search email addresses enclosed by quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"test@content.com\""}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -359,7 +361,7 @@ func testFileInfoSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
t.Run("Should search email addresses without quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "test@content.com"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -379,7 +381,7 @@ func testFileInfoSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search the start inside the markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "start"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -388,7 +390,7 @@ func testFileInfoSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search a word in the middle of the markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "middle"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -397,7 +399,7 @@ func testFileInfoSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search in the end of the markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "end"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -406,7 +408,7 @@ func testFileInfoSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search inside markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "another"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -428,7 +430,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "你"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -436,7 +438,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search two words", func(t *testing.T) {
params := &model.SearchParams{Terms: "你好"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -444,7 +446,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search with wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "你*"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -459,7 +461,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "слово"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -467,7 +469,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search using wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "слов*"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -484,7 +486,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "本"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -493,7 +495,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search two words", func(t *testing.T) {
params := &model.SearchParams{Terms: "本木"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -501,7 +503,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search with wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "本*"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -519,7 +521,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "불"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -527,7 +529,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search two words", func(t *testing.T) {
params := &model.SearchParams{Terms: "불다"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -535,7 +537,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search with wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "불*"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -557,7 +559,7 @@ func testFileInfoSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper)
defer th.deleteUserFileInfos(th.User.Id)
params := &model.SearchParams{Terms: "Straße"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -565,7 +567,7 @@ func testFileInfoSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper)
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
params = &model.SearchParams{Terms: "Strasse"}
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -585,7 +587,7 @@ func testFileInfoSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestH
defer th.deleteUserFileInfos(th.User.Id)
params := &model.SearchParams{Terms: "café"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -593,7 +595,7 @@ func testFileInfoSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestH
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
params = &model.SearchParams{Terms: "café"}
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -601,7 +603,7 @@ func testFileInfoSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestH
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
params = &model.SearchParams{Terms: "cafe"}
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 0)
@ -620,7 +622,7 @@ func testFileInfoSearchOrExcludeFileInfosBySpecificUser(t *testing.T, th *Search
defer th.deleteUserFileInfos(th.User2.Id)
params := &model.SearchParams{Terms: "fromuser", FromUsers: []string{th.User.Id}}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -643,7 +645,7 @@ func testFileInfoSearchOrExcludeFileInfosInChannel(t *testing.T, th *SearchTestH
defer th.deleteUserFileInfos(th.User2.Id)
params := &model.SearchParams{Terms: "fromuser", InChannels: []string{th.ChannelBasic.Id}}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -678,7 +680,7 @@ func testFileInfoSearchOrExcludeFileInfosInDMGM(t *testing.T, th *SearchTestHelp
Terms: "fromuser",
InChannels: []string{direct.Id, group.Id},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -691,7 +693,7 @@ func testFileInfoSearchOrExcludeFileInfosInDMGM(t *testing.T, th *SearchTestHelp
Terms: "fromuser",
InChannels: []string{direct.Id},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -703,7 +705,7 @@ func testFileInfoSearchOrExcludeFileInfosInDMGM(t *testing.T, th *SearchTestHelp
Terms: "fromuser",
InChannels: []string{group.Id},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -730,7 +732,7 @@ func testFileInfoSearchOrExcludeByExtensions(t *testing.T, th *SearchTestHelper)
InChannels: []string{th.ChannelBasic.Id},
Extensions: []string{"jpg"},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -743,7 +745,7 @@ func testFileInfoSearchOrExcludeByExtensions(t *testing.T, th *SearchTestHelper)
InChannels: []string{th.ChannelBasic.Id},
Extensions: []string{"jpg", "bmp"},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -757,7 +759,7 @@ func testFileInfoSearchOrExcludeByExtensions(t *testing.T, th *SearchTestHelper)
InChannels: []string{th.ChannelBasic.Id},
ExcludedExtensions: []string{"jpg"},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -771,7 +773,7 @@ func testFileInfoSearchOrExcludeByExtensions(t *testing.T, th *SearchTestHelper)
InChannels: []string{th.ChannelBasic.Id},
ExcludedExtensions: []string{"jpg", "bmp"},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -802,7 +804,7 @@ func testFileInfoFilterFilesInSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test",
OnDate: "2020-03-22",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -813,7 +815,7 @@ func testFileInfoFilterFilesInSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test",
ExcludedDate: "2020-03-22",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -845,7 +847,7 @@ func testFileInfoFilterFilesBeforeSpecificDate(t *testing.T, th *SearchTestHelpe
Terms: "test",
BeforeDate: "2020-03-23",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -858,7 +860,7 @@ func testFileInfoFilterFilesBeforeSpecificDate(t *testing.T, th *SearchTestHelpe
Terms: "test",
ExcludedBeforeDate: "2020-03-23",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -889,7 +891,7 @@ func testFileInfoFilterFilesAfterSpecificDate(t *testing.T, th *SearchTestHelper
Terms: "test",
AfterDate: "2020-03-23",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -901,7 +903,7 @@ func testFileInfoFilterFilesAfterSpecificDate(t *testing.T, th *SearchTestHelper
Terms: "test",
ExcludedAfterDate: "2020-03-23",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -930,7 +932,7 @@ func testFileInfoFilterFilesWithATerm(t *testing.T, th *SearchTestHelper) {
Terms: "one",
ExcludedTerms: "five eight",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -942,7 +944,7 @@ func testFileInfoFilterFilesWithATerm(t *testing.T, th *SearchTestHelper) {
Terms: "one",
ExcludedTerms: "\"eight nine\"",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -969,7 +971,7 @@ func testFileInfoSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper)
Terms: "one two",
OrTerms: true,
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -982,7 +984,7 @@ func testFileInfoSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper)
Terms: "one two",
OrTerms: false,
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1015,7 +1017,7 @@ func testFileInfoSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper)
FromUsers: []string{th.User2.Id},
InChannels: []string{th.ChannelPrivate.Id},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1028,7 +1030,7 @@ func testFileInfoSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper)
ExcludedUsers: []string{th.User2.Id},
InChannels: []string{th.ChannelPrivate.Id},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1042,7 +1044,7 @@ func testFileInfoSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper)
ExcludedAfterDate: "2020-03-11",
InChannels: []string{th.ChannelPrivate.Id},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1054,7 +1056,7 @@ func testFileInfoSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper)
AfterDate: "2020-03-11",
ExcludedChannels: []string{th.ChannelPrivate.Id},
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1081,7 +1083,7 @@ func testFileInfoSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "the search",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1092,7 +1094,7 @@ func testFileInfoSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "a avoid",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1103,7 +1105,7 @@ func testFileInfoSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "in where you",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1111,14 +1113,14 @@ func testFileInfoSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should avoid stop words 'where', 'is' and 'the'", func(t *testing.T) {
results, err := th.Store.FileInfo().Search([]*model.SearchParams{{Terms: "is the car"}}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{{Terms: "is the car"}}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
th.checkFileInfoInSearchResults(t, p4.Id, results.FileInfos)
})
t.Run("Should remove all terms and return empty list", func(t *testing.T) {
results, err := th.Store.FileInfo().Search([]*model.SearchParams{{Terms: "is the"}}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{{Terms: "is the"}}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Empty(t, results.FileInfos)
})
@ -1140,7 +1142,7 @@ func testFileInfoSupportStemming(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "search",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -1165,7 +1167,7 @@ func testFileInfoSupportWildcards(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "search*",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -1177,7 +1179,7 @@ func testFileInfoSupportWildcards(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "sear* post",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1201,7 +1203,7 @@ func testFileInfoNotSupportPrecedingWildcards(t *testing.T, th *SearchTestHelper
params := &model.SearchParams{
Terms: "*earch",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 0)
@ -1221,7 +1223,7 @@ func testFileInfoSearchDiscardWildcardAlone(t *testing.T, th *SearchTestHelper)
params := &model.SearchParams{
Terms: "qwerty *",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1243,7 +1245,7 @@ func testFileInfoSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "term-with-dash",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1254,7 +1256,7 @@ func testFileInfoSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "\"term-with-dash\"",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1277,7 +1279,7 @@ func testFileInfoSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper)
params := &model.SearchParams{
Terms: "term_with_underscore",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1288,7 +1290,7 @@ func testFileInfoSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper)
params := &model.SearchParams{
Terms: "\"term_with_underscore\"",
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1317,7 +1319,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
t.Run("Doesn't include posts in deleted channels", func(t *testing.T) {
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: false}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -1327,7 +1329,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
t.Run("Include posts in deleted channels", func(t *testing.T) {
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: true}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 3)
@ -1338,7 +1340,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
t.Run("Include posts in deleted channels using multiple terms", func(t *testing.T) {
params := &model.SearchParams{Terms: "message channel", IncludeDeletedChannels: true}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 3)
@ -1353,7 +1355,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
IncludeDeletedChannels: true,
OrTerms: true,
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 3)
@ -1371,7 +1373,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
Terms: "#hashtag",
IncludeDeletedChannels: false,
}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params1, params2}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params1, params2}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, results)
require.Error(t, err)
})
@ -1390,7 +1392,7 @@ func testFileInfoSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "with-dash-term"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1399,7 +1401,7 @@ func testFileInfoSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with quoted dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"with-dash-term\""}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1408,7 +1410,7 @@ func testFileInfoSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple terms with one having dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "with-dash-term message"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1417,7 +1419,7 @@ func testFileInfoSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple OR terms with one having dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "with-dash-term message", OrTerms: true}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -1439,7 +1441,7 @@ func testFileInfoSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "with.dots.term"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1448,7 +1450,7 @@ func testFileInfoSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with quoted dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"with.dots.term\""}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1457,7 +1459,7 @@ func testFileInfoSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple terms with one having dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "with.dots.term message"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1466,7 +1468,7 @@ func testFileInfoSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple OR terms with one having dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "with.dots.term message", OrTerms: true}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -1488,7 +1490,7 @@ func testFileInfoSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper)
t.Run("Search for terms with underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "with_underscores_term"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1497,7 +1499,7 @@ func testFileInfoSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper)
t.Run("Search for terms with quoted underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"with_underscores_term\""}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1506,7 +1508,7 @@ func testFileInfoSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper)
t.Run("Search for multiple terms with one having underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "with_underscores_term message"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1515,7 +1517,7 @@ func testFileInfoSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper)
t.Run("Search for multiple OR terms with one having underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "with_underscores_term message", OrTerms: true}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -1542,7 +1544,7 @@ func testFileInfoSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper)
t.Run("Should stem appr", func(t *testing.T) {
params := &model.SearchParams{Terms: "appr*"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 3)
@ -1553,7 +1555,7 @@ func testFileInfoSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper)
t.Run("Should stem approve", func(t *testing.T) {
params := &model.SearchParams{Terms: "approve*"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1576,7 +1578,7 @@ func testFileInfoSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper
t.Run("Should return results without quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "hell*"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 2)
@ -1586,7 +1588,7 @@ func testFileInfoSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper
t.Run("Should return just one result with quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"hell\"*"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1604,21 +1606,21 @@ func testFileInfoSlashShouldNotBeCharSeparator(t *testing.T, th *SearchTestHelpe
defer th.deleteUserFileInfos(th.User.Id)
params := &model.SearchParams{Terms: "gamma"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
th.checkFileInfoInSearchResults(t, p1.Id, results.FileInfos)
params = &model.SearchParams{Terms: "beta"}
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
th.checkFileInfoInSearchResults(t, p1.Id, results.FileInfos)
params = &model.SearchParams{Terms: "alpha"}
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)
@ -1637,7 +1639,7 @@ func testFileInfoSearchEmailsWithoutQuotes(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserFileInfos(th.User.Id)
params := &model.SearchParams{Terms: "test@test.com"}
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.FileInfos, 1)

View File

@ -12,10 +12,12 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
type SearchTestHelper struct {
Context *request.Context
Store store.Store
Team *model.Team
AnotherTeam *model.Team
@ -293,7 +295,7 @@ func (th *SearchTestHelper) createDirectChannel(teamID, displayName string, user
m2.UserId = users[1].Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
channel, err := th.Store.Channel().SaveDirectChannel(channel, m1, m2)
channel, err := th.Store.Channel().SaveDirectChannel(th.Context, channel, m1, m2)
if err != nil {
return nil, err
}
@ -329,12 +331,12 @@ func (th *SearchTestHelper) createGroupChannel(teamID, displayName string, users
}
func (th *SearchTestHelper) deleteChannel(channel *model.Channel) error {
err := th.Store.Channel().PermanentDeleteMembersByChannel(channel.Id)
err := th.Store.Channel().PermanentDeleteMembersByChannel(th.Context, channel.Id)
if err != nil {
return err
}
return th.Store.Channel().PermanentDelete(channel.Id)
return th.Store.Channel().PermanentDelete(th.Context, channel.Id)
}
func (th *SearchTestHelper) deleteChannels(channels []*model.Channel) error {
@ -393,7 +395,7 @@ func (th *SearchTestHelper) createFileInfo(creatorID, postID, channelID, name, c
creationTime = createAt
}
fileInfoModel := th.createFileInfoModel(creatorID, postID, channelID, name, content, extension, mimeType, creationTime, size)
return th.Store.FileInfo().Save(fileInfoModel)
return th.Store.FileInfo().Save(th.Context, fileInfoModel)
}
func (th *SearchTestHelper) createReply(userID, message, hashtags string, parent *model.Post, createAt int64, pinned bool) (*model.Post, error) {
@ -403,7 +405,7 @@ func (th *SearchTestHelper) createReply(userID, message, hashtags string, parent
}
func (th *SearchTestHelper) deleteUserPosts(userID string) error {
err := th.Store.Post().PermanentDeleteByUser(userID)
err := th.Store.Post().PermanentDeleteByUser(th.Context, userID)
if err != nil {
return errors.New(err.Error())
}
@ -411,7 +413,7 @@ func (th *SearchTestHelper) deleteUserPosts(userID string) error {
}
func (th *SearchTestHelper) deleteUserFileInfos(userID string) error {
if _, err := th.Store.FileInfo().PermanentDeleteByUser(userID); err != nil {
if _, err := th.Store.FileInfo().PermanentDeleteByUser(th.Context, userID); err != nil {
return errors.New(err.Error())
}
return nil

View File

@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
@ -278,7 +279,8 @@ var searchPostStoreTests = []searchTest{
func TestSearchPostStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) {
th := &SearchTestHelper{
Store: s,
Context: request.TestContext(t),
Store: s,
}
err := th.SetupBasicFixtures()
require.NoError(t, err)
@ -301,7 +303,7 @@ func testSearchPostsIncludingDMs(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "test"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -323,13 +325,13 @@ func testSearchPostsWithPagination(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "test"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
th.checkPostInSearchResults(t, p2.Id, results.Posts)
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -344,7 +346,7 @@ func testSearchReturnPinnedAndUnpinned(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "test"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -444,7 +446,7 @@ func testSearchANDORQuotesCombinations(t *testing.T, th *SearchTestHelper) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
params := &model.SearchParams{Terms: tc.terms, OrTerms: tc.orTerms}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, tc.expectedLen)
@ -464,7 +466,7 @@ func testSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
t.Run("Should search email addresses enclosed by quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"test@test.com\""}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -473,7 +475,7 @@ func testSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
t.Run("Should search email addresses without quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "test@test.com"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -489,7 +491,7 @@ func testSearchEmailAddressesWithQuotes(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "\"test@test.com\""}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -503,7 +505,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search the start inside the markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "start"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -512,7 +514,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search a word in the middle of the markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "middle"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -521,7 +523,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search in the end of the markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "end"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -530,7 +532,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search inside markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "another"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -548,7 +550,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "你"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -556,7 +558,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search two words", func(t *testing.T) {
params := &model.SearchParams{Terms: "你好"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -564,7 +566,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search with wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "你*"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -579,7 +581,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "слово"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -587,7 +589,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search using wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "слов*"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -604,7 +606,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "本"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -613,7 +615,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search two words", func(t *testing.T) {
params := &model.SearchParams{Terms: "本木"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -621,7 +623,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search with wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "本*"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -639,7 +641,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "불"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -647,7 +649,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search two words", func(t *testing.T) {
params := &model.SearchParams{Terms: "불다"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -655,7 +657,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
})
t.Run("Should search with wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "불*"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -673,7 +675,7 @@ func testSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "Straße"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -681,7 +683,7 @@ func testSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper) {
th.checkPostInSearchResults(t, p2.Id, results.Posts)
params = &model.SearchParams{Terms: "Strasse"}
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -697,7 +699,7 @@ func testSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "café"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -705,7 +707,7 @@ func testSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestHelper) {
th.checkPostInSearchResults(t, p2.Id, results.Posts)
params = &model.SearchParams{Terms: "café"}
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -713,7 +715,7 @@ func testSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestHelper) {
th.checkPostInSearchResults(t, p2.Id, results.Posts)
params = &model.SearchParams{Terms: "cafe"}
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 0)
@ -731,7 +733,7 @@ func testSearchOrExcludePostsBySpecificUser(t *testing.T, th *SearchTestHelper)
Terms: "fromuser",
FromUsers: []string{th.User.Id},
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -750,7 +752,7 @@ func testSearchOrExcludePostsInChannel(t *testing.T, th *SearchTestHelper) {
Terms: "fromuser",
InChannels: []string{th.ChannelBasic.Id},
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -778,7 +780,7 @@ func testSearchOrExcludePostsInDMGM(t *testing.T, th *SearchTestHelper) {
Terms: "fromuser",
InChannels: []string{direct.Id, group.Id},
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -791,7 +793,7 @@ func testSearchOrExcludePostsInDMGM(t *testing.T, th *SearchTestHelper) {
Terms: "fromuser",
InChannels: []string{direct.Id},
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -803,7 +805,7 @@ func testSearchOrExcludePostsInDMGM(t *testing.T, th *SearchTestHelper) {
Terms: "fromuser",
InChannels: []string{group.Id},
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -828,7 +830,7 @@ func testFilterMessagesInSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test",
OnDate: "2020-03-22",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -839,7 +841,7 @@ func testFilterMessagesInSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test",
ExcludedDate: "2020-03-22",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -865,7 +867,7 @@ func testFilterMessagesBeforeSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test",
BeforeDate: "2020-03-23",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -878,7 +880,7 @@ func testFilterMessagesBeforeSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test",
ExcludedBeforeDate: "2020-03-23",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -903,7 +905,7 @@ func testFilterMessagesAfterSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test",
AfterDate: "2020-03-23",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -915,7 +917,7 @@ func testFilterMessagesAfterSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test",
ExcludedAfterDate: "2020-03-23",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -938,7 +940,7 @@ func testFilterMessagesWithATerm(t *testing.T, th *SearchTestHelper) {
Terms: "one",
ExcludedTerms: "five eight",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -950,7 +952,7 @@ func testFilterMessagesWithATerm(t *testing.T, th *SearchTestHelper) {
Terms: "one",
ExcludedTerms: "\"eight nine\"",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -973,7 +975,7 @@ func testSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper) {
Terms: "one two",
OrTerms: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -986,7 +988,7 @@ func testSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper) {
Terms: "one two",
OrTerms: false,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1013,7 +1015,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
FromUsers: []string{th.User2.Id},
InChannels: []string{th.ChannelPrivate.Id},
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1026,7 +1028,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
ExcludedUsers: []string{th.User2.Id},
InChannels: []string{th.ChannelPrivate.Id},
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1040,7 +1042,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
ExcludedAfterDate: "2020-03-11",
InChannels: []string{th.ChannelPrivate.Id},
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1052,7 +1054,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
AfterDate: "2020-03-11",
ExcludedChannels: []string{th.ChannelPrivate.Id},
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1075,7 +1077,7 @@ func testSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "the search",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1086,7 +1088,7 @@ func testSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "a avoid",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1097,7 +1099,7 @@ func testSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "in where you",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1130,7 +1132,7 @@ func testSupportStemming(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "search",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1151,7 +1153,7 @@ func testSupportWildcards(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "search*",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1163,7 +1165,7 @@ func testSupportWildcards(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "sear* post",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1183,7 +1185,7 @@ func testNotSupportPrecedingWildcards(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "*earch",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 0)
@ -1199,7 +1201,7 @@ func testSearchDiscardWildcardAlone(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "qwerty *",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1217,7 +1219,7 @@ func testSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "term-with-dash",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1228,7 +1230,7 @@ func testSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "\"term-with-dash\"",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1247,7 +1249,7 @@ func testSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "term_with_underscore",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1258,7 +1260,7 @@ func testSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{
Terms: "\"term_with_underscore\"",
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1280,7 +1282,7 @@ func testSearchOrExcludePostsWithHashtags(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1293,7 +1295,7 @@ func testSearchOrExcludePostsWithHashtags(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag",
IsHashtag: false,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1319,7 +1321,7 @@ func testSearchHashtagWithMarkdown(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 5)
@ -1342,7 +1344,7 @@ func testSearchWithMultipleHashtags(t *testing.T, th *SearchTestHelper) {
Terms: "#hashone #hashtwo",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1355,7 +1357,7 @@ func testSearchWithMultipleHashtags(t *testing.T, th *SearchTestHelper) {
IsHashtag: true,
OrTerms: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1373,7 +1375,7 @@ func testSearchPostsWithDotsInHashtags(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag.dot",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1394,7 +1396,7 @@ func testSearchHashtagCaseInsensitive(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 3)
@ -1408,7 +1410,7 @@ func testSearchHashtagCaseInsensitive(t *testing.T, th *SearchTestHelper) {
Terms: "#HASHTAG",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 3)
@ -1422,7 +1424,7 @@ func testSearchHashtagCaseInsensitive(t *testing.T, th *SearchTestHelper) {
Terms: "#HaShTaG",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 3)
@ -1443,7 +1445,7 @@ func testSearchHashtagWithDash(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag-test",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1461,7 +1463,7 @@ func testSearchHashtagWithNumbers(t *testing.T, th *SearchTestHelper) {
Terms: "#h4sht4g",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1479,7 +1481,7 @@ func testSearchHashtagWithDots(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag.test",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1497,7 +1499,7 @@ func testSearchHashtagWithUnderscores(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag_test",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1519,7 +1521,7 @@ func testSearchHashtagWithDashAndNumbers(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag-1-finals23",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1543,7 +1545,7 @@ func testSearchShouldExcludeSystemMessages(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "test system"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 0)
@ -1559,7 +1561,7 @@ func testSearchShouldBeAbleToMatchByMentions(t *testing.T, th *SearchTestHelper)
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "@testuser"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 3)
@ -1579,7 +1581,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
t.Run("Doesn't include posts in deleted channels", func(t *testing.T) {
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: false}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1589,7 +1591,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
t.Run("Include posts in deleted channels", func(t *testing.T) {
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: true}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 3)
@ -1600,7 +1602,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
t.Run("Include posts in deleted channels using multiple terms", func(t *testing.T) {
params := &model.SearchParams{Terms: "message channel", IncludeDeletedChannels: true}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 3)
@ -1615,7 +1617,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
IncludeDeletedChannels: true,
OrTerms: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 3)
@ -1633,7 +1635,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag",
IncludeDeletedChannels: false,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params1, params2}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params1, params2}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, results)
require.Error(t, err)
})
@ -1648,7 +1650,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "with-dash-term"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1657,7 +1659,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with quoted dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"with-dash-term\""}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1666,7 +1668,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple terms with one having dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "with-dash-term message"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1675,7 +1677,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple OR terms with one having dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "with-dash-term message", OrTerms: true}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1693,7 +1695,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "with.dots.term"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1702,7 +1704,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with quoted dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"with.dots.term\""}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1711,7 +1713,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple terms with one having dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "with.dots.term message"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1720,7 +1722,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple OR terms with one having dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "with.dots.term message", OrTerms: true}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1738,7 +1740,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "with_underscores_term"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1747,7 +1749,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with quoted underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"with_underscores_term\""}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1756,7 +1758,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple terms with one having underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "with_underscores_term message"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1765,7 +1767,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple OR terms with one having underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "with_underscores_term message", OrTerms: true}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1787,7 +1789,7 @@ func testSearchBotAccountsPosts(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(bot.UserId)
params := &model.SearchParams{Terms: "bot"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1806,7 +1808,7 @@ func testSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper) {
t.Run("Should stem appr", func(t *testing.T) {
params := &model.SearchParams{Terms: "appr*"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 3)
@ -1817,7 +1819,7 @@ func testSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper) {
t.Run("Should stem approve", func(t *testing.T) {
params := &model.SearchParams{Terms: "approve*"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1834,7 +1836,7 @@ func testSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper) {
t.Run("Should return results without quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "hell*"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
@ -1844,7 +1846,7 @@ func testSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper) {
t.Run("Should return just one result with quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"hell\"*"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1862,7 +1864,7 @@ func testHashtagSearchShouldSupportThreeOrMoreCharacters(t *testing.T, th *Searc
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "#123", IsHashtag: true}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1875,21 +1877,21 @@ func testSlashShouldNotBeCharSeparator(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "gamma"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
th.checkPostInSearchResults(t, p1.Id, results.Posts)
params = &model.SearchParams{Terms: "beta"}
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
th.checkPostInSearchResults(t, p1.Id, results.Posts)
params = &model.SearchParams{Terms: "alpha"}
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1904,7 +1906,7 @@ func testSupportSearchInComments(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "reply"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1917,7 +1919,7 @@ func testSupportSearchTermsWithinLinks(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "wikipedia"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 1)
@ -1930,7 +1932,7 @@ func testShouldNotReturnLinksEmbeddedInMarkdown(t *testing.T, th *SearchTestHelp
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "wikipedia"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 0)
@ -1939,7 +1941,7 @@ func testShouldNotReturnLinksEmbeddedInMarkdown(t *testing.T, th *SearchTestHelp
func testSearchAcrossTeams(t *testing.T, th *SearchTestHelper) {
err := th.addUserToChannels(th.User, []string{th.ChannelAnotherTeam.Id})
require.NoError(t, err)
defer th.Store.Channel().RemoveMember(th.ChannelAnotherTeam.Id, th.User.Id)
defer th.Store.Channel().RemoveMember(th.Context, th.ChannelAnotherTeam.Id, th.User.Id)
_, err = th.createPost(th.User.Id, th.ChannelAnotherTeam.Id, "text to search", "", model.PostTypeDefault, 0, false)
require.NoError(t, err)
@ -1948,7 +1950,7 @@ func testSearchAcrossTeams(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
params := &model.SearchParams{Terms: "search"}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, "", 0, 20)
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, "", 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)

View File

@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
@ -161,7 +162,8 @@ var searchUserStoreTests = []searchTest{
func TestSearchUserStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) {
th := &SearchTestHelper{
Store: s,
Context: request.TestContext(t),
Store: s,
}
err := th.SetupBasicFixtures()
require.NoError(t, err)
@ -174,13 +176,13 @@ func testGetAllUsersInChannelWithEmptyTerm(t *testing.T, th *SearchTestHelper) {
AllowFullNames: true,
Limit: model.UserSearchDefaultLimit,
}
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
t.Run("Should be able to correctly honor limit when autocompleting", func(t *testing.T) {
result, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
result, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
require.Len(t, result.InChannel, 1)
require.Len(t, result.OutOfChannel, 1)
@ -188,7 +190,7 @@ func testGetAllUsersInChannelWithEmptyTerm(t *testing.T, th *SearchTestHelper) {
t.Run("Return all users in team", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
@ -204,7 +206,7 @@ func testGetAllUsersInChannelWithEmptyTerm(t *testing.T, th *SearchTestHelper) {
defer th.deleteUser(userGuest)
// In case teamId and channelId are empty our current logic goes through Search
users, err := th.Store.User().Search("", "", options)
users, err := th.Store.User().Search(th.Context, "", "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2, th.UserAnotherTeam,
userAlternate, userGuest}, users)
@ -229,7 +231,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
t.Run("Autocomplete users with channel restrictions", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{th.ChannelBasic.Id}}
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, userAlternate, guest}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -237,7 +239,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
t.Run("Autocomplete users with term and channel restrictions", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{th.ChannelBasic.Id}}
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alt", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alt", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -245,7 +247,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
t.Run("Autocomplete users with all channels restricted", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{}, Channels: []string{}}
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -253,7 +255,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
t.Run("Autocomplete users with all channels restricted but with empty team", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{}, Channels: []string{}}
users, err := th.Store.User().AutocompleteUsersInChannel("", th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, "", th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -262,7 +264,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
options := createDefaultOptions(true, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{th.ChannelBasic.Id}}
// In case teamId and channelId are empty our current logic goes through Search
users, err := th.Store.User().Search("", "", options)
users, err := th.Store.User().Search(th.Context, "", "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate, guest, th.User}, users)
})
@ -272,7 +274,7 @@ func testHonorTeamRestrictionsAutocompletingUsers(t *testing.T, th *SearchTestHe
t.Run("Should return results for users in the team", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{th.Team.Id}}
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
@ -280,7 +282,7 @@ func testHonorTeamRestrictionsAutocompletingUsers(t *testing.T, th *SearchTestHe
t.Run("Should return empty because we're filtering all the teams", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{}, Channels: []string{}}
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -288,11 +290,11 @@ func testHonorTeamRestrictionsAutocompletingUsers(t *testing.T, th *SearchTestHe
t.Run("Should return empty when searching in one team and filtering by another", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{th.AnotherTeam.Id}}
users, err := th.Store.User().Search(th.Team.Id, "", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users)
acusers, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
acusers, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, acusers.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, acusers.OutOfChannel)
@ -302,7 +304,7 @@ func testShouldReturnNothingWithoutProperAccess(t *testing.T, th *SearchTestHelp
t.Run("Should return results users for the defined channel in the list", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
options.ListOfAllowedChannels = []string{th.ChannelBasic.Id}
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -310,7 +312,7 @@ func testShouldReturnNothingWithoutProperAccess(t *testing.T, th *SearchTestHelp
t.Run("Should return empty because we're filtering all the channels", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
options.ListOfAllowedChannels = []string{}
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -325,7 +327,7 @@ func testAutocompleteUserByUsername(t *testing.T, th *SearchTestHelper) {
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
require.NoError(t, err)
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
@ -340,14 +342,14 @@ func testAutocompleteUserByFirstName(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
t.Run("Should autocomplete users when the first name is unique", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "altfirstname", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "altfirstname", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should autocomplete users for in the channel and out of the channel with the same first name", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicfirstname", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicfirstname", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
@ -363,14 +365,14 @@ func testAutocompleteUserByLastName(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
t.Run("Should return results when the last name is unique", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "altlastname", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "altlastname", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should return results for in the channel and out of the channel with the same last name", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basiclastname", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basiclastname", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
@ -386,14 +388,14 @@ func testAutocompleteUserByNickName(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
t.Run("Should return results when the nickname is unique", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternatenickname", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternatenickname", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should return users that share the same part of the nickname", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicnickname", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicnickname", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
@ -403,7 +405,7 @@ func testAutocompleteUserByEmail(t *testing.T, th *SearchTestHelper) {
userAlternate, err := th.createUser("alternateusername", "alternatenickname", "firstname", "altlastname")
require.NoError(t, err)
userAlternate.Email = "useralt@test.email.com"
_, err = th.Store.User().Update(userAlternate, false)
_, err = th.Store.User().Update(th.Context, userAlternate, false)
require.NoError(t, err)
defer th.deleteUser(userAlternate)
err = th.addUserToTeams(userAlternate, []string{th.Team.Id})
@ -412,47 +414,47 @@ func testAutocompleteUserByEmail(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
t.Run("Should autocomplete users when the email is unique", func(t *testing.T) {
options := createDefaultOptions(false, true, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "useralt@test.email.com", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "useralt@test.email.com", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should autocomplete users that share the same email user prefix", func(t *testing.T) {
options := createDefaultOptions(false, true, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "success_", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "success_", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
})
t.Run("Should autocomplete users that share the same email domain", func(t *testing.T) {
options := createDefaultOptions(false, true, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "simulator.amazon.com", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "simulator.amazon.com", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
})
t.Run("Should search users when the email is unique", func(t *testing.T) {
options := createDefaultOptions(false, true, false)
users, err := th.Store.User().Search(th.Team.Id, "useralt@test.email.com", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "useralt@test.email.com", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
})
t.Run("Should search users that share the same email user prefix", func(t *testing.T) {
options := createDefaultOptions(false, true, false)
users, err := th.Store.User().Search(th.Team.Id, "success_", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "success_", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
})
t.Run("Should search users that share the same email domain", func(t *testing.T) {
options := createDefaultOptions(false, true, false)
users, err := th.Store.User().Search(th.Team.Id, "simulator.amazon.com", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "simulator.amazon.com", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
})
}
func testShouldNotMatchSpecificQueriesEmail(t *testing.T, th *SearchTestHelper) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "success_", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "success_", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -467,21 +469,21 @@ func testAutocompleteUserByUsernameWithDot(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
t.Run("Should return results when searching for the whole username with Dot", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate.username", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate.username", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should return results when searching for part of the username including the Dot", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, ".username", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, ".username", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should return results when searching for part of the username not including the Dot", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "username", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "username", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -497,21 +499,21 @@ func testAutocompleteUserByUsernameWithUnderscore(t *testing.T, th *SearchTestHe
require.NoError(t, err)
t.Run("Should return results when searching for the whole username with underscore", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate_username", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate_username", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should return results when searching for part of the username including the underscore", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "_username", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "_username", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should return results when searching for part of the username not including the underscore", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "username", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "username", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -527,21 +529,21 @@ func testAutocompleteUserByUsernameWithHyphen(t *testing.T, th *SearchTestHelper
require.NoError(t, err)
t.Run("Should return results when searching for the whole username with hyphen", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate-username", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate-username", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should return results when searching for part of the username including the hyphen", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "-username", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "-username", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should return results when searching for part of the username not including the hyphen", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "username", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "username", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -558,14 +560,14 @@ func testShouldEscapePercentageCharacter(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
t.Run("Should autocomplete users escaping percentage symbol", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate%", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate%", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should search users escaping percentage symbol", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().Search(th.Team.Id, "alternate%", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate%", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
})
@ -580,14 +582,14 @@ func testShouldEscapeUnderscoreCharacter(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
t.Run("Should autocomplete users escaping underscore symbol", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate_", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate_", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should search users escaping underscore symbol", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().Search(th.Team.Id, "alternate_", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate_", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
})
@ -597,7 +599,7 @@ func testShouldBeAbleToSearchInactiveUsers(t *testing.T, th *SearchTestHelper) {
userAlternate, err := th.createUser("basicusernamealternate", "alternatenickname", "firstname", "altlastname")
require.NoError(t, err)
userAlternate.DeleteAt = model.GetMillis()
_, err = th.Store.User().Update(userAlternate, true)
_, err = th.Store.User().Update(th.Context, userAlternate, true)
require.NoError(t, err)
defer th.deleteUser(userAlternate)
err = th.addUserToTeams(userAlternate, []string{th.Team.Id})
@ -606,27 +608,27 @@ func testShouldBeAbleToSearchInactiveUsers(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
t.Run("Should autocomplete inactive users if we allow it", func(t *testing.T) {
options := createDefaultOptions(false, false, true)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
})
t.Run("Should search inactive users if we allow it", func(t *testing.T) {
options := createDefaultOptions(false, false, true)
users, err := th.Store.User().Search(th.Team.Id, "basicusername", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2, userAlternate}, users)
})
t.Run("Shouldn't autocomplete inactive users if we don't allow it", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
})
t.Run("Shouldn't search inactive users if we don't allow it", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().Search(th.Team.Id, "basicusername", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2}, users)
})
@ -636,13 +638,13 @@ func testShouldBeAbleToSearchFilteringByRole(t *testing.T, th *SearchTestHelper)
userAlternate, err := th.createUser("basicusernamealternate", "alternatenickname", "firstname", "altlastname")
require.NoError(t, err)
userAlternate.Roles = "system_admin system_user"
_, err = th.Store.User().Update(userAlternate, true)
_, err = th.Store.User().Update(th.Context, userAlternate, true)
require.NoError(t, err)
defer th.deleteUser(userAlternate)
userAlternate2, err := th.createUser("basicusernamealternate2", "alternatenickname2", "firstname2", "altlastname2")
require.NoError(t, err)
userAlternate2.Roles = "system_user"
_, err = th.Store.User().Update(userAlternate2, true)
_, err = th.Store.User().Update(th.Context, userAlternate2, true)
require.NoError(t, err)
defer th.deleteUser(userAlternate2)
err = th.addUserToTeams(userAlternate, []string{th.Team.Id})
@ -654,7 +656,7 @@ func testShouldBeAbleToSearchFilteringByRole(t *testing.T, th *SearchTestHelper)
t.Run("Should autocomplete users filtering by roles", func(t *testing.T) {
options := createDefaultOptions(false, false, true)
options.Role = "system_admin"
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -662,7 +664,7 @@ func testShouldBeAbleToSearchFilteringByRole(t *testing.T, th *SearchTestHelper)
t.Run("Should search users filtering by roles", func(t *testing.T) {
options := createDefaultOptions(false, false, true)
options.Role = "system_admin"
users, err := th.Store.User().Search(th.Team.Id, "", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
})
@ -671,14 +673,14 @@ func testShouldBeAbleToSearchFilteringByRole(t *testing.T, th *SearchTestHelper)
func testShouldIgnoreLeadingAtSymbols(t *testing.T, th *SearchTestHelper) {
t.Run("Should autocomplete ignoring the @ symbol at the beginning", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "@basicusername", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "@basicusername", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
})
t.Run("Should search ignoring the @ symbol at the beginning", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().Search(th.Team.Id, "@basicusername", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "@basicusername", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2}, users)
})
@ -686,7 +688,7 @@ func testShouldIgnoreLeadingAtSymbols(t *testing.T, th *SearchTestHelper) {
func testSearchUsersShouldBeCaseInsensitive(t *testing.T, th *SearchTestHelper) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "BaSiCUsErNaMe", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "BaSiCUsErNaMe", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
@ -703,14 +705,14 @@ func testSearchOneTwoCharUsernamesAndFirstLastNames(t *testing.T, th *SearchTest
require.NoError(t, err)
t.Run("Should support two characters in the full name", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "zi", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "zi", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should support two characters in the username", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "ho", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "ho", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -728,14 +730,14 @@ func testShouldSupportKoreanCharacters(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
t.Run("Should support hanja korean characters", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "서강준", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "서강준", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
})
t.Run("Should support hangul korean characters", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "안신원", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "안신원", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -751,7 +753,7 @@ func testSearchWithHyphenAtTheEndOfTheTerm(t *testing.T, th *SearchTestHelper) {
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
require.NoError(t, err)
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate-", options)
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate-", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
@ -760,39 +762,39 @@ func testSearchWithHyphenAtTheEndOfTheTerm(t *testing.T, th *SearchTestHelper) {
func testSearchUsersInTeam(t *testing.T, th *SearchTestHelper) {
t.Run("Should return all the team users", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().Search(th.Team.Id, "", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2}, users)
})
t.Run("Should return all the team users with no team id", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().Search("", "basicusername", options)
users, err := th.Store.User().Search(th.Context, "", "basicusername", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2, th.UserAnotherTeam}, users)
})
t.Run("Should return all the team users filtered by username", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().Search(th.Team.Id, "basicusername1", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername1", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
})
t.Run("Should not return spurious results", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().Search(th.Team.Id, "falseuser", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "falseuser", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users)
})
t.Run("Should return all the team users filtered by username and with channel restrictions", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{th.ChannelBasic.Id}}
users, err := th.Store.User().Search(th.Team.Id, "basicusername", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
})
t.Run("Should return all the team users filtered by username and with all channel restricted", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{}}
users, err := th.Store.User().Search(th.Team.Id, "basicusername1", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername1", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users)
})
@ -801,7 +803,7 @@ func testSearchUsersInTeam(t *testing.T, th *SearchTestHelper) {
Limit: 1,
}
users, err := th.Store.User().Search(th.Team.Id, "", optionsWithLimit)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "", optionsWithLimit)
require.NoError(t, err)
require.Len(t, users, 1)
})
@ -816,7 +818,7 @@ func testSearchUsersInTeamUsernameWithDot(t *testing.T, th *SearchTestHelper) {
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
require.NoError(t, err)
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().Search(th.Team.Id, "alternate.", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate.", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
}
@ -830,7 +832,7 @@ func testSearchUsersInTeamUsernameWithHyphen(t *testing.T, th *SearchTestHelper)
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
require.NoError(t, err)
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().Search(th.Team.Id, "alternate-", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate-", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
}
@ -844,7 +846,7 @@ func testSearchUsersInTeamUsernameWithUnderscore(t *testing.T, th *SearchTestHel
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
require.NoError(t, err)
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().Search(th.Team.Id, "alternate_", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate_", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
}
@ -852,19 +854,19 @@ func testSearchUsersInTeamUsernameWithUnderscore(t *testing.T, th *SearchTestHel
func testSearchUsersByFullName(t *testing.T, th *SearchTestHelper) {
t.Run("Should search users by full name", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().Search(th.Team.Id, "basicfirstname", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicfirstname", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2}, users)
})
t.Run("Should search user by full name", func(t *testing.T) {
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().Search(th.Team.Id, "basicfirstname1", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicfirstname1", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
})
t.Run("Should return empty when search by full name and is deactivated", func(t *testing.T) {
options := createDefaultOptions(false, false, false)
users, err := th.Store.User().Search(th.Team.Id, "basicfirstname1", options)
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicfirstname1", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users)
})
@ -878,7 +880,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
// searching user without specifying team
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().Search("", "hello", options)
users, err := th.Store.User().Search(th.Context, "", "hello", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
@ -890,7 +892,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
options = createDefaultOptions(true, false, false)
users, err = th.Store.User().Search(th.Team.Id, "hello", options)
users, err = th.Store.User().Search(th.Context, th.Team.Id, "hello", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
})
@ -900,7 +902,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
defer th.deleteUser(userAlternate)
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().Search("", "hello", options)
users, err := th.Store.User().Search(th.Context, "", "hello", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
@ -912,7 +914,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
options = createDefaultOptions(true, false, false)
users, err = th.Store.User().Search(th.Team.Id, "hello", options)
users, err = th.Store.User().Search(th.Context, th.Team.Id, "hello", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
})
@ -922,7 +924,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
defer th.deleteUser(userAlternate)
options := createDefaultOptions(true, false, false)
users, err := th.Store.User().Search("", "hello", options)
users, err := th.Store.User().Search(th.Context, "", "hello", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
@ -934,7 +936,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
require.NoError(t, err)
options = createDefaultOptions(true, false, false)
users, err = th.Store.User().Search(th.Team.Id, "hello", options)
users, err = th.Store.User().Search(th.Context, th.Team.Id, "hello", options)
require.NoError(t, err)
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
})

View File

@ -6,11 +6,7 @@ package sqlstore
import (
"bytes"
"database/sql/driver"
"fmt"
"strconv"
"strings"
"github.com/mattermost/mattermost/server/public/shared/mlog"
)
type jsonArray []string
@ -50,16 +46,6 @@ func (str jsonKeyPath) Value() (driver.Value, error) {
return "{" + string(str) + "}", nil
}
type TraceOnAdapter struct{}
func (t *TraceOnAdapter) Printf(format string, v ...any) {
originalString := fmt.Sprintf(format, v...)
newString := strings.ReplaceAll(originalString, "\n", " ")
newString = strings.ReplaceAll(newString, "\t", " ")
newString = strings.ReplaceAll(newString, "\"", "")
mlog.Debug(newString)
}
type JSONSerializable interface {
ToJSON() string
}

View File

@ -18,6 +18,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/einterfaces"
"github.com/mattermost/mattermost/server/v8/platform/services/cache"
@ -613,7 +614,7 @@ func (s SqlChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64)
return newChannel, err
}
func (s SqlChannelStore) CreateDirectChannel(user *model.User, otherUser *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error) {
func (s SqlChannelStore) CreateDirectChannel(rctx request.CTX, user *model.User, otherUser *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error) {
channel := new(model.Channel)
for _, option := range channelOptions {
@ -641,10 +642,10 @@ func (s SqlChannelStore) CreateDirectChannel(user *model.User, otherUser *model.
SchemeUser: !otherUser.IsGuest(),
}
return s.SaveDirectChannel(channel, cm1, cm2)
return s.SaveDirectChannel(rctx, channel, cm1, cm2)
}
func (s SqlChannelStore) SaveDirectChannel(directChannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (_ *model.Channel, err error) {
func (s SqlChannelStore) SaveDirectChannel(rctx request.CTX, directChannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (_ *model.Channel, err error) {
if directChannel.DeleteAt != 0 {
return nil, store.NewErrInvalidInput("Channel", "DeleteAt", directChannel.DeleteAt)
}
@ -721,7 +722,7 @@ func (s SqlChannelStore) saveChannelT(transaction *sqlxTxWrapper, channel *model
}
// Update writes the updated channel to the database.
func (s SqlChannelStore) Update(channel *model.Channel) (_ *model.Channel, err error) {
func (s SqlChannelStore) Update(rctx request.CTX, channel *model.Channel) (_ *model.Channel, err error) {
transaction, err := s.GetMasterX().Beginx()
if err != nil {
return nil, errors.Wrap(err, "begin_transaction")
@ -973,7 +974,7 @@ func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *sqlxTxWrapper, tea
}
// PermanentDelete removes the given channel from the database.
func (s SqlChannelStore) PermanentDelete(channelId string) (err error) {
func (s SqlChannelStore) PermanentDelete(rctx request.CTX, channelId string) (err error) {
transaction, err := s.GetMasterX().Beginx()
if err != nil {
return errors.Wrap(err, "PermanentDelete: begin_transaction")
@ -1009,7 +1010,7 @@ func (s SqlChannelStore) permanentDeleteT(transaction *sqlxTxWrapper, channelId
return nil
}
func (s SqlChannelStore) PermanentDeleteMembersByChannel(channelId string) error {
func (s SqlChannelStore) PermanentDeleteMembersByChannel(rctx request.CTX, channelId string) error {
_, err := s.GetMasterX().Exec("DELETE FROM ChannelMembers WHERE ChannelId = ?", channelId)
if err != nil {
return errors.Wrapf(err, "failed to delete Channel with channelId=%s", channelId)
@ -1836,7 +1837,7 @@ func (s SqlChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) (
return updatedMembers, nil
}
func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
func (s SqlChannelStore) UpdateMember(rctx request.CTX, member *model.ChannelMember) (*model.ChannelMember, error) {
updatedMembers, err := s.UpdateMultipleMembers([]*model.ChannelMember{member})
if err != nil {
return nil, err
@ -2485,7 +2486,7 @@ func (s SqlChannelStore) GetGuestCount(channelId string, allowFromCache bool) (i
return count, nil
}
func (s SqlChannelStore) RemoveMembers(channelId string, userIds []string) error {
func (s SqlChannelStore) RemoveMembers(rctx request.CTX, channelId string, userIds []string) error {
builder := s.getQueryBuilder().
Delete("ChannelMembers").
Where(sq.Eq{"ChannelId": channelId}).
@ -2516,11 +2517,11 @@ func (s SqlChannelStore) RemoveMembers(channelId string, userIds []string) error
return nil
}
func (s SqlChannelStore) RemoveMember(channelId string, userId string) error {
return s.RemoveMembers(channelId, []string{userId})
func (s SqlChannelStore) RemoveMember(rctx request.CTX, channelId string, userId string) error {
return s.RemoveMembers(rctx, channelId, []string{userId})
}
func (s SqlChannelStore) RemoveAllDeactivatedMembers(channelId string) error {
func (s SqlChannelStore) RemoveAllDeactivatedMembers(rctx request.CTX, channelId string) error {
query := `
DELETE
FROM
@ -2545,7 +2546,7 @@ func (s SqlChannelStore) RemoveAllDeactivatedMembers(channelId string) error {
return nil
}
func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) error {
func (s SqlChannelStore) PermanentDeleteMembersByUser(rctx request.CTX, userId string) error {
if _, err := s.GetMasterX().Exec("DELETE FROM ChannelMembers WHERE UserId = ?", userId); err != nil {
return errors.Wrapf(err, "failed to permanent delete ChannelMembers with userId=%s", userId)
}
@ -3035,7 +3036,7 @@ func (s SqlChannelStore) GetTeamMembersForChannel(channelID string) ([]string, e
return teamMemberIDs, nil
}
func (s SqlChannelStore) Autocomplete(userID, term string, includeDeleted, isGuest bool) (model.ChannelListWithTeamData, error) {
func (s SqlChannelStore) Autocomplete(rctx request.CTX, userID, term string, includeDeleted, isGuest bool) (model.ChannelListWithTeamData, error) {
query := s.getQueryBuilder().Select("c.*",
"t.DisplayName AS TeamDisplayName",
"t.Name AS TeamName",
@ -3090,7 +3091,7 @@ func (s SqlChannelStore) Autocomplete(userID, term string, includeDeleted, isGue
return channels, nil
}
func (s SqlChannelStore) AutocompleteInTeam(teamID, userID, term string, includeDeleted, isGuest bool) (model.ChannelList, error) {
func (s SqlChannelStore) AutocompleteInTeam(rctx request.CTX, teamID, userID, term string, includeDeleted, isGuest bool) (model.ChannelList, error) {
query := s.getQueryBuilder().Select("*").
From("Channels c").
Where(sq.Eq{"c.TeamId": teamID}).

View File

@ -90,7 +90,6 @@ func (s SqlCommandWebhookStore) TryUse(id string, limit int) error {
}
func (s SqlCommandWebhookStore) Cleanup() {
mlog.Debug("Cleaning up command webhook store.")
exptime := model.GetMillis() - model.CommandWebhookLifetime
query := s.getQueryBuilder().

View File

@ -15,6 +15,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/einterfaces"
)
@ -110,7 +111,7 @@ func newSqlFileInfoStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterfac
return s
}
func (fs SqlFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, error) {
func (fs SqlFileInfoStore) Save(rctx request.CTX, info *model.FileInfo) (*model.FileInfo, error) {
info.PreSave()
if err := info.IsValid(); err != nil {
return nil, err
@ -159,7 +160,7 @@ func (fs SqlFileInfoStore) GetByIds(ids []string) ([]*model.FileInfo, error) {
return infos, nil
}
func (fs SqlFileInfoStore) Upsert(info *model.FileInfo) (*model.FileInfo, error) {
func (fs SqlFileInfoStore) Upsert(rctx request.CTX, info *model.FileInfo) (*model.FileInfo, error) {
info.PreSave()
if err := info.IsValid(); err != nil {
return nil, err
@ -202,7 +203,7 @@ func (fs SqlFileInfoStore) Upsert(info *model.FileInfo) (*model.FileInfo, error)
return nil, errors.Wrap(err, "unable to retrieve rows affected")
}
if count == 0 {
return fs.Save(info)
return fs.Save(rctx, info)
}
return info, nil
}
@ -388,7 +389,7 @@ func (fs SqlFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, error)
return infos, nil
}
func (fs SqlFileInfoStore) AttachToPost(fileId, postId, channelId, creatorId string) error {
func (fs SqlFileInfoStore) AttachToPost(rctx request.CTX, fileId, postId, channelId, creatorId string) error {
query := fs.getQueryBuilder().
Update("FileInfo").
Set("PostId", postId).
@ -422,7 +423,7 @@ func (fs SqlFileInfoStore) AttachToPost(fileId, postId, channelId, creatorId str
return nil
}
func (fs SqlFileInfoStore) SetContent(fileId, content string) error {
func (fs SqlFileInfoStore) SetContent(rctx request.CTX, fileId, content string) error {
query := fs.getQueryBuilder().
Update("FileInfo").
Set("Content", content).
@ -441,7 +442,7 @@ func (fs SqlFileInfoStore) SetContent(fileId, content string) error {
return nil
}
func (fs SqlFileInfoStore) DeleteForPost(postId string) (string, error) {
func (fs SqlFileInfoStore) DeleteForPost(rctx request.CTX, postId string) (string, error) {
if _, err := fs.GetMasterX().Exec(
`UPDATE
FileInfo
@ -454,14 +455,14 @@ func (fs SqlFileInfoStore) DeleteForPost(postId string) (string, error) {
return postId, nil
}
func (fs SqlFileInfoStore) PermanentDelete(fileId string) error {
func (fs SqlFileInfoStore) PermanentDelete(rctx request.CTX, fileId string) error {
if _, err := fs.GetMasterX().Exec(`DELETE FROM FileInfo WHERE Id = ?`, fileId); err != nil {
return errors.Wrapf(err, "failed to delete FileInfo with id=%s", fileId)
}
return nil
}
func (fs SqlFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
func (fs SqlFileInfoStore) PermanentDeleteBatch(rctx request.CTX, endTime int64, limit int64) (int64, error) {
var query string
if fs.DriverName() == "postgres" {
query = "DELETE from FileInfo WHERE Id = any (array (SELECT Id FROM FileInfo WHERE CreateAt < ? LIMIT ?))"
@ -482,7 +483,7 @@ func (fs SqlFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int
return rowsAffected, nil
}
func (fs SqlFileInfoStore) PermanentDeleteByUser(userId string) (int64, error) {
func (fs SqlFileInfoStore) PermanentDeleteByUser(rctx request.CTX, userId string) (int64, error) {
query := "DELETE from FileInfo WHERE CreatorId = ?"
sqlResult, err := fs.GetMasterX().Exec(query, userId)
@ -498,7 +499,7 @@ func (fs SqlFileInfoStore) PermanentDeleteByUser(userId string) (int64, error) {
return rowsAffected, nil
}
func (fs SqlFileInfoStore) Search(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.FileInfoList, error) {
func (fs SqlFileInfoStore) Search(rctx request.CTX, paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.FileInfoList, error) {
// Since we don't support paging for DB search, we just return nothing for later pages
if page > 0 {
return model.NewFileInfoList(), nil
@ -659,7 +660,7 @@ func (fs SqlFileInfoStore) Search(paramsList []*model.SearchParams, userId, team
items := []fileInfoWithChannelID{}
err = fs.GetSearchReplicaX().Select(&items, queryString, args...)
if err != nil {
mlog.Warn("Query error searching files.", mlog.String("error", trimInput(err.Error())))
rctx.Logger().Warn("Query error searching files.", mlog.String("error", trimInput(err.Error())))
// Don't return the error to the caller as it is of no use to the user. Instead return an empty set of search results.
} else {
for _, item := range items {

View File

@ -3,8 +3,12 @@
package sqlstore
func InitTest() {
initStores()
import (
"github.com/mattermost/mattermost/server/public/shared/mlog"
)
func InitTest(logger mlog.LoggerIFace) {
initStores(logger)
}
func TearDownTest() {

View File

@ -116,12 +116,12 @@ func createEmoji(ss store.Store, userId string) *model.Emoji {
return emoji
}
func createFileInfo(ss store.Store, postId, channelId, userId string) *model.FileInfo {
func createFileInfo(rctx request.CTX, ss store.Store, postId, channelId, userId string) *model.FileInfo {
m := model.FileInfo{}
m.PostId = postId
m.CreatorId = userId
m.Path = "some/path/to/file"
info, _ := ss.FileInfo().Save(&m)
info, _ := ss.FileInfo().Save(rctx, &m)
return info
}
@ -493,7 +493,7 @@ func TestCheckChannelsChannelMembersIntegrity(t *testing.T) {
require.Equal(t, model.OrphanedRecord{
ParentId: &member.ChannelId,
}, data.Records[0])
ss.Channel().PermanentDeleteMembersByChannel(member.ChannelId)
ss.Channel().PermanentDeleteMembersByChannel(rctx, member.ChannelId)
})
})
}
@ -625,7 +625,7 @@ func TestCheckPostsFileInfoIntegrity(t *testing.T) {
t.Run("should generate a report with one record", func(t *testing.T) {
postId := model.NewId()
info := createFileInfo(ss, postId, model.NewId(), model.NewId())
info := createFileInfo(rctx, ss, postId, model.NewId(), model.NewId())
result := checkPostsFileInfoIntegrity(store)
require.NoError(t, result.Err)
data := result.Data.(model.RelationalIntegrityCheckData)
@ -821,7 +821,7 @@ func TestCheckTeamsChannelsIntegrity(t *testing.T) {
channel := createChannelWithTeamId(ss, model.NewId())
userA := createUser(ss)
userB := createUser(ss)
direct, err := ss.Channel().CreateDirectChannel(userA, userB)
direct, err := ss.Channel().CreateDirectChannel(rctx, userA, userB)
require.NoError(t, err)
require.NotNil(t, direct)
result := checkTeamsChannelsIntegrity(store)
@ -842,7 +842,7 @@ func TestCheckTeamsChannelsIntegrity(t *testing.T) {
channel := createChannelWithTeamId(ss, model.NewId())
userA := createUser(ss)
userB := createUser(ss)
direct, err := ss.Channel().CreateDirectChannel(userA, userB)
direct, err := ss.Channel().CreateDirectChannel(rctx, userA, userB)
require.NoError(t, err)
require.NotNil(t, direct)
_, err = dbmap.Exec(`UPDATE Channels SET TeamId = 'test' WHERE Id = '` + direct.Id + `'`)
@ -1120,7 +1120,7 @@ func TestCheckUsersChannelMembersIntegrity(t *testing.T) {
ParentId: &member.UserId,
}, data.Records[0])
dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, channel.Id)
ss.Channel().PermanentDeleteMembersByUser(member.UserId)
ss.Channel().PermanentDeleteMembersByUser(rctx, member.UserId)
})
})
}
@ -1228,7 +1228,7 @@ func TestCheckUsersFileInfoIntegrity(t *testing.T) {
t.Run("should generate a report with one record", func(t *testing.T) {
user := createUser(ss)
userId := user.Id
info := createFileInfo(ss, model.NewId(), model.NewId(), userId)
info := createFileInfo(rctx, ss, model.NewId(), model.NewId(), userId)
dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id)
result := checkUsersFileInfoIntegrity(store)
require.NoError(t, result.Err)

View File

@ -16,7 +16,7 @@ func TestMain(m *testing.M) {
mainHelper = testlib.NewMainHelperWithOptions(nil)
defer mainHelper.Close()
sqlstore.InitTest()
sqlstore.InitTest(mainHelper.Logger)
mainHelper.Main(m)
sqlstore.TearDownTest()

View File

@ -28,11 +28,12 @@ type Migrator struct {
store *SqlStore
}
func NewMigrator(settings model.SqlSettings, dryRun bool) (*Migrator, error) {
func NewMigrator(settings model.SqlSettings, logger mlog.LoggerIFace, dryRun bool) (*Migrator, error) {
ss := &SqlStore{
rrCounter: 0,
srCounter: 0,
settings: &settings,
logger: logger,
quitMonitor: make(chan struct{}),
wgMonitor: &sync.WaitGroup{},
}
@ -127,7 +128,7 @@ func (ss *SqlStore) initMorph(dryRun bool) (*morph.Morph, error) {
if err != nil {
return nil, err
}
db, err2 := SetupConnection("master", dataSource, ss.settings, DBPingAttempts)
db, err2 := SetupConnection(ss.Logger(), "master", dataSource, ss.settings, DBPingAttempts)
if err2 != nil {
return nil, err2
}

View File

@ -7,11 +7,14 @@ import (
"testing"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestUpAndDownMigrations(t *testing.T) {
logger := mlog.CreateTestLogger(t)
testDrivers := []string{
model.DatabaseDriverPostgres,
model.DatabaseDriverMysql,
@ -24,7 +27,7 @@ func TestUpAndDownMigrations(t *testing.T) {
t.Skip(err)
}
store, err := New(*settings, nil)
store, err := New(*settings, logger, nil)
require.NoError(t, err)
defer store.Close()

View File

@ -18,6 +18,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/channels/store/searchlayer"
"github.com/mattermost/mattermost/server/v8/channels/utils"
@ -329,7 +330,7 @@ func (s *SqlPostStore) populateReplyCount(posts []*model.Post) error {
return nil
}
func (s *SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) (*model.Post, error) {
func (s *SqlPostStore) Update(rctx request.CTX, newPost *model.Post, oldPost *model.Post) (*model.Post, error) {
newPost.UpdateAt = model.GetMillis()
newPost.PreCommit()
@ -451,7 +452,7 @@ func (s *SqlPostStore) OverwriteMultiple(posts []*model.Post) (_ []*model.Post,
return posts, -1, nil
}
func (s *SqlPostStore) Overwrite(post *model.Post) (*model.Post, error) {
func (s *SqlPostStore) Overwrite(rctx request.CTX, post *model.Post) (*model.Post, error) {
posts, _, err := s.OverwriteMultiple([]*model.Post{post})
if err != nil {
return nil, err
@ -870,7 +871,7 @@ func (s *SqlPostStore) GetEtag(channelId string, allowFromCache, collapsedThread
// Soft deletes a post
// and cleans up the thread if it's a comment
func (s *SqlPostStore) Delete(postID string, time int64, deleteByID string) (err error) {
func (s *SqlPostStore) Delete(rctx request.CTX, postID string, time int64, deleteByID string) (err error) {
transaction, err := s.GetMasterX().Beginx()
if err != nil {
return errors.Wrap(err, "begin_transaction")
@ -1010,7 +1011,7 @@ func (s *SqlPostStore) permanentDeleteAllCommentByUser(userId string) (err error
// cleans up threads (removes said user from participants and decreases reply count),
// permanent delete all root posts by user,
// and delete threads and thread memberships for those root posts
func (s *SqlPostStore) PermanentDeleteByUser(userId string) error {
func (s *SqlPostStore) PermanentDeleteByUser(rctx request.CTX, userId string) error {
// First attempt to delete all the comments for a user
if err := s.permanentDeleteAllCommentByUser(userId); err != nil {
return err
@ -1048,7 +1049,7 @@ func (s *SqlPostStore) PermanentDeleteByUser(userId string) error {
// deletes all threads and thread memberships
// deletes all reactions
// no thread comment cleanup needed, since we are deleting threads and thread memberships
func (s *SqlPostStore) PermanentDeleteByChannel(channelId string) (err error) {
func (s *SqlPostStore) PermanentDeleteByChannel(rctx request.CTX, channelId string) (err error) {
transaction, err := s.GetMasterX().Beginx()
if err != nil {
return errors.Wrap(err, "begin_transaction")
@ -2713,7 +2714,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
}
//nolint:unparam
func (s *SqlPostStore) SearchPostsForUser(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, error) {
func (s *SqlPostStore) SearchPostsForUser(rctx request.CTX, paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, error) {
// Since we don't support paging for DB search, we just return nothing for later pages
if page > 0 {
return model.MakePostSearchResults(model.NewPostList(), nil), nil

View File

@ -22,7 +22,6 @@ func newSqlPreferenceStore(sqlStore *SqlStore) store.PreferenceStore {
}
func (s SqlPreferenceStore) deleteUnusedFeatures() {
mlog.Debug("Deleting any unused pre-release features")
sql, args, err := s.getQueryBuilder().
Delete("Preferences").
Where(sq.Eq{"Category": model.PreferenceCategoryAdvancedSettings}).

View File

@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
)
func TestSqlX(t *testing.T) {
@ -32,6 +33,7 @@ func TestSqlX(t *testing.T) {
rrCounter: 0,
srCounter: 0,
settings: settings,
logger: mlog.CreateConsoleTestLogger(t),
quitMonitor: make(chan struct{}),
wgMonitor: &sync.WaitGroup{},
}

View File

@ -131,6 +131,7 @@ type SqlStore struct {
context context.Context
license *model.License
licenseMutex sync.RWMutex
logger mlog.LoggerIFace
metrics einterfaces.MetricsInterface
isBinaryParam bool
@ -140,12 +141,13 @@ type SqlStore struct {
wgMonitor *sync.WaitGroup
}
func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) (*SqlStore, error) {
func New(settings model.SqlSettings, logger mlog.LoggerIFace, metrics einterfaces.MetricsInterface) (*SqlStore, error) {
store := &SqlStore{
rrCounter: 0,
srCounter: 0,
settings: &settings,
metrics: metrics,
logger: logger,
quitMonitor: make(chan struct{}),
wgMonitor: &sync.WaitGroup{},
}
@ -241,16 +243,22 @@ func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) (*Sql
// SetupConnection sets up the connection to the database and pings it to make sure it's alive.
// It also applies any database configuration settings that are required.
func SetupConnection(connType string, dataSource string, settings *model.SqlSettings, attempts int) (*dbsql.DB, error) {
func SetupConnection(logger mlog.LoggerIFace, connType string, dataSource string, settings *model.SqlSettings, attempts int) (*dbsql.DB, error) {
db, err := dbsql.Open(*settings.DriverName, dataSource)
if err != nil {
return nil, errors.Wrap(err, "failed to open SQL connection")
}
// At this point, we have passed sql.Open, so we deliberately ignore any errors.
sanitized, _ := SanitizeDataSource(*settings.DriverName, dataSource)
logger = logger.With(
mlog.String("database", connType),
mlog.String("dataSource", sanitized),
)
for i := 0; i < attempts; i++ {
// At this point, we have passed sql.Open, so we deliberately ignore any errors.
sanitized, _ := SanitizeDataSource(*settings.DriverName, dataSource)
mlog.Info("Pinging SQL", mlog.String("database", connType), mlog.String("dataSource", sanitized))
logger.Info("Pinging SQL")
ctx, cancel := context.WithTimeout(context.Background(), DBPingTimeoutSecs*time.Second)
defer cancel()
err = db.PingContext(ctx)
@ -258,7 +266,7 @@ func SetupConnection(connType string, dataSource string, settings *model.SqlSett
if i == attempts-1 {
return nil, err
}
mlog.Error("Failed to ping DB", mlog.Err(err), mlog.Int("retrying in seconds", DBPingTimeoutSecs))
logger.Error("Failed to ping DB", mlog.Int("retrying in seconds", DBPingTimeoutSecs), mlog.Err(err))
time.Sleep(DBPingTimeoutSecs * time.Second)
continue
}
@ -293,6 +301,10 @@ func (ss *SqlStore) Context() context.Context {
return ss.context
}
func (ss *SqlStore) Logger() mlog.LoggerIFace {
return ss.logger
}
func noOpMapper(s string) string { return s }
func (ss *SqlStore) initConnection() error {
@ -308,7 +320,7 @@ func (ss *SqlStore) initConnection() error {
}
}
handle, err := SetupConnection("master", dataSource, ss.settings, DBPingAttempts)
handle, err := SetupConnection(ss.Logger(), "master", dataSource, ss.settings, DBPingAttempts)
if err != nil {
return err
}
@ -326,7 +338,7 @@ func (ss *SqlStore) initConnection() error {
ss.ReplicaXs = make([]*atomic.Pointer[sqlxDBWrapper], len(ss.settings.DataSourceReplicas))
for i, replica := range ss.settings.DataSourceReplicas {
ss.ReplicaXs[i] = &atomic.Pointer[sqlxDBWrapper]{}
handle, err = SetupConnection(fmt.Sprintf("replica-%v", i), replica, ss.settings, DBPingAttempts)
handle, err = SetupConnection(ss.Logger(), fmt.Sprintf("replica-%v", i), replica, ss.settings, DBPingAttempts)
if err != nil {
// Initializing to be offline
ss.ReplicaXs[i].Store(&sqlxDBWrapper{isOnline: &atomic.Bool{}})
@ -341,7 +353,7 @@ func (ss *SqlStore) initConnection() error {
ss.searchReplicaXs = make([]*atomic.Pointer[sqlxDBWrapper], len(ss.settings.DataSourceSearchReplicas))
for i, replica := range ss.settings.DataSourceSearchReplicas {
ss.searchReplicaXs[i] = &atomic.Pointer[sqlxDBWrapper]{}
handle, err = SetupConnection(fmt.Sprintf("search-replica-%v", i), replica, ss.settings, DBPingAttempts)
handle, err = SetupConnection(ss.Logger(), fmt.Sprintf("search-replica-%v", i), replica, ss.settings, DBPingAttempts)
if err != nil {
// Initializing to be offline
ss.searchReplicaXs[i].Store(&sqlxDBWrapper{isOnline: &atomic.Bool{}})
@ -358,7 +370,7 @@ func (ss *SqlStore) initConnection() error {
if src.DataSource == nil {
continue
}
ss.replicaLagHandles[i], err = SetupConnection(fmt.Sprintf(replicaLagPrefix+"-%d", i), *src.DataSource, ss.settings, DBPingAttempts)
ss.replicaLagHandles[i], err = SetupConnection(ss.Logger(), fmt.Sprintf(replicaLagPrefix+"-%d", i), *src.DataSource, ss.settings, DBPingAttempts)
if err != nil {
mlog.Warn("Failed to setup replica lag handle. Skipping..", mlog.String("db", fmt.Sprintf(replicaLagPrefix+"-%d", i)), mlog.Err(err))
continue
@ -513,7 +525,7 @@ func (ss *SqlStore) monitorReplicas() {
return
}
handle, err := SetupConnection(name, dsn, ss.settings, 1)
handle, err := SetupConnection(ss.Logger(), name, dsn, ss.settings, 1)
if err != nil {
mlog.Warn("Failed to setup connection. Skipping..", mlog.String("db", name), mlog.Err(err))
return

View File

@ -24,6 +24,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin/plugintest/mock"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/db"
"github.com/mattermost/mattermost/server/v8/channels/store"
@ -106,7 +107,7 @@ func StoreTestWithSqlStore(t *testing.T, f func(*testing.T, request.CTX, store.S
}
}
func initStores() {
func initStores(logger mlog.LoggerIFace) {
if testing.Short() {
return
}
@ -138,7 +139,7 @@ func initStores() {
st := st
eg.Go(func() error {
var err error
st.SqlStore, err = New(*st.SqlSettings, nil)
st.SqlStore, err = New(*st.SqlSettings, logger, nil)
if err != nil {
return err
}
@ -183,12 +184,14 @@ func tearDownStores() {
// before the fix in MM-28397.
// Keeping it here to help avoiding future regressions.
func TestStoreLicenseRace(t *testing.T) {
logger := mlog.CreateTestLogger(t)
settings, err := makeSqlSettings(model.DatabaseDriverPostgres)
if err != nil {
t.Skip(err)
}
store, err := New(*settings, nil)
store, err := New(*settings, logger, nil)
require.NoError(t, err)
defer func() {
store.Close()
@ -218,6 +221,9 @@ func TestStoreLicenseRace(t *testing.T) {
func TestGetReplica(t *testing.T) {
t.Parallel()
logger := mlog.CreateTestLogger(t)
testCases := []struct {
Description string
DataSourceReplicaNum int
@ -289,7 +295,7 @@ func TestGetReplica(t *testing.T) {
settings.DataSourceReplicas = dataSourceReplicas
settings.DataSourceSearchReplicas = dataSourceSearchReplicas
store, err := New(*settings, nil)
store, err := New(*settings, logger, nil)
require.NoError(t, err)
defer func() {
store.Close()
@ -362,7 +368,7 @@ func TestGetReplica(t *testing.T) {
settings.DataSourceReplicas = dataSourceReplicas
settings.DataSourceSearchReplicas = dataSourceSearchReplicas
store, err := New(*settings, nil)
store, err := New(*settings, logger, nil)
require.NoError(t, err)
defer func() {
store.Close()
@ -416,6 +422,8 @@ func TestGetReplica(t *testing.T) {
}
func TestGetDbVersion(t *testing.T) {
logger := mlog.CreateTestLogger(t)
testDrivers := []string{
model.DatabaseDriverPostgres,
model.DatabaseDriverMysql,
@ -430,7 +438,7 @@ func TestGetDbVersion(t *testing.T) {
t.Skip(err)
}
store, err := New(*settings, nil)
store, err := New(*settings, logger, nil)
require.NoError(t, err)
version, err := store.GetDbVersion(false)
@ -573,6 +581,9 @@ func TestIsBinaryParamEnabled(t *testing.T) {
func TestGetAllConns(t *testing.T) {
t.Parallel()
logger := mlog.CreateConsoleTestLogger(t)
testCases := []struct {
Description string
DataSourceReplicaNum int
@ -654,7 +665,7 @@ func TestGetAllConns(t *testing.T) {
settings.DataSourceReplicas = dataSourceReplicas
settings.DataSourceSearchReplicas = dataSourceSearchReplicas
store, err := New(*settings, nil)
store, err := New(*settings, logger, nil)
require.NoError(t, err)
defer func() {
store.Close()
@ -764,6 +775,7 @@ func TestReplicaLagQuery(t *testing.T) {
srCounter: 0,
settings: settings,
metrics: mockMetrics,
logger: mlog.CreateConsoleTestLogger(t),
quitMonitor: make(chan struct{}),
wgMonitor: &sync.WaitGroup{},
}
@ -841,6 +853,7 @@ func TestMySQLReadTimeout(t *testing.T) {
store := &SqlStore{
settings: settings,
logger: mlog.CreateConsoleTestLogger(t),
quitMonitor: make(chan struct{}),
wgMonitor: &sync.WaitGroup{},
}
@ -857,6 +870,7 @@ func TestGetDBSchemaVersion(t *testing.T) {
model.DatabaseDriverMysql,
}
logger := mlog.CreateConsoleTestLogger(t)
assets := db.Assets()
for _, d := range testDrivers {
@ -867,7 +881,7 @@ func TestGetDBSchemaVersion(t *testing.T) {
if err != nil {
t.Skip(err)
}
store, err := New(*settings, nil)
store, err := New(*settings, logger, nil)
require.NoError(t, err)
assetsList, err := assets.ReadDir(filepath.Join("migrations", driver))
@ -896,6 +910,8 @@ func TestGetLocalSchemaVersion(t *testing.T) {
model.DatabaseDriverMysql,
}
logger := mlog.CreateConsoleTestLogger(t)
for _, d := range testDrivers {
driver := d
t.Run(driver, func(t *testing.T) {
@ -903,7 +919,7 @@ func TestGetLocalSchemaVersion(t *testing.T) {
if err != nil {
t.Skip(err)
}
store, err := New(*settings, nil)
store, err := New(*settings, logger, nil)
require.NoError(t, err)
ver, err := store.GetLocalSchemaVersion()
@ -922,6 +938,7 @@ func TestGetAppliedMigrations(t *testing.T) {
model.DatabaseDriverMysql,
}
logger := mlog.CreateConsoleTestLogger(t)
assets := db.Assets()
for _, d := range testDrivers {
@ -932,7 +949,7 @@ func TestGetAppliedMigrations(t *testing.T) {
if err != nil {
t.Skip(err)
}
store, err := New(*settings, nil)
store, err := New(*settings, logger, nil)
require.NoError(t, err)
assetsList, err := assets.ReadDir(filepath.Join("migrations", driver))

View File

@ -936,7 +936,7 @@ func (s SqlTeamStore) UpdateMultipleMembers(members []*model.TeamMember) ([]*mod
return updatedMembers, nil
}
func (s SqlTeamStore) UpdateMember(member *model.TeamMember) (*model.TeamMember, error) {
func (s SqlTeamStore) UpdateMember(rctx request.CTX, member *model.TeamMember) (*model.TeamMember, error) {
members, err := s.UpdateMultipleMembers([]*model.TeamMember{member})
if err != nil {
return nil, err
@ -1184,7 +1184,7 @@ func (s SqlTeamStore) GetChannelUnreadsForTeam(teamId, userId string) ([]*model.
return channels, nil
}
func (s SqlTeamStore) RemoveMembers(teamId string, userIds []string) error {
func (s SqlTeamStore) RemoveMembers(rctx request.CTX, teamId string, userIds []string) error {
builder := s.getQueryBuilder().
Delete("TeamMembers").
Where(sq.Eq{"TeamId": teamId}).
@ -1202,8 +1202,8 @@ func (s SqlTeamStore) RemoveMembers(teamId string, userIds []string) error {
}
// RemoveMember remove from the database the team members that match the userId and teamId passed as parameter.
func (s SqlTeamStore) RemoveMember(teamId string, userId string) error {
return s.RemoveMembers(teamId, []string{userId})
func (s SqlTeamStore) RemoveMember(rctx request.CTX, teamId string, userId string) error {
return s.RemoveMembers(rctx, teamId, []string{userId})
}
// RemoveAllMembersByTeam removes from the database the team members that belong to the teamId passed as parameter.
@ -1223,7 +1223,7 @@ func (s SqlTeamStore) RemoveAllMembersByTeam(teamId string) error {
}
// RemoveAllMembersByUser removes from the database the team members that match the userId passed as parameter.
func (s SqlTeamStore) RemoveAllMembersByUser(userId string) error {
func (s SqlTeamStore) RemoveAllMembersByUser(rctx request.CTX, userId string) error {
query, args, err := s.getQueryBuilder().
Delete("TeamMembers").
Where(sq.Eq{"UserId": userId}).ToSql()

View File

@ -18,6 +18,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/einterfaces"
)
@ -162,7 +163,7 @@ func (us SqlUserStore) DeactivateGuests() ([]string, error) {
return userIds, nil
}
func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) (*model.UserUpdate, error) {
func (us SqlUserStore) Update(rctx request.CTX, user *model.User, trustedUpdateData bool) (*model.UserUpdate, error) {
user.PreUpdate()
if err := user.IsValid(); err != nil {
@ -1511,7 +1512,7 @@ func (us SqlUserStore) GetAnyUnreadPostCountForChannel(userId string, channelId
return count, nil
}
func (us SqlUserStore) Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, error) {
func (us SqlUserStore) Search(rctx request.CTX, teamId string, term string, options *model.UserSearchOptions) ([]*model.User, error) {
query := us.usersQuery.
OrderBy("Username ASC").
Limit(uint64(options.Limit))
@ -2143,7 +2144,7 @@ func (us SqlUserStore) DemoteUserToGuest(userID string) (_ *model.User, err erro
return user, nil
}
func (us SqlUserStore) AutocompleteUsersInChannel(teamId, channelId, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error) {
func (us SqlUserStore) AutocompleteUsersInChannel(rctx request.CTX, teamId, channelId, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error) {
var usersInChannel, usersNotInChannel []*model.User
g := errgroup.Group{}
g.Go(func() (err error) {

View File

@ -11,6 +11,7 @@ import (
"time"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/product"
)
@ -94,6 +95,7 @@ type Store interface {
CheckIntegrity() <-chan model.IntegrityCheckResult
SetContext(context context.Context)
Context() context.Context
Logger() mlog.LoggerIFace
NotifyAdmin() NotifyAdminStore
PostPriority() PostPriorityStore
PostAcknowledgement() PostAcknowledgementStore
@ -147,7 +149,7 @@ type TeamStore interface {
AnalyticsTeamCount(opts *model.TeamSearch) (int64, error)
SaveMultipleMembers(members []*model.TeamMember, maxUsersPerTeam int) ([]*model.TeamMember, error)
SaveMember(member *model.TeamMember, maxUsersPerTeam int) (*model.TeamMember, error)
UpdateMember(member *model.TeamMember) (*model.TeamMember, error)
UpdateMember(rctx request.CTX, member *model.TeamMember) (*model.TeamMember, error)
UpdateMultipleMembers(members []*model.TeamMember) ([]*model.TeamMember, error)
GetMember(c request.CTX, teamID string, userID string) (*model.TeamMember, error)
GetMembers(teamID string, offset int, limit int, teamMembersGetOptions *model.TeamMembersGetOptions) ([]*model.TeamMember, error)
@ -158,10 +160,10 @@ type TeamStore interface {
GetTeamsForUserWithPagination(userID string, page, perPage int) ([]*model.TeamMember, error)
GetChannelUnreadsForAllTeams(excludeTeamID, userID string) ([]*model.ChannelUnread, error)
GetChannelUnreadsForTeam(teamID, userID string) ([]*model.ChannelUnread, error)
RemoveMember(teamID string, userID string) error
RemoveMembers(teamID string, userIds []string) error
RemoveMember(rctx request.CTX, teamID string, userID string) error
RemoveMembers(rctx request.CTX, teamID string, userIds []string) error
RemoveAllMembersByTeam(teamID string) error
RemoveAllMembersByUser(userID string) error
RemoveAllMembersByUser(ctx request.CTX, userID string) error
UpdateLastTeamIconUpdate(teamID string, curTime int64) error
GetTeamsByScheme(schemeID string, offset int, limit int) ([]*model.Team, error)
MigrateTeamMembers(fromTeamID string, fromUserID string) (map[string]string, error)
@ -191,9 +193,9 @@ type TeamStore interface {
type ChannelStore interface {
Save(channel *model.Channel, maxChannelsPerTeam int64) (*model.Channel, error)
CreateDirectChannel(userID *model.User, otherUserID *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error)
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error)
Update(channel *model.Channel) (*model.Channel, error)
CreateDirectChannel(ctx request.CTX, userID *model.User, otherUserID *model.User, channelOptions ...model.ChannelOption) (*model.Channel, error)
SaveDirectChannel(ctx request.CTX, channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error)
Update(ctx request.CTX, channel *model.Channel) (*model.Channel, error)
UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamID string) error
ClearSidebarOnTeamLeave(userID, teamID string) error
Get(id string, allowFromCache bool) (*model.Channel, error)
@ -203,7 +205,7 @@ type ChannelStore interface {
Delete(channelID string, timestamp int64) error
Restore(channelID string, timestamp int64) error
SetDeleteAt(channelID string, deleteAt int64, updateAt int64) error
PermanentDelete(channelID string) error
PermanentDelete(ctx request.CTX, channelID string) error
PermanentDeleteByTeam(teamID string) error
GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error)
GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error)
@ -228,7 +230,7 @@ type ChannelStore interface {
GetForPost(postID string) (*model.Channel, error)
SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error)
SaveMember(member *model.ChannelMember) (*model.ChannelMember, error)
UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error)
UpdateMember(ctx request.CTX, member *model.ChannelMember) (*model.ChannelMember, error)
UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error)
// UpdateMemberNotifyProps patches the notifyProps field with the given props map.
// It replaces existing fields and creates new ones which don't exist.
@ -256,10 +258,10 @@ type ChannelStore interface {
InvalidateGuestCount(channelID string)
GetGuestCount(channelID string, allowFromCache bool) (int64, error)
GetPinnedPosts(channelID string) (*model.PostList, error)
RemoveMember(channelID string, userID string) error
RemoveMembers(channelID string, userIds []string) error
PermanentDeleteMembersByUser(userID string) error
PermanentDeleteMembersByChannel(channelID string) error
RemoveMember(ctx request.CTX, channelID string, userID string) error
RemoveMembers(ctx request.CTX, channelID string, userIds []string) error
PermanentDeleteMembersByUser(ctx request.CTX, userID string) error
PermanentDeleteMembersByChannel(ctx request.CTX, channelID string) error
UpdateLastViewedAt(channelIds []string, userID string) (map[string]int64, error)
UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount, mentionCountRoot, urgentMentionCount int, setUnreadCountRoot bool) (*model.ChannelUnreadAt, error)
CountPostsAfter(channelID string, timestamp int64, excludedUserID string) (int, int, error)
@ -269,8 +271,8 @@ type ChannelStore interface {
GetMembersForUser(teamID string, userID string) (model.ChannelMembers, error)
GetTeamMembersForChannel(channelID string) ([]string, error)
GetMembersForUserWithPagination(userID string, page, perPage int) (model.ChannelMembersWithTeamData, error)
Autocomplete(userID, term string, includeDeleted, isGuest bool) (model.ChannelListWithTeamData, error)
AutocompleteInTeam(teamID, userID, term string, includeDeleted, isGuest bool) (model.ChannelList, error)
Autocomplete(rctx request.CTX, userID, term string, includeDeleted, isGuest bool) (model.ChannelListWithTeamData, error)
AutocompleteInTeam(rctx request.CTX, teamID, userID, term string, includeDeleted, isGuest bool) (model.ChannelList, error)
AutocompleteInTeamForSearch(teamID string, userID string, term string, includeDeleted bool) (model.ChannelList, error)
SearchAllChannels(term string, opts ChannelSearchOpts) (model.ChannelListWithTeamData, int64, error)
SearchInTeam(teamID string, term string, includeDeleted bool) (model.ChannelList, error)
@ -305,7 +307,7 @@ type ChannelStore interface {
GetAllChannelsForExportAfter(limit int, afterID string) ([]*model.ChannelForExport, error)
GetAllDirectChannelsForExportAfter(limit int, afterID string) ([]*model.DirectChannelForExport, error)
GetChannelMembersForExport(userID string, teamID string, includeArchivedChannel bool) ([]*model.ChannelMemberForExport, error)
RemoveAllDeactivatedMembers(channelID string) error
RemoveAllDeactivatedMembers(ctx request.CTX, channelID string) error
GetChannelsBatchForIndexing(startTime int64, startChannelID string, limit int) ([]*model.Channel, error)
UserBelongsToChannels(userID string, channelIds []string) (bool, error)
@ -362,12 +364,12 @@ type ThreadStore interface {
type PostStore interface {
SaveMultiple(posts []*model.Post) ([]*model.Post, int, error)
Save(post *model.Post) (*model.Post, error)
Update(newPost *model.Post, oldPost *model.Post) (*model.Post, error)
Update(rctx request.CTX, newPost *model.Post, oldPost *model.Post) (*model.Post, error)
Get(ctx context.Context, id string, opts model.GetPostsOptions, userID string, sanitizeOptions map[string]bool) (*model.PostList, error)
GetSingle(id string, inclDeleted bool) (*model.Post, error)
Delete(postID string, timestamp int64, deleteByID string) error
PermanentDeleteByUser(userID string) error
PermanentDeleteByChannel(channelID string) error
Delete(rctx request.CTX, postID string, timestamp int64, deleteByID string) error
PermanentDeleteByUser(rctx request.CTX, userID string) error
PermanentDeleteByChannel(rctx request.CTX, channelID string) error
GetPosts(options model.GetPostsOptions, allowFromCache bool, sanitizeOptions map[string]bool) (*model.PostList, error)
GetFlaggedPosts(userID string, offset int, limit int) (*model.PostList, error)
// @openTracingParams userID, teamID, offset, limit
@ -388,7 +390,7 @@ type PostStore interface {
ClearCaches()
InvalidateLastPostTimeCache(channelID string)
GetPostsCreatedAt(channelID string, timestamp int64) ([]*model.Post, error)
Overwrite(post *model.Post) (*model.Post, error)
Overwrite(rctx request.CTX, post *model.Post) (*model.Post, error)
OverwriteMultiple(posts []*model.Post) ([]*model.Post, int, error)
GetPostsByIds(postIds []string) ([]*model.Post, error)
GetEditHistoryForPost(postId string) ([]*model.Post, error)
@ -400,7 +402,7 @@ type PostStore interface {
GetParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.PostForExport, error)
GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error)
GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error)
SearchPostsForUser(paramsList []*model.SearchParams, userID, teamID string, page, perPage int) (*model.PostSearchResults, error)
SearchPostsForUser(rctx request.CTX, paramsList []*model.SearchParams, userID, teamID string, page, perPage int) (*model.PostSearchResults, error)
GetOldestEntityCreationTime() (int64, error)
HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error)
GetPostsSinceForSync(options model.GetPostsSinceForSyncOptions, cursor model.GetPostsSinceForSyncCursor, limit int) ([]*model.Post, model.GetPostsSinceForSyncCursor, error)
@ -413,7 +415,7 @@ type PostStore interface {
type UserStore interface {
Save(user *model.User) (*model.User, error)
Update(user *model.User, allowRoleUpdate bool) (*model.UserUpdate, error)
Update(rctx request.CTX, user *model.User, allowRoleUpdate bool) (*model.UserUpdate, error)
UpdateNotifyProps(userID string, props map[string]string) error
UpdateLastPictureUpdate(userID string) error
ResetLastPictureUpdate(userID string) error
@ -462,7 +464,7 @@ type UserStore interface {
GetAnyUnreadPostCountForChannel(userID string, channelID string) (int64, error)
GetRecentlyActiveUsersForTeam(teamID string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, error)
GetNewUsersForTeam(teamID string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, error)
Search(teamID string, term string, options *model.UserSearchOptions) ([]*model.User, error)
Search(rctx request.CTX, teamID string, term string, options *model.UserSearchOptions) ([]*model.User, error)
SearchNotInTeam(notInTeamID string, term string, options *model.UserSearchOptions) ([]*model.User, error)
SearchInChannel(channelID string, term string, options *model.UserSearchOptions) ([]*model.User, error)
SearchNotInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) ([]*model.User, error)
@ -485,7 +487,7 @@ type UserStore interface {
PromoteGuestToUser(userID string) error
DemoteUserToGuest(userID string) (*model.User, error)
DeactivateGuests() ([]string, error)
AutocompleteUsersInChannel(teamID, channelID, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error)
AutocompleteUsersInChannel(rctx request.CTX, teamID, channelID, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error)
GetKnownUsers(userID string) ([]string, error)
IsEmpty(excludeBots bool) (bool, error)
GetUsersWithInvalidEmails(page int, perPage int, restrictedDomains string) ([]*model.User, error)
@ -706,8 +708,8 @@ type StatusStore interface {
}
type FileInfoStore interface {
Save(info *model.FileInfo) (*model.FileInfo, error)
Upsert(info *model.FileInfo) (*model.FileInfo, error)
Save(ctx request.CTX, info *model.FileInfo) (*model.FileInfo, error)
Upsert(rctx request.CTX, info *model.FileInfo) (*model.FileInfo, error)
Get(id string) (*model.FileInfo, error)
GetFromMaster(id string) (*model.FileInfo, error)
GetByIds(ids []string) ([]*model.FileInfo, error)
@ -716,13 +718,13 @@ type FileInfoStore interface {
GetForUser(userID string) ([]*model.FileInfo, error)
GetWithOptions(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, error)
InvalidateFileInfosForPostCache(postID string, deleted bool)
AttachToPost(fileID string, postID string, channelID, creatorID string) error
DeleteForPost(postID string) (string, error)
PermanentDelete(fileID string) error
PermanentDeleteBatch(endTime int64, limit int64) (int64, error)
PermanentDeleteByUser(userID string) (int64, error)
SetContent(fileID, content string) error
Search(paramsList []*model.SearchParams, userID, teamID string, page, perPage int) (*model.FileInfoList, error)
AttachToPost(c request.CTX, fileID string, postID string, channelID, creatorID string) error
DeleteForPost(c request.CTX, postID string) (string, error)
PermanentDelete(c request.CTX, fileID string) error
PermanentDeleteBatch(ctx request.CTX, endTime int64, limit int64) (int64, error)
PermanentDeleteByUser(ctx request.CTX, userID string) (int64, error)
SetContent(ctx request.CTX, fileID, content string) error
Search(ctx request.CTX, paramsList []*model.SearchParams, userID, teamID string, page, perPage int) (*model.FileInfoList, error)
CountAll() (int64, error)
GetFilesBatchForIndexing(startTime int64, startFileID string, includeDeleted bool, limit int) ([]*model.FileForIndexing, error)
ClearCaches()

View File

@ -199,7 +199,7 @@ func testBotStoreGetAll(t *testing.T, rctx request.CTX, ss store.Store, s SqlSto
require.NoError(t, err1, "couldn't save user")
deletedUser.DeleteAt = model.GetMillis()
_, err2 := ss.User().Update(&deletedUser, true)
_, err2 := ss.User().Update(rctx, &deletedUser, true)
require.NoError(t, err2, "couldn't delete user")
defer func() { require.NoError(t, ss.User().PermanentDelete(deletedUser.Id)) }()

View File

@ -46,7 +46,7 @@ func cleanupChannels(t *testing.T, rctx request.CTX, ss store.Store) {
list, err := ss.Channel().GetAllChannels(0, 100000, store.ChannelSearchOpts{IncludeDeleted: true})
require.NoError(t, err, "error cleaning all channels", err)
for _, channel := range list {
err = ss.Channel().PermanentDelete(channel.Id)
err = ss.Channel().PermanentDelete(rctx, channel.Id)
assert.NoError(t, err)
}
}
@ -239,7 +239,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, rctx request.CTX, ss store.
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
_, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
_, nErr = ss.Channel().SaveDirectChannel(rctx, &o1, &m1, &m2)
require.NoError(t, nErr, "couldn't save direct channel", nErr)
members, nErr := ss.Channel().GetMembers(o1.Id, 0, 100)
@ -250,7 +250,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, rctx request.CTX, ss store.
require.NoError(t, nErr)
require.ElementsMatch(t, []string{u1.Id, u2.Id}, userIDs)
_, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
_, nErr = ss.Channel().SaveDirectChannel(rctx, &o1, &m1, &m2)
require.Error(t, nErr, "shouldn't be a able to update from save")
// Attempt to save a direct channel that already exists
@ -261,7 +261,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, rctx request.CTX, ss store.
Type: o1.Type,
}
returnedChannel, nErr := ss.Channel().SaveDirectChannel(&o1a, &m1, &m2)
returnedChannel, nErr := ss.Channel().SaveDirectChannel(rctx, &o1a, &m1, &m2)
require.Error(t, nErr, "should've failed to save a duplicate direct channel")
var cErr *store.ErrConflict
require.Truef(t, errors.As(nErr, &cErr), "should've returned ChannelExistsError")
@ -271,7 +271,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, rctx request.CTX, ss store.
o1.Id = ""
o1.Name = NewTestId()
o1.Type = model.ChannelTypeOpen
_, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
_, nErr = ss.Channel().SaveDirectChannel(rctx, &o1, &m1, &m2)
require.Error(t, nErr, "Should not be able to save non-direct channel")
// Save yourself Direct Message
@ -279,7 +279,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, rctx request.CTX, ss store.
o1.DisplayName = "Myself"
o1.Name = model.GetDMNameFromIds(NewTestId(), NewTestId())
o1.Type = model.ChannelTypeDirect
_, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m1)
_, nErr = ss.Channel().SaveDirectChannel(rctx, &o1, &m1, &m1)
require.NoError(t, nErr, "couldn't save direct channel", nErr)
members, nErr = ss.Channel().GetMembers(o1.Id, 0, 100)
@ -311,11 +311,11 @@ func testChannelStoreCreateDirectChannel(t *testing.T, rctx request.CTX, ss stor
_, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u2.Id}, -1)
require.NoError(t, nErr)
c1, nErr := ss.Channel().CreateDirectChannel(u1, u2)
c1, nErr := ss.Channel().CreateDirectChannel(rctx, u1, u2)
require.NoError(t, nErr, "couldn't create direct channel", nErr)
defer func() {
ss.Channel().PermanentDeleteMembersByChannel(c1.Id)
ss.Channel().PermanentDelete(c1.Id)
ss.Channel().PermanentDeleteMembersByChannel(rctx, c1.Id)
ss.Channel().PermanentDelete(rctx, c1.Id)
}()
members, nErr := ss.Channel().GetMembers(c1.Id, 0, 100)
@ -344,20 +344,20 @@ func testChannelStoreUpdate(t *testing.T, rctx request.CTX, ss store.Store) {
time.Sleep(100 * time.Millisecond)
_, err := ss.Channel().Update(&o1)
_, err := ss.Channel().Update(rctx, &o1)
require.NoError(t, err, err)
o1.DeleteAt = 100
_, err = ss.Channel().Update(&o1)
_, err = ss.Channel().Update(rctx, &o1)
require.Error(t, err, "update should have failed because channel is archived")
o1.DeleteAt = 0
o1.Id = "missing"
_, err = ss.Channel().Update(&o1)
_, err = ss.Channel().Update(rctx, &o1)
require.Error(t, err, "Update should have failed because of missing key")
o2.Name = o1.Name
_, err = ss.Channel().Update(&o2)
_, err = ss.Channel().Update(rctx, &o2)
require.Error(t, err, "update should have failed because of existing name")
// Make sure that the error correctly reports the wrong field to be Name
@ -468,7 +468,7 @@ func testChannelStoreGet(t *testing.T, rctx request.CTX, ss store.Store, s SqlSt
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
_, nErr = ss.Channel().SaveDirectChannel(&o2, &m1, &m2)
_, nErr = ss.Channel().SaveDirectChannel(rctx, &o2, &m1, &m2)
require.NoError(t, nErr)
c2, err := ss.Channel().Get(o2.Id, false)
@ -582,7 +582,7 @@ func testChannelStoreGetChannelsByIds(t *testing.T, rctx request.CTX, ss store.S
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
_, nErr = ss.Channel().SaveDirectChannel(&o2, &m1, &m2)
_, nErr = ss.Channel().SaveDirectChannel(rctx, &o2, &m1, &m2)
require.NoError(t, nErr)
t.Run("Get 2 existing channels", func(t *testing.T) {
@ -671,7 +671,7 @@ func testGetChannelsWithTeamDataByIds(t *testing.T, rctx request.CTX, ss store.S
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
_, nErr = ss.Channel().SaveDirectChannel(&c2, &m1, &m2)
_, nErr = ss.Channel().SaveDirectChannel(rctx, &c2, &m1, &m2)
require.NoError(t, nErr)
res, err := ss.Channel().GetChannelsWithTeamDataByIds([]string{c1.Id, c2.Id}, false)
@ -804,7 +804,7 @@ func testChannelStoreDelete(t *testing.T, rctx request.CTX, ss store.Store) {
require.NoError(t, nErr)
require.Len(t, list, 1, "invalid number of channels")
cresult := ss.Channel().PermanentDelete(o2.Id)
cresult := ss.Channel().PermanentDelete(rctx, o2.Id)
require.NoError(t, cresult)
list, nErr = ss.Channel().GetChannels(o1.TeamId, m1.UserId, &model.ChannelSearchOpts{
@ -1115,7 +1115,7 @@ func testChannelMemberStore(t *testing.T, rctx request.CTX, ss store.Store) {
require.NoError(t, nErr)
require.EqualValues(t, 2, count, "should have saved 2 members")
nErr = ss.Channel().RemoveMember(o2.ChannelId, o2.UserId)
nErr = ss.Channel().RemoveMember(rctx, o2.ChannelId, o2.UserId)
require.NoError(t, nErr)
count, nErr = ss.Channel().GetMemberCount(o1.ChannelId, false)
@ -1188,7 +1188,7 @@ func testChannelSaveMember(t *testing.T, rctx request.CTX, ss store.Store) {
}
channel, nErr = ss.Channel().Save(channel, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
testCases := []struct {
Name string
@ -1310,7 +1310,7 @@ func testChannelSaveMember(t *testing.T, rctx request.CTX, ss store.Store) {
}
member, nErr = ss.Channel().SaveMember(member)
require.NoError(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u1.Id)
assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
assert.Equal(t, tc.ExpectedSchemeGuest, member.SchemeGuest)
@ -1349,7 +1349,7 @@ func testChannelSaveMember(t *testing.T, rctx request.CTX, ss store.Store) {
}
channel, nErr = ss.Channel().Save(channel, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
testCases := []struct {
Name string
@ -1471,7 +1471,7 @@ func testChannelSaveMember(t *testing.T, rctx request.CTX, ss store.Store) {
}
member, nErr = ss.Channel().SaveMember(member)
require.NoError(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u1.Id)
assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
assert.Equal(t, tc.ExpectedSchemeGuest, member.SchemeGuest)
@ -1509,7 +1509,7 @@ func testChannelSaveMember(t *testing.T, rctx request.CTX, ss store.Store) {
SchemeId: &cs.Id,
}, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
testCases := []struct {
Name string
@ -1631,7 +1631,7 @@ func testChannelSaveMember(t *testing.T, rctx request.CTX, ss store.Store) {
}
member, nErr = ss.Channel().SaveMember(member)
require.NoError(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u1.Id)
assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
assert.Equal(t, tc.ExpectedSchemeGuest, member.SchemeGuest)
@ -1696,7 +1696,7 @@ func testChannelSaveMultipleMembers(t *testing.T, rctx request.CTX, ss store.Sto
}
channel, nErr = ss.Channel().Save(channel, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
testCases := []struct {
Name string
@ -1830,8 +1830,8 @@ func testChannelSaveMultipleMembers(t *testing.T, rctx request.CTX, ss store.Sto
require.NoError(t, nErr)
require.Len(t, members, 2)
member = members[0]
defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(channel.Id, u2.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u1.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u2.Id)
assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
@ -1871,7 +1871,7 @@ func testChannelSaveMultipleMembers(t *testing.T, rctx request.CTX, ss store.Sto
}
channel, nErr = ss.Channel().Save(channel, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
testCases := []struct {
Name string
@ -2005,8 +2005,8 @@ func testChannelSaveMultipleMembers(t *testing.T, rctx request.CTX, ss store.Sto
require.NoError(t, nErr)
require.Len(t, members, 2)
member = members[0]
defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(channel.Id, u2.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u1.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u2.Id)
assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
@ -2045,7 +2045,7 @@ func testChannelSaveMultipleMembers(t *testing.T, rctx request.CTX, ss store.Sto
SchemeId: &cs.Id,
}, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
testCases := []struct {
Name string
@ -2178,8 +2178,8 @@ func testChannelSaveMultipleMembers(t *testing.T, rctx request.CTX, ss store.Sto
require.NoError(t, err)
require.Len(t, members, 2)
member = members[0]
defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(channel.Id, u2.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u1.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u2.Id)
assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
@ -2198,7 +2198,7 @@ func testChannelUpdateMember(t *testing.T, rctx request.CTX, ss store.Store) {
t.Run("not valid channel member", func(t *testing.T) {
member := &model.ChannelMember{ChannelId: "wrong", UserId: u1.Id, NotifyProps: defaultNotifyProps}
_, nErr := ss.Channel().UpdateMember(member)
_, nErr := ss.Channel().UpdateMember(rctx, member)
require.Error(t, nErr)
var appErr *model.AppError
require.True(t, errors.As(nErr, &appErr))
@ -2210,7 +2210,7 @@ func testChannelUpdateMember(t *testing.T, rctx request.CTX, ss store.Store) {
props["property"] = strings.Repeat("Z", model.ChannelMemberNotifyPropsMaxRunes)
member := &model.ChannelMember{ChannelId: model.NewId(), UserId: u1.Id, NotifyProps: props}
_, nErr := ss.Channel().UpdateMember(member)
_, nErr := ss.Channel().UpdateMember(rctx, member)
require.Error(t, nErr)
var appErr *model.AppError
require.ErrorAs(t, nErr, &appErr)
@ -2236,7 +2236,7 @@ func testChannelUpdateMember(t *testing.T, rctx request.CTX, ss store.Store) {
}
channel, nErr = ss.Channel().Save(channel, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
member := &model.ChannelMember{
ChannelId: channel.Id,
@ -2359,7 +2359,7 @@ func testChannelUpdateMember(t *testing.T, rctx request.CTX, ss store.Store) {
member.SchemeUser = tc.SchemeUser
member.SchemeAdmin = tc.SchemeAdmin
member.ExplicitRoles = tc.ExplicitRoles
member, nErr = ss.Channel().UpdateMember(member)
member, nErr = ss.Channel().UpdateMember(rctx, member)
require.NoError(t, nErr)
assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
@ -2399,7 +2399,7 @@ func testChannelUpdateMember(t *testing.T, rctx request.CTX, ss store.Store) {
}
channel, nErr = ss.Channel().Save(channel, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
member := &model.ChannelMember{
ChannelId: channel.Id,
@ -2522,7 +2522,7 @@ func testChannelUpdateMember(t *testing.T, rctx request.CTX, ss store.Store) {
member.SchemeUser = tc.SchemeUser
member.SchemeAdmin = tc.SchemeAdmin
member.ExplicitRoles = tc.ExplicitRoles
member, nErr = ss.Channel().UpdateMember(member)
member, nErr = ss.Channel().UpdateMember(rctx, member)
require.NoError(t, nErr)
assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
@ -2561,7 +2561,7 @@ func testChannelUpdateMember(t *testing.T, rctx request.CTX, ss store.Store) {
SchemeId: &cs.Id,
}, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
member := &model.ChannelMember{
ChannelId: channel.Id,
@ -2684,7 +2684,7 @@ func testChannelUpdateMember(t *testing.T, rctx request.CTX, ss store.Store) {
member.SchemeUser = tc.SchemeUser
member.SchemeAdmin = tc.SchemeAdmin
member.ExplicitRoles = tc.ExplicitRoles
member, nErr = ss.Channel().UpdateMember(member)
member, nErr = ss.Channel().UpdateMember(rctx, member)
require.NoError(t, nErr)
assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
@ -2753,15 +2753,15 @@ func testChannelUpdateMultipleMembers(t *testing.T, rctx request.CTX, ss store.S
}
channel, nErr = ss.Channel().Save(channel, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
member := &model.ChannelMember{ChannelId: channel.Id, UserId: u1.Id, NotifyProps: defaultNotifyProps}
otherMember := &model.ChannelMember{ChannelId: channel.Id, UserId: u2.Id, NotifyProps: defaultNotifyProps}
var members []*model.ChannelMember
members, nErr = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember})
require.NoError(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(channel.Id, u2.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u1.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u2.Id)
require.Len(t, members, 2)
member = members[0]
otherMember = members[1]
@ -2923,15 +2923,15 @@ func testChannelUpdateMultipleMembers(t *testing.T, rctx request.CTX, ss store.S
}
channel, nErr = ss.Channel().Save(channel, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
member := &model.ChannelMember{ChannelId: channel.Id, UserId: u1.Id, NotifyProps: defaultNotifyProps}
otherMember := &model.ChannelMember{ChannelId: channel.Id, UserId: u2.Id, NotifyProps: defaultNotifyProps}
var members []*model.ChannelMember
members, nErr = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember})
require.NoError(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(channel.Id, u2.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u1.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u2.Id)
require.Len(t, members, 2)
member = members[0]
otherMember = members[1]
@ -3092,14 +3092,14 @@ func testChannelUpdateMultipleMembers(t *testing.T, rctx request.CTX, ss store.S
SchemeId: &cs.Id,
}, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
member := &model.ChannelMember{ChannelId: channel.Id, UserId: u1.Id, NotifyProps: defaultNotifyProps}
otherMember := &model.ChannelMember{ChannelId: channel.Id, UserId: u2.Id, NotifyProps: defaultNotifyProps}
members, err := ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember})
require.NoError(t, err)
defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(channel.Id, u2.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u1.Id)
defer ss.Channel().RemoveMember(rctx, channel.Id, u2.Id)
require.Len(t, members, 2)
member = members[0]
otherMember = members[1]
@ -3255,7 +3255,7 @@ func testChannelUpdateMemberNotifyProps(t *testing.T, rctx request.CTX, ss store
}
channel, nErr = ss.Channel().Save(channel, -1)
require.NoError(t, nErr)
defer func() { ss.Channel().PermanentDelete(channel.Id) }()
defer func() { ss.Channel().PermanentDelete(rctx, channel.Id) }()
member := &model.ChannelMember{
ChannelId: channel.Id,
@ -3301,7 +3301,7 @@ func testChannelRemoveMember(t *testing.T, rctx request.CTX, ss store.Store) {
require.NoError(t, nErr)
t.Run("remove member from not existing channel", func(t *testing.T) {
nErr = ss.Channel().RemoveMember("not-existing-channel", u1.Id)
nErr = ss.Channel().RemoveMember(rctx, "not-existing-channel", u1.Id)
require.NoError(t, nErr)
var membersCount int64
membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
@ -3310,7 +3310,7 @@ func testChannelRemoveMember(t *testing.T, rctx request.CTX, ss store.Store) {
})
t.Run("remove not existing member from an existing channel", func(t *testing.T) {
nErr = ss.Channel().RemoveMember(channelID, model.NewId())
nErr = ss.Channel().RemoveMember(rctx, channelID, model.NewId())
require.NoError(t, nErr)
var membersCount int64
membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
@ -3319,7 +3319,7 @@ func testChannelRemoveMember(t *testing.T, rctx request.CTX, ss store.Store) {
})
t.Run("remove existing member from an existing channel", func(t *testing.T) {
nErr = ss.Channel().RemoveMember(channelID, u1.Id)
nErr = ss.Channel().RemoveMember(rctx, channelID, u1.Id)
require.NoError(t, nErr)
defer ss.Channel().SaveMember(m1)
var membersCount int64
@ -3348,7 +3348,7 @@ func testChannelRemoveMembers(t *testing.T, rctx request.CTX, ss store.Store) {
require.NoError(t, nErr)
t.Run("remove members from not existing channel", func(t *testing.T) {
nErr = ss.Channel().RemoveMembers("not-existing-channel", []string{u1.Id, u2.Id, u3.Id, u4.Id})
nErr = ss.Channel().RemoveMembers(rctx, "not-existing-channel", []string{u1.Id, u2.Id, u3.Id, u4.Id})
require.NoError(t, nErr)
var membersCount int64
membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
@ -3357,7 +3357,7 @@ func testChannelRemoveMembers(t *testing.T, rctx request.CTX, ss store.Store) {
})
t.Run("remove not existing members from an existing channel", func(t *testing.T) {
nErr = ss.Channel().RemoveMembers(channelID, []string{model.NewId(), model.NewId()})
nErr = ss.Channel().RemoveMembers(rctx, channelID, []string{model.NewId(), model.NewId()})
require.NoError(t, nErr)
var membersCount int64
membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
@ -3366,7 +3366,7 @@ func testChannelRemoveMembers(t *testing.T, rctx request.CTX, ss store.Store) {
})
t.Run("remove not existing and not existing members from an existing channel", func(t *testing.T) {
nErr = ss.Channel().RemoveMembers(channelID, []string{u1.Id, u2.Id, model.NewId(), model.NewId()})
nErr = ss.Channel().RemoveMembers(rctx, channelID, []string{u1.Id, u2.Id, model.NewId(), model.NewId()})
require.NoError(t, nErr)
defer ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2})
var membersCount int64
@ -3375,7 +3375,7 @@ func testChannelRemoveMembers(t *testing.T, rctx request.CTX, ss store.Store) {
require.Equal(t, int64(2), membersCount)
})
t.Run("remove existing members from an existing channel", func(t *testing.T) {
nErr = ss.Channel().RemoveMembers(channelID, []string{u1.Id, u2.Id, u3.Id})
nErr = ss.Channel().RemoveMembers(rctx, channelID, []string{u1.Id, u2.Id, u3.Id})
require.NoError(t, nErr)
defer ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2, m3})
membersCount, err := ss.Channel().GetMemberCount(channelID, false)
@ -3433,14 +3433,14 @@ func testChannelDeleteMemberStore(t *testing.T, rctx request.CTX, ss store.Store
require.NoError(t, nErr)
require.EqualValues(t, 2, count, "should have saved 2 members")
nErr = ss.Channel().PermanentDeleteMembersByUser(o2.UserId)
nErr = ss.Channel().PermanentDeleteMembersByUser(rctx, o2.UserId)
require.NoError(t, nErr)
count, nErr = ss.Channel().GetMemberCount(o1.ChannelId, false)
require.NoError(t, nErr)
require.EqualValues(t, 1, count, "should have removed 1 member")
nErr = ss.Channel().PermanentDeleteMembersByChannel(o1.ChannelId)
nErr = ss.Channel().PermanentDeleteMembersByChannel(rctx, o1.ChannelId)
require.NoError(t, nErr)
count, nErr = ss.Channel().GetMemberCount(o1.ChannelId, false)
@ -3545,7 +3545,7 @@ func testChannelStoreGetChannels(t *testing.T, rctx request.CTX, ss store.Store)
time.Sleep(time.Millisecond)
now := model.GetMillis()
_, nErr = ss.Channel().Update(o1)
_, nErr = ss.Channel().Update(rctx, o1)
require.NoError(t, nErr)
list, nErr = ss.Channel().GetChannels(o1.TeamId, m1.UserId, &model.ChannelSearchOpts{
@ -3777,7 +3777,7 @@ func testChannelStoreGetAllChannels(t *testing.T, rctx request.CTX, ss store.Sto
u1 := model.User{Id: model.NewId()}
u2 := model.User{Id: model.NewId()}
_, nErr = ss.Channel().CreateDirectChannel(&u1, &u2)
_, nErr = ss.Channel().CreateDirectChannel(rctx, &u1, &u2)
require.NoError(t, nErr)
userIds := []string{model.NewId(), model.NewId(), model.NewId()}
@ -4379,12 +4379,12 @@ func testChannelStoreGetMembersForUser(t *testing.T, rctx request.CTX, ss store.
u2 := model.User{Id: model.NewId()}
u3 := model.User{Id: model.NewId()}
u4 := model.User{Id: model.NewId()}
_, nErr = ss.Channel().CreateDirectChannel(&u1, &user)
_, nErr = ss.Channel().CreateDirectChannel(rctx, &u1, &user)
require.NoError(t, nErr)
_, nErr = ss.Channel().CreateDirectChannel(&u2, &user)
_, nErr = ss.Channel().CreateDirectChannel(rctx, &u2, &user)
require.NoError(t, nErr)
// other user direct message
_, nErr = ss.Channel().CreateDirectChannel(&u3, &u4)
_, nErr = ss.Channel().CreateDirectChannel(rctx, &u3, &u4)
require.NoError(t, nErr)
var members model.ChannelMembers
@ -4828,11 +4828,11 @@ func testUpdateChannelMember(t *testing.T, rctx request.CTX, ss store.Store) {
require.NoError(t, err)
m1.NotifyProps["test"] = "sometext"
_, err = ss.Channel().UpdateMember(m1)
_, err = ss.Channel().UpdateMember(rctx, m1)
require.NoError(t, err, err)
m1.UserId = ""
_, err = ss.Channel().UpdateMember(m1)
_, err = ss.Channel().UpdateMember(rctx, m1)
require.Error(t, err, "bad user id - should fail")
}
@ -5799,7 +5799,7 @@ func testChannelStoreSearchInTeam(t *testing.T, rctx request.CTX, ss store.Store
for _, testCase := range testCases {
t.Run("AutoCompleteInTeam/"+testCase.Description, func(t *testing.T) {
channels, err := ss.Channel().AutocompleteInTeam(testCase.TeamID, testCase.UserID, testCase.Term, testCase.IncludeDeleted, false)
channels, err := ss.Channel().AutocompleteInTeam(rctx, testCase.TeamID, testCase.UserID, testCase.Term, testCase.IncludeDeleted, false)
require.NoError(t, err)
sort.Sort(ByChannelDisplayName(channels))
require.Equal(t, testCase.ExpectedResults, channels)
@ -5960,11 +5960,11 @@ func testAutocomplete(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore
_, err = ss.Team().SaveMember(tm5, -1)
require.NoError(t, err)
err = ss.Channel().RemoveMember(o5.Id, m1.UserId)
err = ss.Channel().RemoveMember(rctx, o5.Id, m1.UserId)
require.NoError(t, err)
tm5.Roles = ""
tm5.DeleteAt = model.GetMillis()
_, err = ss.Team().UpdateMember(tm5)
_, err = ss.Team().UpdateMember(rctx, tm5)
require.NoError(t, err)
testCases := []struct {
@ -5987,7 +5987,7 @@ func testAutocomplete(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore
for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) {
channels, err2 := ss.Channel().Autocomplete(testCase.UserID, testCase.Term, testCase.IncludeDeleted, testCase.IsGuest)
channels, err2 := ss.Channel().Autocomplete(rctx, testCase.UserID, testCase.Term, testCase.IncludeDeleted, testCase.IsGuest)
require.NoError(t, err2)
var gotChannelIds []string
var gotTeamNames []string
@ -6010,7 +6010,7 @@ func testAutocomplete(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore
}, -1)
require.NoError(t, err)
}
channels, err := ss.Channel().Autocomplete(m1.UserId, "Chann", false, false)
channels, err := ss.Channel().Autocomplete(rctx, m1.UserId, "Chann", false, false)
require.NoError(t, err)
assert.Len(t, channels, model.ChannelSearchDefaultLimit)
})
@ -6615,8 +6615,8 @@ func testChannelStoreSearchGroupChannels(t *testing.T, rctx request.CTX, ss stor
defer func() {
for _, gc := range []model.Channel{gc1, gc2, gc3} {
ss.Channel().PermanentDeleteMembersByChannel(gc3.Id)
ss.Channel().PermanentDelete(gc.Id)
ss.Channel().PermanentDeleteMembersByChannel(rctx, gc3.Id)
ss.Channel().PermanentDelete(rctx, gc.Id)
}
}()
@ -6722,11 +6722,11 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, rctx request.CTX, s
_, err = ss.User().Save(u2)
require.NoError(t, err)
d4, nErr := ss.Channel().CreateDirectChannel(u1, u2)
d4, nErr := ss.Channel().CreateDirectChannel(rctx, u1, u2)
require.NoError(t, nErr)
defer func() {
ss.Channel().PermanentDeleteMembersByChannel(d4.Id)
ss.Channel().PermanentDelete(d4.Id)
ss.Channel().PermanentDeleteMembersByChannel(rctx, d4.Id)
ss.Channel().PermanentDelete(rctx, d4.Id)
}()
var openStartCount int64
@ -7220,7 +7220,7 @@ func testMaterializedPublicChannels(t *testing.T, rctx request.CTX, ss store.Sto
require.Equal(t, model.ChannelList{&o1, &o2}, channels)
})
ss.Channel().PermanentDelete(o1.Id)
ss.Channel().PermanentDelete(rctx, o1.Id)
t.Run("o1 no longer listed in public channels when permanently deleted", func(t *testing.T) {
channels, channelErr := ss.Channel().SearchInTeam(teamId, "", true)
@ -7229,7 +7229,7 @@ func testMaterializedPublicChannels(t *testing.T, rctx request.CTX, ss store.Sto
})
o2.Type = model.ChannelTypePrivate
_, err := ss.Channel().Update(&o2)
_, err := ss.Channel().Update(rctx, &o2)
require.NoError(t, err)
t.Run("o2 no longer listed since now private", func(t *testing.T) {
@ -7239,7 +7239,7 @@ func testMaterializedPublicChannels(t *testing.T, rctx request.CTX, ss store.Sto
})
o2.Type = model.ChannelTypeOpen
_, err = ss.Channel().Update(&o2)
_, err = ss.Channel().Update(rctx, &o2)
require.NoError(t, err)
t.Run("o2 listed once again since now public", func(t *testing.T) {
@ -7325,7 +7325,7 @@ func testMaterializedPublicChannels(t *testing.T, rctx request.CTX, ss store.Sto
require.NoError(t, execerr)
o4.DisplayName += " - Modified"
_, err = ss.Channel().Update(&o4)
_, err = ss.Channel().Update(rctx, &o4)
require.NoError(t, err)
t.Run("verify o4 UPDATE converted to INSERT", func(t *testing.T) {
@ -7492,13 +7492,13 @@ func testChannelStoreRemoveAllDeactivatedMembers(t *testing.T, rctx request.CTX,
// Deactivate users 1 & 2.
u1.DeleteAt = model.GetMillis()
u2.DeleteAt = model.GetMillis()
_, err = ss.User().Update(&u1, true)
_, err = ss.User().Update(rctx, &u1, true)
require.NoError(t, err)
_, err = ss.User().Update(&u2, true)
_, err = ss.User().Update(rctx, &u2, true)
require.NoError(t, err)
// Remove all deactivated users from the channel.
assert.NoError(t, ss.Channel().RemoveAllDeactivatedMembers(c1.Id))
assert.NoError(t, ss.Channel().RemoveAllDeactivatedMembers(rctx, c1.Id))
// Get all the channel members. Check there is now only 1: m3.
d2, err := ss.Channel().GetMembers(c1.Id, 0, 1000)
@ -7559,7 +7559,7 @@ func testChannelStoreExportAllDirectChannels(t *testing.T, rctx request.CTX, ss
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
ss.Channel().SaveDirectChannel(rctx, &o1, &m1, &m2)
d1, nErr := ss.Channel().GetAllDirectChannelsForExportAfter(10000, strings.Repeat("0", 26))
assert.NoError(t, nErr)
@ -7622,7 +7622,7 @@ func testChannelStoreExportAllDirectChannelsExcludePrivateAndPublic(t *testing.T
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
ss.Channel().SaveDirectChannel(rctx, &o1, &m1, &m2)
d1, nErr := ss.Channel().GetAllDirectChannelsForExportAfter(10000, strings.Repeat("0", 26))
assert.NoError(t, nErr)
@ -7668,7 +7668,7 @@ func testChannelStoreExportAllDirectChannelsDeletedChannel(t *testing.T, rctx re
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
ss.Channel().SaveDirectChannel(rctx, &o1, &m1, &m2)
o1.DeleteAt = 1
nErr = ss.Channel().SetDeleteAt(o1.Id, 1, 1)
@ -7758,7 +7758,7 @@ func testGroupSyncedChannelCount(t *testing.T, rctx request.CTX, ss store.Store)
}, 999)
require.NoError(t, nErr)
require.True(t, channel1.IsGroupConstrained())
defer ss.Channel().PermanentDelete(channel1.Id)
defer ss.Channel().PermanentDelete(rctx, channel1.Id)
channel2, nErr := ss.Channel().Save(&model.Channel{
DisplayName: model.NewId(),
@ -7767,14 +7767,14 @@ func testGroupSyncedChannelCount(t *testing.T, rctx request.CTX, ss store.Store)
}, 999)
require.NoError(t, nErr)
require.False(t, channel2.IsGroupConstrained())
defer ss.Channel().PermanentDelete(channel2.Id)
defer ss.Channel().PermanentDelete(rctx, channel2.Id)
count, err := ss.Channel().GroupSyncedChannelCount()
require.NoError(t, err)
require.GreaterOrEqual(t, count, int64(1))
channel2.GroupConstrained = model.NewBool(true)
channel2, err = ss.Channel().Update(channel2)
channel2, err = ss.Channel().Update(rctx, channel2)
require.NoError(t, err)
require.True(t, channel2.IsGroupConstrained())
@ -7878,7 +7878,7 @@ func testGetChannelsWithUnreadsAndWithMentions(t *testing.T, rctx request.CTX, s
return o1, m1
}
o1, err := ss.Channel().CreateDirectChannel(&model.User{Id: userId}, &model.User{Id: model.NewId()}, func(channel *model.Channel) {
o1, err := ss.Channel().CreateDirectChannel(rctx, &model.User{Id: userId}, &model.User{Id: model.NewId()}, func(channel *model.Channel) {
channel.TotalMsgCount = 25
channel.LastPostAt = 12345
channel.LastRootPostAt = 12345
@ -7896,7 +7896,7 @@ func testGetChannelsWithUnreadsAndWithMentions(t *testing.T, rctx request.CTX, s
m1.MentionCount = 5
}
m1, err = ss.Channel().UpdateMember(m1)
m1, err = ss.Channel().UpdateMember(rctx, m1)
require.NoError(t, err)
return *o1, *m1

Some files were not shown because too many files have changed in this diff Show More