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 удалений

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

@@ -232,6 +232,8 @@ func (sp *ShareProvider) doInviteRemote(a *app.App, c request.CTX, args *model.C
}
// Check if channel is shared or not.
// TODO: have the share channels service generate the "channel has been shared post" and this section can be removed since
// since `a.InviteRemoteToChannel` will share the channel automatically.
hasChan, err := a.HasSharedChannel(args.ChannelId)
if err != nil {
return responsef(args.T("api.command_share.check_channel_exist.error", map[string]any{"ChannelID": args.ChannelId, "Error": err.Error()}))
@@ -251,7 +253,7 @@ func (sp *ShareProvider) doInviteRemote(a *app.App, c request.CTX, args *model.C
return responsef(args.T("api.command_share.remote_id_invalid.error", map[string]any{"Error": appErr.Error()}))
}
if err = a.InviteRemoteToChannel(args.ChannelId, remoteID, args.UserId); err != nil {
if err = a.InviteRemoteToChannel(args.ChannelId, remoteID, args.UserId, true); err != nil {
return responsef(appErr.Error())
}

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

@@ -12,33 +12,32 @@ import (
"github.com/mattermost/mattermost/server/v8/channels/testlib"
"github.com/mattermost/mattermost/server/v8/channels/app"
"github.com/mattermost/mattermost/server/v8/platform/services/remotecluster"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
)
func setupForSharedChannels(tb testing.TB) *TestHelper {
return setupConfig(tb, func(cfg *model.Config) {
*cfg.ExperimentalSettings.EnableRemoteClusterService = true
*cfg.ExperimentalSettings.EnableSharedChannels = true
})
}
func TestShareProviderDoCommand(t *testing.T) {
t.Run("share command sends a websocket channel converted event", func(t *testing.T) {
th := setup(t).initBasic()
th := setupForSharedChannels(t).initBasic()
defer th.tearDown()
th.addPermissionToRole(model.PermissionManageSharedChannels.Id, th.BasicUser.Roles)
mockSyncService := app.NewMockSharedChannelService(nil, app.MockOptionSharedChannelServiceWithActive(true))
mockSyncService := app.NewMockSharedChannelService(th.Server.GetSharedChannelSyncService())
th.Server.SetSharedChannelSyncService(mockSyncService)
remoteClusterService, err := remotecluster.NewRemoteClusterService(th.Server, th.App)
require.NoError(t, err)
th.Server.SetRemoteClusterService(remoteClusterService)
testCluster := &testlib.FakeClusterInterface{}
th.Server.Platform().SetCluster(testCluster)
err = remoteClusterService.Start()
require.NoError(t, err)
defer remoteClusterService.Shutdown()
commandProvider := ShareProvider{}
channel := th.CreateChannel(th.BasicTeam, WithShared(false))
@@ -61,24 +60,17 @@ func TestShareProviderDoCommand(t *testing.T) {
})
t.Run("unshare command sends a websocket channel converted event", func(t *testing.T) {
th := setup(t).initBasic()
th := setupForSharedChannels(t).initBasic()
defer th.tearDown()
th.addPermissionToRole(model.PermissionManageSharedChannels.Id, th.BasicUser.Roles)
mockSyncService := app.NewMockSharedChannelService(nil)
mockSyncService := app.NewMockSharedChannelService(th.Server.GetSharedChannelSyncService())
th.Server.SetSharedChannelSyncService(mockSyncService)
remoteClusterService, err := remotecluster.NewRemoteClusterService(th.Server, th.App)
require.NoError(t, err)
th.Server.SetRemoteClusterService(remoteClusterService)
testCluster := &testlib.FakeClusterInterface{}
th.Server.Platform().SetCluster(testCluster)
err = remoteClusterService.Start()
require.NoError(t, err)
defer remoteClusterService.Shutdown()
commandProvider := ShareProvider{}
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
args := &model.CommandArgs{

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

@@ -92,6 +92,18 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
IncludeCacheLayer: includeCacheLayer,
}
if enterprise {
th.App.Srv().Jobs.StopWorkers()
th.App.Srv().Jobs.StopSchedulers()
th.App.Srv().SetLicense(model.NewTestLicense())
th.App.Srv().Jobs.StartWorkers()
th.App.Srv().Jobs.StartSchedulers()
} else {
th.App.Srv().SetLicense(getLicense(false, memoryConfig))
}
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
@@ -118,18 +130,6 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
*cfg.PasswordSettings.Number = false
})
if enterprise {
th.App.Srv().Jobs.StopWorkers()
th.App.Srv().Jobs.StopSchedulers()
th.App.Srv().SetLicense(model.NewTestLicense())
th.App.Srv().Jobs.StartWorkers()
th.App.Srv().Jobs.StartSchedulers()
} else {
th.App.Srv().SetLicense(nil)
}
if th.tempWorkspace == "" {
th.tempWorkspace = tempWorkspace
}
@@ -137,6 +137,16 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
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 setup(tb testing.TB) *TestHelper {
if testing.Short() {
tb.SkipNow()
@@ -148,6 +158,17 @@ func setup(tb testing.TB) *TestHelper {
return setupTestHelper(dbStore, false, true, tb, nil)
}
func setupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper {
if testing.Short() {
tb.SkipNow()
}
dbStore := mainHelper.GetStore()
dbStore.DropAllTables()
dbStore.MarkSystemRanUnitTests()
return setupTestHelper(dbStore, false, true, tb, updateConfig)
}
var initBasicOnce sync.Once
var userCache struct {
SystemAdminUser *model.User