Shared channels auto-share DM & group messages (#26097)

* option for auto inviting plugin to all shared channels.
* auto-invite remotes to shared channels when flag set
Этот коммит содержится в:
Doug Lauder
2024-02-09 10:47:12 -05:00
коммит произвёл GitHub
родитель 7e419e98ee
Коммит 7b7bcff821
28 изменённых файлов: 525 добавлений и 323 удалений

Просмотреть файл

@@ -157,6 +157,8 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
th.App.SetSearchEngine(searchEngine)
}
th.App.Srv().SetLicense(getLicense(enterprise, memoryConfig))
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.MaxUsersPerTeam = 50
*cfg.RateLimitSettings.Enable = false
@@ -186,12 +188,6 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
web.New(th.App.Srv())
wsapi.Init(th.App.Srv())
if enterprise {
th.App.Srv().SetLicense(model.NewTestLicense())
} else {
th.App.Srv().SetLicense(nil)
}
th.Client = th.CreateClient()
th.SystemAdminClient = th.CreateClient()
th.SystemManagerClient = th.CreateClient()
@@ -215,6 +211,16 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
return th
}
func getLicense(enterprise bool, cfg *model.Config) *model.License {
if *cfg.ExperimentalSettings.EnableRemoteClusterService || *cfg.ExperimentalSettings.EnableSharedChannels {
return model.NewTestLicenseSKU(model.LicenseShortSkuProfessional)
}
if enterprise {
return model.NewTestLicense()
}
return nil
}
func SetupEnterprise(tb testing.TB, options ...app.Option) *TestHelper {
if testing.Short() {
tb.SkipNow()
@@ -285,6 +291,7 @@ func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelpe
dbStore := mainHelper.GetStore()
dbStore.DropAllTables()
dbStore.MarkSystemRanUnitTests()
mainHelper.PreloadMigrations()
searchEngine := mainHelper.GetSearchEngine()
th := setupTestHelper(dbStore, searchEngine, false, true, updateConfig, nil)
th.InitLogin()

Просмотреть файл

@@ -15,23 +15,26 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/v8/channels/app"
)
var (
rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
)
func setupForSharedChannels(tb testing.TB) *TestHelper {
return SetupConfig(tb, func(cfg *model.Config) {
*cfg.ExperimentalSettings.EnableRemoteClusterService = true
*cfg.ExperimentalSettings.EnableSharedChannels = true
})
}
func TestGetAllSharedChannels(t *testing.T) {
th := Setup(t).InitBasic()
th := setupForSharedChannels(t).InitBasic()
defer th.TearDown()
const pages = 3
const pageSize = 7
mockService := app.NewMockRemoteClusterService(nil, app.MockOptionRemoteClusterServiceWithActive(true))
th.App.Srv().SetRemoteClusterService(mockService)
savedIds := make([]string, 0, pages*pageSize)
// make some shared channels
@@ -45,6 +48,7 @@ func TestGetAllSharedChannels(t *testing.T) {
CreatorId: th.BasicChannel.CreatorId,
RemoteId: model.NewId(),
}
_, err := th.App.ShareChannel(th.Context, sc)
require.NoError(t, err)
savedIds = append(savedIds, channel.Id)
@@ -96,12 +100,9 @@ func randomBool() bool {
}
func TestGetRemoteClusterById(t *testing.T) {
th := Setup(t).InitBasic()
th := setupForSharedChannels(t).InitBasic()
defer th.TearDown()
mockService := app.NewMockRemoteClusterService(nil, app.MockOptionRemoteClusterServiceWithActive(true))
th.App.Srv().SetRemoteClusterService(mockService)
// for this test we need a user that belongs to a channel that
// is shared with the requested remote id.
@@ -155,7 +156,7 @@ func TestGetRemoteClusterById(t *testing.T) {
func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
t.Run("creates a local DM channel that is shared", func(t *testing.T) {
th := Setup(t).InitBasic()
th := setupForSharedChannels(t).InitBasic()
defer th.TearDown()
client := th.Client
defer client.Logout(context.Background())
@@ -175,16 +176,14 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
})
t.Run("sends a shared channel invitation to the remote", func(t *testing.T) {
th := Setup(t).InitBasic()
th := setupForSharedChannels(t).InitBasic()
defer th.TearDown()
client := th.Client
defer client.Logout(context.Background())
mockService := app.NewMockSharedChannelService(nil, app.MockOptionSharedChannelServiceWithActive(true))
th.App.Srv().SetSharedChannelSyncService(mockService)
localUser := th.BasicUser
remoteUser := th.CreateUser()
rc := &model.RemoteCluster{
Name: "test",
Token: model.NewId(),
@@ -203,21 +202,17 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
channelName := model.GetDMNameFromIds(localUser.Id, remoteUser.Id)
require.Equal(t, channelName, dm.Name, "dm name didn't match")
require.True(t, dm.IsShared())
assert.Equal(t, 1, mockService.NumInvitations())
})
t.Run("does not send a shared channel invitation to the remote when creator is remote", func(t *testing.T) {
th := Setup(t).InitBasic()
th := setupForSharedChannels(t).InitBasic()
defer th.TearDown()
client := th.Client
defer client.Logout(context.Background())
mockService := app.NewMockSharedChannelService(nil, app.MockOptionSharedChannelServiceWithActive(true))
th.App.Srv().SetSharedChannelSyncService(mockService)
localUser := th.BasicUser
remoteUser := th.CreateUser()
rc := &model.RemoteCluster{
Name: "test",
Token: model.NewId(),
@@ -236,7 +231,5 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
channelName := model.GetDMNameFromIds(localUser.Id, remoteUser.Id)
require.Equal(t, channelName, dm.Name, "dm name didn't match")
require.True(t, dm.IsShared())
assert.Zero(t, mockService.NumInvitations())
})
}