Move cluster, webhub and store out of Server (#20899)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
203df2f537
Коммит
5e69c6b02f
@@ -34,7 +34,6 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/services/searchengine"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
"github.com/mattermost/mattermost-server/v6/store/localcachelayer"
|
||||
"github.com/mattermost/mattermost-server/v6/store/storetest/mocks"
|
||||
"github.com/mattermost/mattermost-server/v6/testlib"
|
||||
"github.com/mattermost/mattermost-server/v6/web"
|
||||
@@ -115,13 +114,7 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
options = append(options, app.ConfigStore(configStore))
|
||||
if includeCache {
|
||||
// Adds the cache layer to the test store
|
||||
options = append(options, app.StoreOverride(func(s *app.Server) store.Store {
|
||||
lcl, err2 := localcachelayer.NewLocalCacheLayer(dbStore, s.GetMetrics(), s.Cluster, s.CacheProvider)
|
||||
if err2 != nil {
|
||||
panic(err2)
|
||||
}
|
||||
return lcl
|
||||
}))
|
||||
options = append(options, app.StoreOverrideWithCache(dbStore))
|
||||
} else {
|
||||
options = append(options, app.StoreOverride(dbStore))
|
||||
}
|
||||
@@ -150,8 +143,8 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
}
|
||||
th.Context.SetLogger(testLogger)
|
||||
|
||||
if s.SearchEngine != nil && s.SearchEngine.BleveEngine != nil && searchEngine != nil {
|
||||
searchEngine.BleveEngine = s.SearchEngine.BleveEngine
|
||||
if s.Platform().SearchEngine != nil && s.Platform().SearchEngine.BleveEngine != nil && searchEngine != nil {
|
||||
searchEngine.BleveEngine = s.Platform().SearchEngine.BleveEngine
|
||||
}
|
||||
|
||||
if searchEngine != nil {
|
||||
@@ -303,7 +296,7 @@ func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config
|
||||
emptyMockStore := mocks.Store{}
|
||||
emptyMockStore.On("Close").Return(nil)
|
||||
emptyMockStore.On("Status").Return(&statusMock)
|
||||
th.App.Srv().Store = &emptyMockStore
|
||||
th.App.Srv().SetStore(&emptyMockStore)
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -317,7 +310,7 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
||||
emptyMockStore := mocks.Store{}
|
||||
emptyMockStore.On("Close").Return(nil)
|
||||
emptyMockStore.On("Status").Return(&statusMock)
|
||||
th.App.Srv().Store = &emptyMockStore
|
||||
th.App.Srv().SetStore(&emptyMockStore)
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -331,7 +324,7 @@ func SetupEnterpriseWithStoreMock(tb testing.TB, options ...app.Option) *TestHel
|
||||
emptyMockStore := mocks.Store{}
|
||||
emptyMockStore.On("Close").Return(nil)
|
||||
emptyMockStore.On("Status").Return(&statusMock)
|
||||
th.App.Srv().Store = &emptyMockStore
|
||||
th.App.Srv().SetStore(&emptyMockStore)
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -587,7 +580,7 @@ func (th *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
|
||||
}
|
||||
|
||||
ruser.Password = "Pa$$word11"
|
||||
_, err = th.App.Srv().Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
_, err = th.App.Srv().Store().User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -773,7 +766,7 @@ func (th *TestHelper) CreateMessagePostWithClient(client *model.Client4, channel
|
||||
}
|
||||
|
||||
func (th *TestHelper) CreateMessagePostNoClient(channel *model.Channel, message string, createAtTime int64) *model.Post {
|
||||
post, err := th.App.Srv().Store.Post().Save(&model.Post{
|
||||
post, err := th.App.Srv().Store().Post().Save(&model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: message,
|
||||
@@ -1157,9 +1150,9 @@ 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 {
|
||||
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(cm); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
@@ -1168,9 +1161,9 @@ 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(context.Background(), team.Id, user.Id); err == nil {
|
||||
if tm, err := th.App.Srv().Store().Team().GetMember(context.Background(), 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(tm); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
@@ -1179,9 +1172,9 @@ 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(context.Background(), team.Id, user.Id); err == nil {
|
||||
if tm, err := th.App.Srv().Store().Team().GetMember(context.Background(), 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(tm); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1168,7 +1168,7 @@ func TestGetAllChannels(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
policyChannel := (sysManagerChannels)[0]
|
||||
policy, err := th.App.Srv().Store.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
policy, err := th.App.Srv().Store().RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
@@ -1661,7 +1661,7 @@ func TestSearchAllChannels(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
policyChannel := sysManagerChannels[0]
|
||||
policy, savePolicyErr := th.App.Srv().Store.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
policy, savePolicyErr := th.App.Srv().Store().RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
@@ -1923,7 +1923,7 @@ func TestDeleteChannel2(t *testing.T) {
|
||||
// successful delete by channel admin
|
||||
th.MakeUserChannelAdmin(user, publicChannel6)
|
||||
th.MakeUserChannelAdmin(user, privateChannel7)
|
||||
th.App.Srv().Store.Channel().ClearCaches()
|
||||
th.App.Srv().Store().Channel().ClearCaches()
|
||||
|
||||
_, err = client.DeleteChannel(publicChannel6.Id)
|
||||
require.NoError(t, err)
|
||||
@@ -4139,17 +4139,17 @@ func TestGetChannelModerations(t *testing.T) {
|
||||
mockSchemeStore := mocks.SchemeStore{}
|
||||
mockSchemeStore.On("Get", mock.Anything).Return(scheme, nil)
|
||||
mockStore.On("Scheme").Return(&mockSchemeStore)
|
||||
mockStore.On("Team").Return(th.App.Srv().Store.Team())
|
||||
mockStore.On("Channel").Return(th.App.Srv().Store.Channel())
|
||||
mockStore.On("User").Return(th.App.Srv().Store.User())
|
||||
mockStore.On("Post").Return(th.App.Srv().Store.Post())
|
||||
mockStore.On("FileInfo").Return(th.App.Srv().Store.FileInfo())
|
||||
mockStore.On("Webhook").Return(th.App.Srv().Store.Webhook())
|
||||
mockStore.On("System").Return(th.App.Srv().Store.System())
|
||||
mockStore.On("License").Return(th.App.Srv().Store.License())
|
||||
mockStore.On("Role").Return(th.App.Srv().Store.Role())
|
||||
mockStore.On("Team").Return(th.App.Srv().Store().Team())
|
||||
mockStore.On("Channel").Return(th.App.Srv().Store().Channel())
|
||||
mockStore.On("User").Return(th.App.Srv().Store().User())
|
||||
mockStore.On("Post").Return(th.App.Srv().Store().Post())
|
||||
mockStore.On("FileInfo").Return(th.App.Srv().Store().FileInfo())
|
||||
mockStore.On("Webhook").Return(th.App.Srv().Store().Webhook())
|
||||
mockStore.On("System").Return(th.App.Srv().Store().System())
|
||||
mockStore.On("License").Return(th.App.Srv().Store().License())
|
||||
mockStore.On("Role").Return(th.App.Srv().Store().Role())
|
||||
mockStore.On("Close").Return(nil)
|
||||
th.App.Srv().Store = &mockStore
|
||||
th.App.Srv().SetStore(&mockStore)
|
||||
|
||||
team.SchemeId = &scheme.Id
|
||||
_, appErr := th.App.UpdateTeamScheme(team)
|
||||
@@ -4283,17 +4283,17 @@ func TestPatchChannelModerations(t *testing.T) {
|
||||
mockSchemeStore.On("Save", mock.Anything).Return(scheme, nil)
|
||||
mockSchemeStore.On("Delete", mock.Anything).Return(scheme, nil)
|
||||
mockStore.On("Scheme").Return(&mockSchemeStore)
|
||||
mockStore.On("Team").Return(th.App.Srv().Store.Team())
|
||||
mockStore.On("Channel").Return(th.App.Srv().Store.Channel())
|
||||
mockStore.On("User").Return(th.App.Srv().Store.User())
|
||||
mockStore.On("Post").Return(th.App.Srv().Store.Post())
|
||||
mockStore.On("FileInfo").Return(th.App.Srv().Store.FileInfo())
|
||||
mockStore.On("Webhook").Return(th.App.Srv().Store.Webhook())
|
||||
mockStore.On("System").Return(th.App.Srv().Store.System())
|
||||
mockStore.On("License").Return(th.App.Srv().Store.License())
|
||||
mockStore.On("Role").Return(th.App.Srv().Store.Role())
|
||||
mockStore.On("Team").Return(th.App.Srv().Store().Team())
|
||||
mockStore.On("Channel").Return(th.App.Srv().Store().Channel())
|
||||
mockStore.On("User").Return(th.App.Srv().Store().User())
|
||||
mockStore.On("Post").Return(th.App.Srv().Store().Post())
|
||||
mockStore.On("FileInfo").Return(th.App.Srv().Store().FileInfo())
|
||||
mockStore.On("Webhook").Return(th.App.Srv().Store().Webhook())
|
||||
mockStore.On("System").Return(th.App.Srv().Store().System())
|
||||
mockStore.On("License").Return(th.App.Srv().Store().License())
|
||||
mockStore.On("Role").Return(th.App.Srv().Store().Role())
|
||||
mockStore.On("Close").Return(nil)
|
||||
th.App.Srv().Store = &mockStore
|
||||
th.App.Srv().SetStore(&mockStore)
|
||||
|
||||
team.SchemeId = &scheme.Id
|
||||
_, appErr := th.App.UpdateTeamScheme(team)
|
||||
@@ -4548,7 +4548,7 @@ func TestRootMentionsCount(t *testing.T) {
|
||||
channel := th.BasicChannel
|
||||
|
||||
// initially, MentionCountRoot is 0 in the database
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(context.Background(), channel.Id, user.Id)
|
||||
channelMember, err := th.App.Srv().Store().Channel().GetMember(context.Background(), channel.Id, user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), channelMember.MentionCountRoot)
|
||||
require.Equal(t, int64(0), channelMember.MentionCount)
|
||||
@@ -4569,7 +4569,7 @@ func TestRootMentionsCount(t *testing.T) {
|
||||
// regular count stays the same
|
||||
require.Equal(t, int64(2), channelUnread.MentionCount)
|
||||
// validate that DB is updated
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channel.Id, user.Id)
|
||||
channelMember, err = th.App.Srv().Store().Channel().GetMember(context.Background(), channel.Id, user.Id)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, int64(1), channelMember.MentionCountRoot)
|
||||
|
||||
|
||||
@@ -297,6 +297,7 @@ func Test_requestTrial(t *testing.T) {
|
||||
require.Equal(t, http.StatusOK, r.StatusCode, "Status OK")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_validateBusinessEmail(t *testing.T) {
|
||||
t.Run("Returns forbidden for non admin executors", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
)
|
||||
@@ -24,12 +25,14 @@ func TestHelpCommand(t *testing.T) {
|
||||
}()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.SupportSettings.HelpLink = "" })
|
||||
rs1, _, _ := client.ExecuteCommand(channel.Id, "/help ")
|
||||
rs1, _, err := client.ExecuteCommand(channel.Id, "/help ")
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, rs1.Text, model.SupportSettingsDefaultHelpLink, "failed to default help link")
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.SupportSettings.HelpLink = "https://docs.mattermost.com/guides/user.html"
|
||||
})
|
||||
rs2, _, _ := client.ExecuteCommand(channel.Id, "/help ")
|
||||
rs2, _, err := client.ExecuteCommand(channel.Id, "/help ")
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, rs2.Text, "https://docs.mattermost.com/guides/user.html", "failed to help link")
|
||||
}
|
||||
|
||||
@@ -239,9 +239,9 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var config map[string]string
|
||||
if c.AppContext.Session().UserId == "" {
|
||||
config = c.App.LimitedClientConfigWithComputed()
|
||||
config = c.App.Srv().Platform().LimitedClientConfigWithComputed()
|
||||
} else {
|
||||
config = c.App.ClientConfigWithComputed()
|
||||
config = c.App.Srv().Platform().ClientConfigWithComputed()
|
||||
}
|
||||
|
||||
w.Write([]byte(model.MapToJSON(config)))
|
||||
|
||||
@@ -542,12 +542,7 @@ func TestUpdateConfigDiffInAuditRecord(t *testing.T) {
|
||||
defer os.Unsetenv("MM_EXPERIMENTALAUDITSETTINGS_FILEENABLED")
|
||||
defer os.Unsetenv("MM_EXPERIMENTALAUDITSETTINGS_FILENAME")
|
||||
|
||||
options := []app.Option{
|
||||
func(s *app.Server) error {
|
||||
s.SetLicense(model.NewTestLicense("advanced_logging"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
options := []app.Option{app.WithLicense(model.NewTestLicense("advanced_logging"))}
|
||||
th := SetupWithServerOptions(t, options)
|
||||
defer th.TearDown()
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ func TestCORSRequestHandling(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
licenseStore := mocks.LicenseStore{}
|
||||
licenseStore.On("Get", "").Return(&model.LicenseRecord{}, nil)
|
||||
th.App.Srv().Store.(*mocks.Store).On("License").Return(&licenseStore)
|
||||
th.App.Srv().Store().(*mocks.Store).On("License").Return(&licenseStore)
|
||||
|
||||
port := th.App.Srv().ListenAddr.Port
|
||||
host := fmt.Sprintf("http://localhost:%v", port)
|
||||
|
||||
@@ -663,7 +663,7 @@ func TestUploadFiles(t *testing.T) {
|
||||
fmt.Sprintf("Wrong clientId returned, expected %v, got %v", tc.clientIds[i], fileResp.ClientIds[i]))
|
||||
}
|
||||
|
||||
dbInfo, err := th.App.Srv().Store.FileInfo().Get(ri.Id)
|
||||
dbInfo, err := th.App.Srv().Store().FileInfo().Get(ri.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, dbInfo.Id, ri.Id, "File id from response should match one stored in database")
|
||||
assert.Equal(t, dbInfo.CreatorId, tc.expectedCreatorId, "F ile should be assigned to user")
|
||||
@@ -912,7 +912,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.BasicUser.Id)
|
||||
err = th.App.Srv().Store().FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = false })
|
||||
@@ -948,7 +948,7 @@ func TestGetFileLink(t *testing.T) {
|
||||
_, _, err = th.SystemAdminClient.GetFileLink(fileId)
|
||||
require.NoError(t, err)
|
||||
|
||||
fileInfo, err := th.App.Srv().Store.FileInfo().Get(fileId)
|
||||
fileInfo, err := th.App.Srv().Store().FileInfo().Get(fileId)
|
||||
require.NoError(t, err)
|
||||
th.cleanupTestFile(fileInfo)
|
||||
}
|
||||
@@ -1070,10 +1070,10 @@ 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.BasicUser.Id)
|
||||
err = th.App.Srv().Store().FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
info, err := th.App.Srv().Store.FileInfo().Get(fileId)
|
||||
info, err := th.App.Srv().Store().FileInfo().Get(fileId)
|
||||
require.NoError(t, err)
|
||||
link := th.App.GeneratePublicLink(client.URL, info)
|
||||
|
||||
@@ -1103,7 +1103,7 @@ func TestGetPublicFile(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode, "should've failed to get image with public link after salt changed")
|
||||
|
||||
fileInfo, err := th.App.Srv().Store.FileInfo().Get(fileId)
|
||||
fileInfo, err := th.App.Srv().Store().FileInfo().Get(fileId)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, th.cleanupTestFile(fileInfo))
|
||||
|
||||
@@ -1135,25 +1135,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.BasicUser.Id)
|
||||
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo1.Id, th.BasicPost.Id, 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.BasicUser.Id)
|
||||
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo2.Id, th.BasicPost.Id, 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.BasicUser.Id)
|
||||
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo3.Id, th.BasicPost.Id, 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.BasicUser.Id)
|
||||
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo4.Id, th.BasicPost.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
archivedChannel := th.CreatePublicChannel()
|
||||
@@ -1162,7 +1162,7 @@ func TestSearchFiles(t *testing.T) {
|
||||
post := &model.Post{ChannelId: archivedChannel.Id, Message: model.NewId() + "a"}
|
||||
rpost, _, err := client.CreatePost(post)
|
||||
require.NoError(t, err)
|
||||
err = th.App.Srv().Store.FileInfo().AttachToPost(fileInfo5.Id, rpost.Id, th.BasicUser.Id)
|
||||
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo5.Id, rpost.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
th.Client.DeleteChannel(archivedChannel.Id)
|
||||
|
||||
|
||||
@@ -938,7 +938,7 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
err error
|
||||
)
|
||||
if c.Params.IncludeTotalCount {
|
||||
totalCount, cerr := c.App.Srv().Store.Group().GroupCount()
|
||||
totalCount, cerr := c.App.Srv().Store().Group().GroupCount()
|
||||
if cerr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroups", "api.custom_groups.count_err", nil, "", http.StatusInternalServerError).Wrap(cerr)
|
||||
return
|
||||
|
||||
@@ -153,7 +153,7 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, userReaction := range userReactions {
|
||||
_, err := th.App.Srv().Store.Reaction().Save(userReaction)
|
||||
_, err := th.App.Srv().Store().Reaction().Save(userReaction)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
EmojiName: "confused",
|
||||
}
|
||||
|
||||
_, err = th.App.Srv().Store.Reaction().Save(reaction)
|
||||
_, err = th.App.Srv().Store().Reaction().Save(reaction)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ func TestGetTopReactionsForUserSince(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, userReaction := range userReactions {
|
||||
_, err := th.App.Srv().Store.Reaction().Save(userReaction)
|
||||
_, err := th.App.Srv().Store().Reaction().Save(userReaction)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -806,7 +806,7 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
_, appErr = th.App.DeletePost(th.Context, replyPostUser2InPrivate.Id, th.BasicUser2.Id)
|
||||
require.Nil(t, appErr)
|
||||
// unfollow thread
|
||||
_, err := th.App.Srv().Store.Thread().MaintainMembership(th.BasicUser2.Id, rootPostPrivateChannel.Id, store.ThreadMembershipOpts{
|
||||
_, err := th.App.Srv().Store().Thread().MaintainMembership(th.BasicUser2.Id, rootPostPrivateChannel.Id, store.ThreadMembershipOpts{
|
||||
Following: false,
|
||||
UpdateFollowing: true,
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestCreateJob(t *testing.T) {
|
||||
t.Run("valid job as user with permissions", func(t *testing.T) {
|
||||
received, _, err := th.SystemAdminClient.CreateJob(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(received.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(received.Id)
|
||||
})
|
||||
|
||||
t.Run("invalid job type as user without permissions", func(t *testing.T) {
|
||||
@@ -54,10 +54,10 @@ func TestGetJob(t *testing.T) {
|
||||
Status: model.JobStatusPending,
|
||||
Type: model.JobTypeMessageExport,
|
||||
}
|
||||
_, err := th.App.Srv().Store.Job().Save(job)
|
||||
_, err := th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
|
||||
received, _, err := th.SystemAdminClient.GetJob(job.Id)
|
||||
require.NoError(t, err)
|
||||
@@ -104,9 +104,9 @@ func TestGetJobs(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv().Store.Job().Save(job)
|
||||
_, err := th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
received, _, err := th.SystemAdminClient.GetJobs(0, 2)
|
||||
@@ -157,9 +157,9 @@ func TestGetJobsByType(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv().Store.Job().Save(job)
|
||||
_, err := th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
received, _, err := th.SystemAdminClient.GetJobsByType(jobType, 0, 2)
|
||||
@@ -226,9 +226,9 @@ func TestDownloadJob(t *testing.T) {
|
||||
|
||||
// Here we have a job that exist in our database but the results do not exist therefore when we try to download the results
|
||||
// as a system admin, we should get a not found status.
|
||||
_, err = th.App.Srv().Store.Job().Save(job)
|
||||
_, err = th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
|
||||
filePath := "./data/export/" + job.Id + "/testdat.txt"
|
||||
mkdirAllErr := os.MkdirAll(filepath.Dir(filePath), 0770)
|
||||
@@ -250,7 +250,7 @@ func TestDownloadJob(t *testing.T) {
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
job.Data["is_downloadable"] = "true"
|
||||
updateStatus, err := th.App.Srv().Store.Job().UpdateOptimistically(job, model.JobStatusSuccess)
|
||||
updateStatus, err := th.App.Srv().Store().Job().UpdateOptimistically(job, model.JobStatusSuccess)
|
||||
require.True(t, updateStatus)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -278,9 +278,9 @@ func TestDownloadJob(t *testing.T) {
|
||||
},
|
||||
Status: model.JobStatusSuccess,
|
||||
}
|
||||
_, err = th.App.Srv().Store.Job().Save(job)
|
||||
_, err = th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
|
||||
// System admin shouldn't be able to download since the job type is not message export
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(job.Id)
|
||||
@@ -312,9 +312,9 @@ func TestCancelJob(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv().Store.Job().Save(job)
|
||||
_, err := th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
resp, err := th.Client.CancelJob(jobs[0].Id)
|
||||
|
||||
@@ -106,7 +106,7 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// skip the restrictions if license is a sanctioned trial
|
||||
if !license.IsSanctionedTrial() && license.IsTrialLicense() {
|
||||
canStartTrialLicense, err := c.App.Srv().LicenseManager.CanStartTrial()
|
||||
canStartTrialLicense, err := c.App.Srv().Platform().LicenseManager().CanStartTrial()
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("addLicense", "api.license.add_license.open.app_error", nil, "", http.StatusInternalServerError)
|
||||
return
|
||||
@@ -180,12 +180,12 @@ func requestTrialLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Srv().LicenseManager == nil {
|
||||
if c.App.Srv().Platform().LicenseManager() == nil {
|
||||
c.Err = model.NewAppError("requestTrialLicense", "api.license.upgrade_needed.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
canStartTrialLicense, err := c.App.Srv().LicenseManager.CanStartTrial()
|
||||
canStartTrialLicense, err := c.App.Srv().Platform().LicenseManager().CanStartTrial()
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("requestTrialLicense", "api.license.request-trial.can-start-trial.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -264,12 +264,12 @@ func requestRenewalLink(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getPrevTrialLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if c.App.Srv().LicenseManager == nil {
|
||||
if c.App.Srv().Platform().LicenseManager() == nil {
|
||||
c.Err = model.NewAppError("getPrevTrialLicense", "api.license.upgrade_needed.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
license, err := c.App.Srv().LicenseManager.GetPrevTrial()
|
||||
license, err := c.App.Srv().Platform().LicenseManager().GetPrevTrial()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app"
|
||||
"github.com/mattermost/mattermost-server/v6/app/platform"
|
||||
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/utils"
|
||||
@@ -117,7 +118,7 @@ func TestUploadLicenseFile(t *testing.T) {
|
||||
|
||||
licenseManagerMock := &mocks.LicenseInterface{}
|
||||
licenseManagerMock.On("CanStartTrial").Return(false, nil).Once()
|
||||
th.App.Srv().LicenseManager = licenseManagerMock
|
||||
th.App.Srv().Platform().SetLicenseManager(licenseManagerMock)
|
||||
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile([]byte("sadasdasdasdasdasdsa"))
|
||||
CheckErrorID(t, err, "api.license.request-trial.can-start-trial.not-allowed")
|
||||
@@ -155,7 +156,7 @@ func TestUploadLicenseFile(t *testing.T) {
|
||||
|
||||
licenseManagerMock := &mocks.LicenseInterface{}
|
||||
licenseManagerMock.On("CanStartTrial").Return(false, nil).Once()
|
||||
th.App.Srv().LicenseManager = licenseManagerMock
|
||||
th.App.Srv().Platform().SetLicenseManager(licenseManagerMock)
|
||||
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile([]byte("sadasdasdasdasdasdsa"))
|
||||
require.NoError(t, err)
|
||||
@@ -202,7 +203,7 @@ func TestRequestTrialLicense(t *testing.T) {
|
||||
|
||||
licenseManagerMock := &mocks.LicenseInterface{}
|
||||
licenseManagerMock.On("CanStartTrial").Return(true, nil)
|
||||
th.App.Srv().LicenseManager = licenseManagerMock
|
||||
th.App.Srv().Platform().SetLicenseManager(licenseManagerMock)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "http://localhost:8065/" })
|
||||
|
||||
@@ -235,7 +236,7 @@ func TestRequestTrialLicense(t *testing.T) {
|
||||
utils.LicenseValidator = &mockLicenseValidator
|
||||
licenseManagerMock := &mocks.LicenseInterface{}
|
||||
licenseManagerMock.On("CanStartTrial").Return(true, nil).Once()
|
||||
th.App.Srv().LicenseManager = licenseManagerMock
|
||||
th.App.Srv().Platform().SetLicenseManager(licenseManagerMock)
|
||||
|
||||
defer func(requestTrialURL string) {
|
||||
app.RequestTrialURL = requestTrialURL
|
||||
@@ -265,19 +266,19 @@ func TestRequestTrialLicense(t *testing.T) {
|
||||
utils.LicenseValidator = &mockLicenseValidator
|
||||
licenseManagerMock := &mocks.LicenseInterface{}
|
||||
licenseManagerMock.On("CanStartTrial").Return(true, nil).Once()
|
||||
th.App.Srv().LicenseManager = licenseManagerMock
|
||||
th.App.Srv().Platform().SetLicenseManager(licenseManagerMock)
|
||||
|
||||
defer func(requestTrialURL string) {
|
||||
app.RequestTrialURL = requestTrialURL
|
||||
}(app.RequestTrialURL)
|
||||
app.RequestTrialURL = testServer.URL
|
||||
platform.RequestTrialURL = requestTrialURL
|
||||
}(platform.RequestTrialURL)
|
||||
platform.RequestTrialURL = testServer.URL
|
||||
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicense(nUsers)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, resp.StatusCode, 451)
|
||||
})
|
||||
|
||||
th.App.Srv().LicenseManager = nil
|
||||
th.App.Srv().Platform().SetLicenseManager(nil)
|
||||
t.Run("trial license should fail if LicenseManager is nil", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicense(1)
|
||||
CheckErrorID(t, err, "api.license.upgrade_needed.app_error")
|
||||
|
||||
@@ -422,7 +422,7 @@ func setFirstAdminVisitMarketplaceStatus(c *Context, w http.ResponseWriter, r *h
|
||||
Value: "true",
|
||||
}
|
||||
|
||||
if err := c.App.Srv().Store.System().SaveOrUpdate(&firstAdminVisitMarketplaceObj); err != nil {
|
||||
if err := c.App.Srv().Store().System().SaveOrUpdate(&firstAdminVisitMarketplaceObj); err != nil {
|
||||
c.Err = model.NewAppError("setFirstAdminVisitMarketplaceStatus", "api.error_set_first_admin_visit_marketplace_status", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -445,7 +445,7 @@ func getFirstAdminVisitMarketplaceStatus(c *Context, w http.ResponseWriter, r *h
|
||||
return
|
||||
}
|
||||
|
||||
firstAdminVisitMarketplaceObj, err := c.App.Srv().Store.System().GetByName(model.SystemFirstAdminVisitMarketplace)
|
||||
firstAdminVisitMarketplaceObj, err := c.App.Srv().Store().System().GetByName(model.SystemFirstAdminVisitMarketplace)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
|
||||
@@ -287,7 +287,7 @@ func TestNotifyClusterPluginEvent(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
testCluster := &testlib.FakeClusterInterface{}
|
||||
th.Server.Cluster = testCluster
|
||||
th.Server.Platform().SetCluster(testCluster)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PluginSettings.Enable = true
|
||||
|
||||
@@ -1480,18 +1480,18 @@ func TestGetFlaggedPostsForUser(t *testing.T) {
|
||||
mockPostStore := mocks.PostStore{}
|
||||
mockPostStore.On("GetFlaggedPosts", mock.AnythingOfType("string"), mock.AnythingOfType("int"), mock.AnythingOfType("int")).Return(nil, errors.New("some-error"))
|
||||
mockPostStore.On("ClearCaches").Return()
|
||||
mockStore.On("Team").Return(th.App.Srv().Store.Team())
|
||||
mockStore.On("Channel").Return(th.App.Srv().Store.Channel())
|
||||
mockStore.On("User").Return(th.App.Srv().Store.User())
|
||||
mockStore.On("Scheme").Return(th.App.Srv().Store.Scheme())
|
||||
mockStore.On("Team").Return(th.App.Srv().Store().Team())
|
||||
mockStore.On("Channel").Return(th.App.Srv().Store().Channel())
|
||||
mockStore.On("User").Return(th.App.Srv().Store().User())
|
||||
mockStore.On("Scheme").Return(th.App.Srv().Store().Scheme())
|
||||
mockStore.On("Post").Return(&mockPostStore)
|
||||
mockStore.On("FileInfo").Return(th.App.Srv().Store.FileInfo())
|
||||
mockStore.On("Webhook").Return(th.App.Srv().Store.Webhook())
|
||||
mockStore.On("System").Return(th.App.Srv().Store.System())
|
||||
mockStore.On("License").Return(th.App.Srv().Store.License())
|
||||
mockStore.On("Role").Return(th.App.Srv().Store.Role())
|
||||
mockStore.On("FileInfo").Return(th.App.Srv().Store().FileInfo())
|
||||
mockStore.On("Webhook").Return(th.App.Srv().Store().Webhook())
|
||||
mockStore.On("System").Return(th.App.Srv().Store().System())
|
||||
mockStore.On("License").Return(th.App.Srv().Store().License())
|
||||
mockStore.On("Role").Return(th.App.Srv().Store().Role())
|
||||
mockStore.On("Close").Return(nil)
|
||||
th.App.Srv().Store = &mockStore
|
||||
th.App.Srv().SetStore(&mockStore)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.GetFlaggedPostsForUser(user.Id, 0, 10)
|
||||
require.Error(t, err)
|
||||
@@ -1898,12 +1898,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
||||
|
||||
// Set channel member's last viewed to 0.
|
||||
// All returned posts are latest posts as if all previous posts were already read by the user.
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
|
||||
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(channelMember)
|
||||
require.NoError(t, err)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, _, err = client.GetPostsAroundLastUnread(userId, channelId, 20, 20, false)
|
||||
require.NoError(t, err)
|
||||
@@ -1919,12 +1919,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
||||
postIdNames[systemPost1.Id] = "system post 1"
|
||||
|
||||
// Set channel member's last viewed before post1.
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
|
||||
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(channelMember)
|
||||
require.NoError(t, err)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, _, err = client.GetPostsAroundLastUnread(userId, channelId, 3, 3, false)
|
||||
require.NoError(t, err)
|
||||
@@ -1943,12 +1943,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
||||
}, posts)
|
||||
|
||||
// Set channel member's last viewed before post6.
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
|
||||
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(channelMember)
|
||||
require.NoError(t, err)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, _, err = client.GetPostsAroundLastUnread(userId, channelId, 3, 3, false)
|
||||
require.NoError(t, err)
|
||||
@@ -1970,12 +1970,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
||||
}, posts)
|
||||
|
||||
// Set channel member's last viewed before post10.
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
|
||||
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(channelMember)
|
||||
require.NoError(t, err)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, _, err = client.GetPostsAroundLastUnread(userId, channelId, 3, 3, false)
|
||||
require.NoError(t, err)
|
||||
@@ -1995,12 +1995,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
||||
}, posts)
|
||||
|
||||
// Set channel member's last viewed equal to post10.
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
|
||||
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(channelMember)
|
||||
require.NoError(t, err)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, _, err = client.GetPostsAroundLastUnread(userId, channelId, 3, 3, false)
|
||||
require.NoError(t, err)
|
||||
@@ -2034,12 +2034,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
||||
postIdNames[post12.Id] = "post12 (reply to post4)"
|
||||
postIdNames[post13.Id] = "post13"
|
||||
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
|
||||
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(channelMember)
|
||||
require.NoError(t, err)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store().Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, _, err = client.GetPostsAroundLastUnread(userId, channelId, 1, 2, false)
|
||||
require.NoError(t, err)
|
||||
@@ -3175,7 +3175,7 @@ func TestCreatePostNotificationsWithCRT(t *testing.T) {
|
||||
}
|
||||
|
||||
// reset the cache so that channel member notify props includes all users
|
||||
th.App.Srv().Store.Channel().ClearCaches()
|
||||
th.App.Srv().Store().Channel().ClearCaches()
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
||||
@@ -229,7 +229,7 @@ func TestGetReactions(t *testing.T) {
|
||||
var reactions []*model.Reaction
|
||||
|
||||
for _, userReaction := range userReactions {
|
||||
reaction, err := th.App.Srv().Store.Reaction().Save(userReaction)
|
||||
reaction, err := th.App.Srv().Store().Reaction().Save(userReaction)
|
||||
require.NoError(t, err)
|
||||
reactions = append(reactions, reaction)
|
||||
}
|
||||
@@ -555,7 +555,7 @@ func TestGetBulkReactions(t *testing.T) {
|
||||
|
||||
for _, userReaction := range userReactions {
|
||||
reactions := expectedPostIdsReactionsMap[userReaction.PostId]
|
||||
reaction, err := th.App.Srv().Store.Reaction().Save(userReaction)
|
||||
reaction, err := th.App.Srv().Store().Reaction().Save(userReaction)
|
||||
require.NoError(t, err)
|
||||
reactions = append(reactions, reaction)
|
||||
expectedPostIdsReactionsMap[userReaction.PostId] = reactions
|
||||
|
||||
@@ -111,9 +111,9 @@ func (r *resolver) Config(ctx context.Context) (model.StringMap, error) {
|
||||
}
|
||||
|
||||
if c.AppContext.Session().UserId == "" {
|
||||
return c.App.LimitedClientConfigWithComputed(), nil
|
||||
return c.App.Srv().Platform().LimitedClientConfigWithComputed(), nil
|
||||
}
|
||||
return c.App.ClientConfigWithComputed(), nil
|
||||
return c.App.Srv().Platform().ClientConfigWithComputed(), nil
|
||||
}
|
||||
|
||||
// match with api4.getClientLicense
|
||||
@@ -212,7 +212,7 @@ func (*resolver) ChannelsLeft(ctx context.Context, args struct {
|
||||
return nil, c.Err
|
||||
}
|
||||
|
||||
return c.App.Srv().Store.ChannelMemberHistory().GetChannelsLeftSince(args.UserID, int64(args.Since))
|
||||
return c.App.Srv().Store().ChannelMemberHistory().GetChannelsLeftSince(args.UserID, int64(args.Since))
|
||||
}
|
||||
|
||||
// match with api4.getChannelMember
|
||||
@@ -296,7 +296,7 @@ func (*resolver) ChannelMembers(ctx context.Context, args struct {
|
||||
LastUpdateAt: int(args.LastUpdateAt),
|
||||
ExcludeTeam: args.ExcludeTeam,
|
||||
}
|
||||
members, err := c.App.Srv().Store.Channel().GetMembersForUserWithCursor(args.UserID, args.TeamID, opts)
|
||||
members, err := c.App.Srv().Store().Channel().GetMembersForUserWithCursor(args.UserID, args.TeamID, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ func postProcessChannels(c *web.Context, channels []*model.Channel) ([]*channel,
|
||||
|
||||
// Avoiding unnecessary queries unless necessary.
|
||||
if len(channelIDs) > 0 {
|
||||
userInfo, err = c.App.Srv().Store.Channel().GetMembersInfoByChannelIds(channelIDs)
|
||||
userInfo, err = c.App.Srv().Store().Channel().GetMembersInfoByChannelIds(channelIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestGetAllRoles(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
roles, err := th.App.Srv().Store.Role().GetAll()
|
||||
roles, err := th.App.Srv().Store().Role().GetAll()
|
||||
require.NoError(t, err)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -49,9 +49,9 @@ func TestGetRole(t *testing.T) {
|
||||
SchemeManaged: true,
|
||||
}
|
||||
|
||||
role, err := th.App.Srv().Store.Role().Save(role)
|
||||
role, err := th.App.Srv().Store().Role().Save(role)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(role.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(role.Id)
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
received, _, err := client.GetRole(role.Id)
|
||||
@@ -88,9 +88,9 @@ func TestGetRoleByName(t *testing.T) {
|
||||
SchemeManaged: true,
|
||||
}
|
||||
|
||||
role, err := th.App.Srv().Store.Role().Save(role)
|
||||
role, err := th.App.Srv().Store().Role().Save(role)
|
||||
assert.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(role.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(role.Id)
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
received, _, err := client.GetRoleByName(role.Name)
|
||||
@@ -141,17 +141,17 @@ func TestGetRolesByNames(t *testing.T) {
|
||||
SchemeManaged: true,
|
||||
}
|
||||
|
||||
role1, err := th.App.Srv().Store.Role().Save(role1)
|
||||
role1, err := th.App.Srv().Store().Role().Save(role1)
|
||||
assert.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(role1.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(role1.Id)
|
||||
|
||||
role2, err = th.App.Srv().Store.Role().Save(role2)
|
||||
role2, err = th.App.Srv().Store().Role().Save(role2)
|
||||
assert.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(role2.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(role2.Id)
|
||||
|
||||
role3, err = th.App.Srv().Store.Role().Save(role3)
|
||||
role3, err = th.App.Srv().Store().Role().Save(role3)
|
||||
assert.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(role3.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(role3.Id)
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
// Check all three roles can be found.
|
||||
@@ -199,9 +199,9 @@ func TestPatchRole(t *testing.T) {
|
||||
SchemeManaged: true,
|
||||
}
|
||||
|
||||
role, err2 := th.App.Srv().Store.Role().Save(role)
|
||||
role, err2 := th.App.Srv().Store().Role().Save(role)
|
||||
assert.NoError(t, err2)
|
||||
defer th.App.Srv().Store.Job().Delete(role.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(role.Id)
|
||||
|
||||
patch := &model.RolePatch{
|
||||
Permissions: &[]string{"manage_system", "create_public_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"},
|
||||
@@ -210,18 +210,18 @@ func TestPatchRole(t *testing.T) {
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
|
||||
// Cannot edit a system admin
|
||||
adminRole, err := th.App.Srv().Store.Role().GetByName(context.Background(), "system_admin")
|
||||
adminRole, err := th.App.Srv().Store().Role().GetByName(context.Background(), "system_admin")
|
||||
assert.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(adminRole.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(adminRole.Id)
|
||||
|
||||
_, resp, err := client.PatchRole(adminRole.Id, patch)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
// Cannot give other roles read / write to system roles or manage roles because only system admin can do these actions
|
||||
systemManager, err := th.App.Srv().Store.Role().GetByName(context.Background(), "system_manager")
|
||||
systemManager, err := th.App.Srv().Store().Role().GetByName(context.Background(), "system_manager")
|
||||
assert.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(systemManager.Id)
|
||||
defer th.App.Srv().Store().Job().Delete(systemManager.Id)
|
||||
|
||||
patchWriteSystemRoles := &model.RolePatch{
|
||||
Permissions: &[]string{model.PermissionSysconsoleWriteUserManagementSystemRoles.Id},
|
||||
@@ -300,7 +300,7 @@ func TestPatchRole(t *testing.T) {
|
||||
license.Features.GuestAccountsPermissions = model.NewBool(false)
|
||||
th.App.Srv().SetLicense(license)
|
||||
|
||||
guestRole, err := th.App.Srv().Store.Role().GetByName(context.Background(), "system_guest")
|
||||
guestRole, err := th.App.Srv().Store().Role().GetByName(context.Background(), "system_guest")
|
||||
require.NoError(t, err)
|
||||
received, resp, err = client.PatchRole(guestRole.Id, patch)
|
||||
require.Error(t, err)
|
||||
@@ -311,7 +311,7 @@ func TestPatchRole(t *testing.T) {
|
||||
license := model.NewTestLicense()
|
||||
license.Features.GuestAccountsPermissions = model.NewBool(true)
|
||||
th.App.Srv().SetLicense(license)
|
||||
guestRole, err := th.App.Srv().Store.Role().GetByName(context.Background(), "system_guest")
|
||||
guestRole, err := th.App.Srv().Store().Role().GetByName(context.Background(), "system_guest")
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.PatchRole(guestRole.Id, patch)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -315,7 +315,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
||||
Type: model.TeamOpen,
|
||||
}
|
||||
|
||||
team1, err = th.App.Srv().Store.Team().Save(team1)
|
||||
team1, err = th.App.Srv().Store().Team().Save(team1)
|
||||
require.NoError(t, err)
|
||||
|
||||
l2, _, err := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
@@ -323,7 +323,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
||||
assert.Zero(t, len(l2))
|
||||
|
||||
team1.SchemeId = &scheme1.Id
|
||||
team1, err = th.App.Srv().Store.Team().Update(team1)
|
||||
team1, err = th.App.Srv().Store().Team().Update(team1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
l3, _, err := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
@@ -337,7 +337,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
||||
Type: model.TeamOpen,
|
||||
SchemeId: &scheme1.Id,
|
||||
}
|
||||
team2, err = th.App.Srv().Store.Team().Save(team2)
|
||||
team2, err = th.App.Srv().Store().Team().Save(team2)
|
||||
require.NoError(t, err)
|
||||
|
||||
l4, _, err := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
@@ -409,7 +409,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
||||
Type: model.ChannelTypeOpen,
|
||||
}
|
||||
|
||||
channel1, errCh := th.App.Srv().Store.Channel().Save(channel1, 1000000)
|
||||
channel1, errCh := th.App.Srv().Store().Channel().Save(channel1, 1000000)
|
||||
assert.NoError(t, errCh)
|
||||
|
||||
l2, _, err := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
@@ -417,7 +417,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(channel1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
l3, _, err := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
@@ -432,7 +432,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
||||
Type: model.ChannelTypeOpen,
|
||||
SchemeId: &scheme1.Id,
|
||||
}
|
||||
channel2, err = th.App.Srv().Store.Channel().Save(channel2, 1000000)
|
||||
channel2, err = th.App.Srv().Store().Channel().Save(channel2, 1000000)
|
||||
assert.NoError(t, err)
|
||||
|
||||
l4, _, err := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
@@ -630,7 +630,7 @@ func TestDeleteScheme(t *testing.T) {
|
||||
assert.Zero(t, role6.DeleteAt)
|
||||
|
||||
// Make sure this scheme is in use by a team.
|
||||
team, err := th.App.Srv().Store.Team().Save(&model.Team{
|
||||
team, err := th.App.Srv().Store().Team().Save(&model.Team{
|
||||
Name: "zz" + model.NewId(),
|
||||
DisplayName: model.NewId(),
|
||||
Email: model.NewId() + "@nowhere.com",
|
||||
@@ -699,7 +699,7 @@ func TestDeleteScheme(t *testing.T) {
|
||||
assert.Zero(t, role6.DeleteAt)
|
||||
|
||||
// Make sure this scheme is in use by a team.
|
||||
channel, err := th.App.Srv().Store.Channel().Save(&model.Channel{
|
||||
channel, err := th.App.Srv().Store().Channel().Save(&model.Channel{
|
||||
TeamId: model.NewId(),
|
||||
DisplayName: model.NewId(),
|
||||
Name: model.NewId(),
|
||||
|
||||
@@ -640,7 +640,7 @@ func setServerBusy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddEventParameter("seconds", i)
|
||||
|
||||
c.App.Srv().Busy.Set(time.Second * time.Duration(i))
|
||||
c.App.Srv().Platform().Busy.Set(time.Second * time.Duration(i))
|
||||
mlog.Warn("server busy state activated - non-critical services disabled", mlog.Int64("seconds", i))
|
||||
|
||||
auditRec.Success()
|
||||
@@ -656,7 +656,7 @@ func clearServerBusy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec := c.MakeAuditRecord("clearServerBusy", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
c.App.Srv().Busy.Clear()
|
||||
c.App.Srv().Platform().Busy.Clear()
|
||||
mlog.Info("server busy state cleared - non-critical services enabled")
|
||||
|
||||
auditRec.Success()
|
||||
@@ -671,7 +671,7 @@ func getServerBusyExpires(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// We call to ToJSON because it actually returns a different struct
|
||||
// along with doing some computations.
|
||||
sbsJSON, jsonErr := c.App.Srv().Busy.ToJSON()
|
||||
sbsJSON, jsonErr := c.App.Srv().Platform().Busy.ToJSON()
|
||||
if jsonErr != nil {
|
||||
mlog.Warn(jsonErr.Error())
|
||||
}
|
||||
|
||||
@@ -684,13 +684,13 @@ func TestSetServerBusy(t *testing.T) {
|
||||
resp, err := th.Client.SetServerBusy(secs)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.False(t, th.App.Srv().Busy.IsBusy(), "server should not be marked busy")
|
||||
require.False(t, th.App.Srv().Platform().Busy.IsBusy(), "server should not be marked busy")
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
_, err := c.SetServerBusy(secs)
|
||||
require.NoError(t, err)
|
||||
require.True(t, th.App.Srv().Busy.IsBusy(), "server should be marked busy")
|
||||
require.True(t, th.App.Srv().Platform().Busy.IsBusy(), "server should be marked busy")
|
||||
}, "as system admin")
|
||||
}
|
||||
|
||||
@@ -704,7 +704,7 @@ func TestSetServerBusyInvalidParam(t *testing.T) {
|
||||
resp, err := c.SetServerBusy(p)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.False(t, th.App.Srv().Busy.IsBusy(), "server should not be marked busy due to invalid param ", p)
|
||||
require.False(t, th.App.Srv().Platform().Busy.IsBusy(), "server should not be marked busy due to invalid param ", p)
|
||||
}
|
||||
}, "as system admin, invalid param")
|
||||
}
|
||||
@@ -713,19 +713,19 @@ func TestClearServerBusy(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
th.App.Srv().Platform().Busy.Set(time.Second * 30)
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := th.Client.ClearServerBusy()
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.True(t, th.App.Srv().Busy.IsBusy(), "server should be marked busy")
|
||||
require.True(t, th.App.Srv().Platform().Busy.IsBusy(), "server should be marked busy")
|
||||
})
|
||||
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
th.App.Srv().Platform().Busy.Set(time.Second * 30)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
_, err := c.ClearServerBusy()
|
||||
require.NoError(t, err)
|
||||
require.False(t, th.App.Srv().Busy.IsBusy(), "server should not be marked busy")
|
||||
require.False(t, th.App.Srv().Platform().Busy.IsBusy(), "server should not be marked busy")
|
||||
}, "as system admin")
|
||||
}
|
||||
|
||||
@@ -733,7 +733,7 @@ func TestGetServerBusy(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
th.App.Srv().Platform().Busy.Set(time.Second * 30)
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GetServerBusy()
|
||||
@@ -753,7 +753,7 @@ func TestServerBusy503(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
th.App.Srv().Platform().Busy.Set(time.Second * 30)
|
||||
|
||||
t.Run("search users while busy", func(t *testing.T) {
|
||||
us := &model.UserSearch{Term: "test"}
|
||||
@@ -783,7 +783,7 @@ func TestServerBusy503(t *testing.T) {
|
||||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
|
||||
th.App.Srv().Busy.Clear()
|
||||
th.App.Srv().Platform().Busy.Clear()
|
||||
|
||||
t.Run("search users while not busy", func(t *testing.T) {
|
||||
us := &model.UserSearch{Term: "test"}
|
||||
|
||||
@@ -118,7 +118,7 @@ func localInviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
auditRec.AddMeta("channels", memberInvite.ChannelIds)
|
||||
}
|
||||
|
||||
team, err := c.App.Srv().Store.Team().Get(c.Params.TeamId)
|
||||
team, err := c.App.Srv().Store().Team().Get(c.Params.TeamId)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -134,7 +134,7 @@ func localInviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
|
||||
var channels []*model.Channel
|
||||
if len(memberInvite.ChannelIds) > 0 {
|
||||
channels, err = c.App.Srv().Store.Channel().GetChannelsByIds(memberInvite.ChannelIds, false)
|
||||
channels, err = c.App.Srv().Store().Channel().GetChannelsByIds(memberInvite.ChannelIds, false)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("prepareLocalInviteNewUsersToTeam", "app.channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
@@ -1155,7 +1155,7 @@ func TestGetAllTeams(t *testing.T) {
|
||||
require.True(t, found)
|
||||
})
|
||||
// Now actually create the policy and assign the team to it
|
||||
policy, savePolicyErr := th.App.Srv().Store.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
policy, savePolicyErr := th.App.Srv().Store().RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
@@ -1469,7 +1469,7 @@ func TestSearchAllTeams(t *testing.T) {
|
||||
CheckOKStatus(t, resp)
|
||||
policyTeam := sysManagerTeams[0]
|
||||
// Now actually create the policy and assign the team to it
|
||||
policy, savePolicyErr := th.App.Srv().Store.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
policy, savePolicyErr := th.App.Srv().Store().RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
@@ -2148,7 +2148,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJSON(map[string]string{"teamId": team.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
|
||||
tm, _, err = client.AddTeamMemberFromInvite(token.Token, "")
|
||||
require.NoError(t, err)
|
||||
@@ -2159,7 +2159,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
|
||||
require.Equal(t, tm.TeamId, team.Id, "team ids should have matched")
|
||||
|
||||
_, err = th.App.Srv().Store.Token().GetByToken(token.Token)
|
||||
_, err = th.App.Srv().Store().Token().GetByToken(token.Token)
|
||||
require.Error(t, err, "The token must be deleted after be used")
|
||||
|
||||
tm, resp, err = client.AddTeamMemberFromInvite("junk", "")
|
||||
@@ -2171,7 +2171,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
// expired token of more than 50 hours
|
||||
token = model.NewToken(app.TokenTypeTeamInvitation, "")
|
||||
token.CreateAt = model.GetMillis() - 1000*60*60*50
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
|
||||
_, resp, err = client.AddTeamMemberFromInvite(token.Token, "")
|
||||
require.Error(t, err)
|
||||
@@ -2184,7 +2184,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJSON(map[string]string{"teamId": testId}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
|
||||
_, resp, err = client.AddTeamMemberFromInvite(token.Token, "")
|
||||
require.Error(t, err)
|
||||
@@ -2229,7 +2229,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJSON(map[string]string{"teamId": team.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
_, _, err = client.AddTeamMemberFromInvite(token.Token, "")
|
||||
CheckErrorID(t, err, "app.team.invite_token.group_constrained.error")
|
||||
|
||||
|
||||
@@ -33,9 +33,9 @@ func TestGetPostsUsage(t *testing.T) {
|
||||
th.CreatePost()
|
||||
}
|
||||
|
||||
total, err := th.Server.Store.Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true})
|
||||
total, err := th.Server.Store().Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true})
|
||||
require.NoError(t, err)
|
||||
usersOnly, err := th.Server.Store.Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true, UsersPostsOnly: true})
|
||||
usersOnly, err := th.Server.Store().Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true, UsersPostsOnly: true})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.GreaterOrEqual(t, usersOnly, int64(14))
|
||||
|
||||
@@ -225,7 +225,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
|
||||
ruser, resp, err := th.Client.CreateUserWithToken(&user, token.Token)
|
||||
require.NoError(t, err)
|
||||
@@ -235,7 +235,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
require.Equal(t, user.Nickname, ruser.Nickname)
|
||||
require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles")
|
||||
CheckUserSanitization(t, ruser)
|
||||
_, err = th.App.Srv().Store.Token().GetByToken(token.Token)
|
||||
_, err = th.App.Srv().Store().Token().GetByToken(token.Token)
|
||||
require.Error(t, err, "The token must be deleted after being used")
|
||||
|
||||
teams, appErr := th.App.GetTeamsForUser(ruser.Id)
|
||||
@@ -250,7 +250,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
|
||||
ruser, resp, err := client.CreateUserWithToken(&user, token.Token)
|
||||
require.NoError(t, err)
|
||||
@@ -260,7 +260,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
require.Equal(t, user.Nickname, ruser.Nickname)
|
||||
require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles")
|
||||
CheckUserSanitization(t, ruser)
|
||||
_, err = th.App.Srv().Store.Token().GetByToken(token.Token)
|
||||
_, err = th.App.Srv().Store().Token().GetByToken(token.Token)
|
||||
require.Error(t, err, "The token must be deleted after being used")
|
||||
|
||||
teams, appErr := th.App.GetTeamsForUser(ruser.Id)
|
||||
@@ -275,7 +275,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
|
||||
_, _, err := th.Client.CreateUserWithToken(&user, "")
|
||||
@@ -292,7 +292,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
token.CreateAt = past49Hours
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
|
||||
_, resp, err := th.Client.CreateUserWithToken(&user, token.Token)
|
||||
@@ -323,7 +323,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = false })
|
||||
@@ -344,7 +344,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = false })
|
||||
@@ -362,7 +362,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
require.NoError(t, th.App.Srv().Store().Token().Save(token))
|
||||
|
||||
enableOpenServer := th.App.Config().TeamSettings.EnableOpenServer
|
||||
defer func() {
|
||||
@@ -379,7 +379,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
require.Equal(t, user.Nickname, ruser.Nickname)
|
||||
require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles")
|
||||
CheckUserSanitization(t, ruser)
|
||||
_, err = th.App.Srv().Store.Token().GetByToken(token.Token)
|
||||
_, err = th.App.Srv().Store().Token().GetByToken(token.Token)
|
||||
require.Error(t, err, "The token must be deleted after be used")
|
||||
})
|
||||
}
|
||||
@@ -1665,7 +1665,7 @@ func TestGetTotalUsersStat(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
total, _ := th.Server.Store.User().Count(model.UserCountOptions{
|
||||
total, _ := th.Server.Store().User().Count(model.UserCountOptions{
|
||||
IncludeDeleted: false,
|
||||
IncludeBotAccounts: true,
|
||||
})
|
||||
@@ -1934,7 +1934,7 @@ func TestUpdateUserAuth(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
|
||||
th.LinkUserToTeam(user, team)
|
||||
_, err := th.App.Srv().Store.User().VerifyEmail(user.Id, user.Email)
|
||||
_, err := th.App.Srv().Store().User().VerifyEmail(user.Id, user.Email)
|
||||
require.NoError(t, err)
|
||||
|
||||
userAuth := &model.UserAuth{}
|
||||
@@ -1967,7 +1967,7 @@ func TestUpdateUserAuth(t *testing.T) {
|
||||
// Regular user can not use endpoint
|
||||
user2 := th.CreateUser()
|
||||
th.LinkUserToTeam(user2, team)
|
||||
_, err = th.App.Srv().Store.User().VerifyEmail(user2.Id, user2.Email)
|
||||
_, err = th.App.Srv().Store().User().VerifyEmail(user2.Id, user2.Email)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.SystemAdminClient.Login(user2.Email, "passwd1")
|
||||
@@ -2100,11 +2100,11 @@ func TestPermanentDeleteAllUsers(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that we have users and posts in the database
|
||||
users, err := th.App.Srv().Store.User().GetAll()
|
||||
users, err := th.App.Srv().Store().User().GetAll()
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, len(users), 0)
|
||||
|
||||
postCount, err := th.App.Srv().Store.Post().AnalyticsPostCount(&model.PostCountOptions{})
|
||||
postCount, err := th.App.Srv().Store().Post().AnalyticsPostCount(&model.PostCountOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, postCount, int64(0))
|
||||
|
||||
@@ -2113,11 +2113,11 @@ func TestPermanentDeleteAllUsers(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check that both user and post tables are empty
|
||||
users, err = th.App.Srv().Store.User().GetAll()
|
||||
users, err = th.App.Srv().Store().User().GetAll()
|
||||
require.NoError(t, err)
|
||||
require.Len(t, users, 0)
|
||||
|
||||
postCount, err = th.App.Srv().Store.Post().AnalyticsPostCount(&model.PostCountOptions{})
|
||||
postCount, err = th.App.Srv().Store().Post().AnalyticsPostCount(&model.PostCountOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, postCount, int64(0))
|
||||
|
||||
@@ -2233,7 +2233,7 @@ func TestUpdateUserActive(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
authData := model.NewId()
|
||||
_, err := th.App.Srv().Store.User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
||||
_, err := th.App.Srv().Store().User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = client.UpdateUserActive(user.Id, false)
|
||||
@@ -2472,7 +2472,7 @@ func TestGetUsersWithoutTeam(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
defer th.App.Srv().Store.User().PermanentDelete(user.Id)
|
||||
defer th.App.Srv().Store().User().PermanentDelete(user.Id)
|
||||
|
||||
user2, _, err := th.Client.CreateUser(&model.User{
|
||||
Username: "a000000001" + model.NewId(),
|
||||
@@ -2480,7 +2480,7 @@ func TestGetUsersWithoutTeam(t *testing.T) {
|
||||
Password: "Password1",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store.User().PermanentDelete(user2.Id)
|
||||
defer th.App.Srv().Store().User().PermanentDelete(user2.Id)
|
||||
|
||||
rusers, _, err := th.SystemAdminClient.GetUsersWithoutTeam(0, 100, "")
|
||||
require.NoError(t, err)
|
||||
@@ -2789,13 +2789,13 @@ func TestUserLoginMFAFlow(t *testing.T) {
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Fake user has MFA enabled
|
||||
err := th.Server.Store.User().UpdateMfaActive(th.BasicUser.Id, true)
|
||||
err := th.Server.Store().User().UpdateMfaActive(th.BasicUser.Id, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = th.Server.Store.User().UpdateMfaActive(th.BasicUser.Id, true)
|
||||
err = th.Server.Store().User().UpdateMfaActive(th.BasicUser.Id, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = th.Server.Store.User().UpdateMfaSecret(th.BasicUser.Id, secret.Secret)
|
||||
err = th.Server.Store().User().UpdateMfaSecret(th.BasicUser.Id, secret.Secret)
|
||||
require.NoError(t, err)
|
||||
|
||||
user, _, err := th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
@@ -2822,10 +2822,10 @@ func TestUserLoginMFAFlow(t *testing.T) {
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Fake user has MFA enabled
|
||||
err := th.Server.Store.User().UpdateMfaActive(th.BasicUser.Id, true)
|
||||
err := th.Server.Store().User().UpdateMfaActive(th.BasicUser.Id, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = th.Server.Store.User().UpdateMfaSecret(th.BasicUser.Id, secret.Secret)
|
||||
err = th.Server.Store().User().UpdateMfaSecret(th.BasicUser.Id, secret.Secret)
|
||||
require.NoError(t, err)
|
||||
|
||||
code := dgoogauth.ComputeCode(secret.Secret, time.Now().UTC().Unix()/30)
|
||||
@@ -3006,7 +3006,7 @@ func TestResetPassword(t *testing.T) {
|
||||
loc += 6
|
||||
recoveryTokenString = resultsEmail.Body.Text[loc : loc+model.TokenSize]
|
||||
}
|
||||
recoveryToken, err := th.App.Srv().Store.Token().GetByToken(recoveryTokenString)
|
||||
recoveryToken, err := th.App.Srv().Store().Token().GetByToken(recoveryTokenString)
|
||||
require.NoError(t, err, "Recovery token not found (%s)", recoveryTokenString)
|
||||
|
||||
resp, err := th.Client.ResetPassword(recoveryToken.Token, "")
|
||||
@@ -3036,7 +3036,7 @@ func TestResetPassword(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
authData := model.NewId()
|
||||
_, err = th.App.Srv().Store.User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
||||
_, err = th.App.Srv().Store().User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
||||
require.NoError(t, err)
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
resp, err = client.SendPasswordResetEmail(user.Email)
|
||||
@@ -3200,10 +3200,10 @@ func TestRevokeSessionsFromAllUsers(t *testing.T) {
|
||||
th.Client.Login(user.Email, user.Password)
|
||||
admin := th.SystemAdminUser
|
||||
th.Client.Login(admin.Email, admin.Password)
|
||||
sessions, err := th.Server.Store.Session().GetSessions(user.Id)
|
||||
sessions, err := th.Server.Store().Session().GetSessions(user.Id)
|
||||
require.NotEmpty(t, sessions)
|
||||
require.NoError(t, err)
|
||||
sessions, err = th.Server.Store.Session().GetSessions(admin.Id)
|
||||
sessions, err = th.Server.Store().Session().GetSessions(admin.Id)
|
||||
require.NotEmpty(t, sessions)
|
||||
require.NoError(t, err)
|
||||
_, err = th.Client.RevokeSessionsFromAllUsers()
|
||||
@@ -3215,11 +3215,11 @@ func TestRevokeSessionsFromAllUsers(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
sessions, err = th.Server.Store.Session().GetSessions(user.Id)
|
||||
sessions, err = th.Server.Store().Session().GetSessions(user.Id)
|
||||
require.Empty(t, sessions)
|
||||
require.NoError(t, err)
|
||||
|
||||
sessions, err = th.Server.Store.Session().GetSessions(admin.Id)
|
||||
sessions, err = th.Server.Store().Session().GetSessions(admin.Id)
|
||||
require.Empty(t, sessions)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -3891,7 +3891,7 @@ func TestSwitchAccount(t *testing.T) {
|
||||
th.LoginBasic()
|
||||
|
||||
fakeAuthData := model.NewId()
|
||||
_, appErr := th.App.Srv().Store.User().UpdateAuthData(th.BasicUser.Id, model.UserAuthServiceGitlab, &fakeAuthData, th.BasicUser.Email, true)
|
||||
_, appErr := th.App.Srv().Store().User().UpdateAuthData(th.BasicUser.Id, model.UserAuthServiceGitlab, &fakeAuthData, th.BasicUser.Email, true)
|
||||
require.NoError(t, appErr)
|
||||
|
||||
sr = &model.SwitchRequest{
|
||||
@@ -4978,7 +4978,7 @@ func TestGetUsersByStatus(t *testing.T) {
|
||||
th.LinkUserToTeam(user, team)
|
||||
th.AddUserToChannel(user, channel)
|
||||
|
||||
th.App.SaveAndBroadcastStatus(&model.Status{
|
||||
th.App.Srv().Platform().SaveAndBroadcastStatus(&model.Status{
|
||||
UserId: user.Id,
|
||||
Status: status,
|
||||
Manual: true,
|
||||
@@ -5169,7 +5169,7 @@ func TestLoginLockout(t *testing.T) {
|
||||
CheckErrorID(t, err, "api.user.check_user_login_attempts.too_many.app_error")
|
||||
|
||||
// Fake user has MFA enabled
|
||||
err = th.Server.Store.User().UpdateMfaActive(th.BasicUser2.Id, true)
|
||||
err = th.Server.Store().User().UpdateMfaActive(th.BasicUser2.Id, true)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.Client.LoginWithMFA(th.BasicUser2.Email, th.BasicUser2.Password, "000000")
|
||||
CheckErrorID(t, err, "api.user.check_user_mfa.bad_code.app_error")
|
||||
@@ -5183,7 +5183,7 @@ func TestLoginLockout(t *testing.T) {
|
||||
CheckErrorID(t, err, "api.user.check_user_login_attempts.too_many.app_error")
|
||||
|
||||
// Fake user has MFA disabled
|
||||
err = th.Server.Store.User().UpdateMfaActive(th.BasicUser2.Id, false)
|
||||
err = th.Server.Store().User().UpdateMfaActive(th.BasicUser2.Id, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
//Check if lock is active
|
||||
@@ -5512,7 +5512,7 @@ func TestPublishUserTyping(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
th.Server.Busy.Set(time.Second * 10)
|
||||
th.Server.Platform().Busy.Set(time.Second * 10)
|
||||
|
||||
t.Run("should return service unavailable for non-system admin user when triggering a typing event and server busy", func(t *testing.T) {
|
||||
resp, err := th.Client.PublishUserTyping("invalid", tr)
|
||||
@@ -5643,7 +5643,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.BasicUser.Id)
|
||||
|
||||
uss, _, err := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{})
|
||||
require.NoError(t, err)
|
||||
@@ -5660,7 +5660,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.BasicUser.Id)
|
||||
|
||||
uss, _, err := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{})
|
||||
require.NoError(t, err)
|
||||
@@ -5679,7 +5679,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.BasicUser.Id)
|
||||
|
||||
uss, _, err := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
Extended: true,
|
||||
@@ -5701,7 +5701,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.BasicUser.Id)
|
||||
|
||||
uss, _, err := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
Deleted: false,
|
||||
@@ -5744,7 +5744,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.BasicUser.Id)
|
||||
|
||||
uss, _, err := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
Deleted: false,
|
||||
@@ -5771,7 +5771,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.BasicUser.Id)
|
||||
|
||||
uss, _, err := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
Deleted: false,
|
||||
@@ -5822,8 +5822,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.BasicUser.Id)
|
||||
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
|
||||
|
||||
uss, _, err := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
Deleted: false,
|
||||
@@ -5858,8 +5858,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.BasicUser.Id)
|
||||
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
|
||||
|
||||
uss, _, err := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
Deleted: false,
|
||||
@@ -5881,7 +5881,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.BasicUser.Id)
|
||||
|
||||
_, resp, err := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
ThreadsOnly: true,
|
||||
@@ -5966,8 +5966,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.BasicUser.Id)
|
||||
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.BasicUser2.Id)
|
||||
|
||||
t.Run("Listed for update event", func(t *testing.T) {
|
||||
var caught bool
|
||||
@@ -6230,7 +6230,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.BasicUser.Id)
|
||||
var uss *model.Threads
|
||||
uss, _, err = th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
Deleted: false,
|
||||
@@ -6332,8 +6332,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.BasicUser.Id)
|
||||
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
|
||||
|
||||
// create a post by regular user
|
||||
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
|
||||
@@ -6389,8 +6389,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.BasicUser.Id)
|
||||
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
|
||||
|
||||
// create a post by regular user
|
||||
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
|
||||
@@ -6409,7 +6409,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(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{
|
||||
@@ -6432,8 +6432,8 @@ func TestSingleThreadGet(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.BasicUser.Id)
|
||||
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
|
||||
|
||||
// create a post by regular user
|
||||
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
|
||||
@@ -6489,8 +6489,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.BasicUser.Id)
|
||||
defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
|
||||
|
||||
// create regular post
|
||||
rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
|
||||
@@ -6545,7 +6545,7 @@ func TestReadThreads(t *testing.T) {
|
||||
_, resp, err = client.CreatePost(&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.BasicUser.Id)
|
||||
|
||||
var uss, uss2 *model.Threads
|
||||
uss, _, err = th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
@@ -6567,8 +6567,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.BasicUser.Id)
|
||||
defer th.App.Srv().Store().Post().PermanentDeleteByUser(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})
|
||||
@@ -6595,8 +6595,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.BasicUser.Id)
|
||||
defer th.App.Srv().Store().Post().PermanentDeleteByUser(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})
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app"
|
||||
"github.com/mattermost/mattermost-server/v6/app/platform"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
@@ -38,7 +38,7 @@ func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// We initialize webconn with all the necessary data.
|
||||
// If the queues are empty, they are initialized in the constructor.
|
||||
cfg := &app.WebConnConfig{
|
||||
cfg := &platform.WebConnConfig{
|
||||
WebSocket: ws,
|
||||
Session: *c.AppContext.Session(),
|
||||
TFunc: c.AppContext.T,
|
||||
@@ -53,7 +53,7 @@ func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg.ConnectionID = model.NewId()
|
||||
// In case of fresh connection id, sequence number is already zero.
|
||||
} else {
|
||||
cfg, err = c.App.PopulateWebConnConfig(c.AppContext.Session(), cfg, r.URL.Query().Get(sequenceNumberParam))
|
||||
cfg, err = c.App.Srv().Platform().PopulateWebConnConfig(c.AppContext.Session(), cfg, r.URL.Query().Get(sequenceNumberParam))
|
||||
if err != nil {
|
||||
mlog.Warn("Error while populating webconn config", mlog.String("id", r.URL.Query().Get(connectionIDParam)), mlog.Err(err))
|
||||
ws.Close()
|
||||
@@ -61,9 +61,9 @@ func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
wc := c.App.NewWebConn(cfg)
|
||||
wc := c.App.Srv().Platform().NewWebConn(cfg, c.App, c.App.Srv().Channels().GetPluginsEnvironment)
|
||||
if c.AppContext.Session().UserId != "" {
|
||||
c.App.HubRegister(wc)
|
||||
c.App.Srv().Platform().HubRegister(wc)
|
||||
}
|
||||
|
||||
wc.Pump()
|
||||
|
||||
@@ -295,14 +295,14 @@ func TestWebSocketStatuses(t *testing.T) {
|
||||
ruser, _, err := client.CreateUser(&user)
|
||||
require.NoError(t, err)
|
||||
th.LinkUserToTeam(ruser, rteam)
|
||||
_, err = th.App.Srv().Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
_, err = th.App.Srv().Store().User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
require.NoError(t, err)
|
||||
|
||||
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser2, _, err := client.CreateUser(&user2)
|
||||
require.NoError(t, err)
|
||||
th.LinkUserToTeam(ruser2, rteam)
|
||||
_, err = th.App.Srv().Store.User().VerifyEmail(ruser2.Id, ruser2.Email)
|
||||
_, err = th.App.Srv().Store().User().VerifyEmail(ruser2.Id, ruser2.Email)
|
||||
require.NoError(t, err)
|
||||
|
||||
client.Login(user.Email, user.Password)
|
||||
|
||||
Ссылка в новой задаче
Block a user