diff --git a/server/channels/app/slashcommands/command_share.go b/server/channels/app/slashcommands/command_share.go index 91affe307a..3b3d2a4348 100644 --- a/server/channels/app/slashcommands/command_share.go +++ b/server/channels/app/slashcommands/command_share.go @@ -254,7 +254,7 @@ func (sp *ShareProvider) doInviteRemote(a *app.App, c request.CTX, args *model.C } if err = a.InviteRemoteToChannel(args.ChannelId, remoteID, args.UserId, true); err != nil { - return responsef(appErr.Error()) + return responsef(args.T("api.command_share.invite_remote_to_channel.error", map[string]any{"Error": err.Error()})) } return responsef("##### " + args.T("api.command_share.invitation_sent", map[string]any{"Name": rc.DisplayName, "SiteURL": rc.SiteURL})) diff --git a/server/channels/app/slashcommands/command_share_test.go b/server/channels/app/slashcommands/command_share_test.go index c42f7338f9..cbcee62761 100644 --- a/server/channels/app/slashcommands/command_share_test.go +++ b/server/channels/app/slashcommands/command_share_test.go @@ -90,4 +90,42 @@ func TestShareProviderDoCommand(t *testing.T) { }) require.Len(t, channelConvertedMessages, 2) // one msg for share creation, one for unshare. }) + + t.Run("invite remote to channel shared with us", func(t *testing.T) { + th := setupForSharedChannels(t).initBasic() + defer th.tearDown() + + th.addPermissionToRole(model.PermissionManageSharedChannels.Id, th.BasicUser.Roles) + + mockSyncService := app.NewMockSharedChannelService(th.Server.GetSharedChannelSyncService()) + th.Server.SetSharedChannelSyncService(mockSyncService) + + testCluster := &testlib.FakeClusterInterface{} + th.Server.Platform().SetCluster(testCluster) + + remoteCluster, err := th.App.AddRemoteCluster(&model.RemoteCluster{ + RemoteId: model.NewId(), + Name: "remote", + SiteURL: "example.com", + Token: model.NewId(), + Topics: "topic", + CreateAt: model.GetMillis(), + LastPingAt: model.GetMillis(), + CreatorId: model.NewId(), + }) + require.Nil(t, err) + + commandProvider := ShareProvider{} + channel := th.CreateChannel(th.BasicTeam, WithShared(true)) // will create with generated remoteID + args := &model.CommandArgs{ + T: func(s string, args ...any) string { return s }, + ChannelId: channel.Id, + UserId: th.BasicUser.Id, + TeamId: th.BasicTeam.Id, + Command: "/share-channel invite --connectionID " + remoteCluster.RemoteId, + } + + response := commandProvider.DoCommand(th.App, th.Context, args, "") + require.Contains(t, response.Text, args.T("api.command_share.invite_remote_to_channel.error")) + }) } diff --git a/server/i18n/en.json b/server/i18n/en.json index be04380150..4514fdeeec 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -1449,6 +1449,10 @@ "id": "api.command_share.invite_remote.help", "translation": "Invites an external Mattermost instance to the current shared channel" }, + { + "id": "api.command_share.invite_remote_to_channel.error", + "translation": "Cannot invite remote to channel: {{.Error}}" + }, { "id": "api.command_share.missing_action", "translation": "Missing action. Available actions: {{.Actions}}"