MM-39058 - invite people to join team and channels (#19849)

* MM-39058-invite-to-team-from-add-channel

* fix tests by validating the memberInvite is not nil

* fix i18n texts

* fix lint problem

* fix translation lines

* fix the data structure

* modify api4-team_local file to match with the expected structure

* fix unit tests, fix translation tests

* remove go routine cause not necesary

* add unit test for invite to team and channel

* remove unnecessary validation

* allow both data structures, simple string array and object with memberInvite struct

* fix texts

* fix linter

* fix problems with graceful invites workflow

* handle error while parsing body

* fix unit tests

* take the address just once

* rename channels to channelIds

* fix unit tests

* add tests and fix local channels invite support

Co-authored-by: Pablo Velez Vidal <pablo.velez@mattermost.com>
Этот коммит содержится в:
Pablo Andrés Vélez Vidal
2022-04-08 12:20:44 -05:00
коммит произвёл GitHub
родитель 0e4b0b6939
Коммит 4b354685e9
16 изменённых файлов: 517 добавлений и 52 удалений

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

@@ -2982,7 +2982,8 @@ func TestInviteUsersToTeam(t *testing.T) {
user1 := th.GenerateTestEmail()
user2 := th.GenerateTestEmail()
emailList := []string{user1, user2}
memberInvite := &model.MemberInvite{Emails: []string{user1, user2}}
emailList := memberInvite.Emails
//Delete all the messages before check the sample email
mail.DeleteMailBox(user1)
@@ -3018,7 +3019,7 @@ func TestInviteUsersToTeam(t *testing.T) {
require.True(t, strings.ContainsAny(resultsMailbox[len(resultsMailbox)-1].To[0], email), "Wrong To recipient")
resultsEmail, err := mail.GetMessageFromMailbox(email, resultsMailbox[len(resultsMailbox)-1].ID)
if err == nil {
require.Equalf(t, resultsEmail.Subject, expectedSubject, "Wrong Subject, actual: %s, expected: %s", resultsEmail.Subject, expectedSubject)
require.Equalf(t, resultsEmail.Subject, expectedSubject, "Wrong Subject, \nactual: %s, \nexpected: %s", resultsEmail.Subject, expectedSubject)
}
}
}
@@ -3034,6 +3035,18 @@ func TestInviteUsersToTeam(t *testing.T) {
"SiteName": th.App.ClientConfig()["SiteName"]})
checkEmail(t, expectedSubject)
// Test the invite to team and channel
mail.DeleteMailBox(user1)
mail.DeleteMailBox(user2)
_, _, err = th.SystemAdminClient.InviteUsersToTeamAndChannelsGracefully(th.BasicTeam.Id, []string{user1, user2}, []string{th.BasicChannel.Id}, "")
require.NoError(t, err)
expectedSubject = i18n.T("api.templates.invite_team_and_channel_subject",
map[string]interface{}{"SenderName": th.SystemAdminUser.GetDisplayName(nameFormat),
"TeamDisplayName": th.BasicTeam.DisplayName,
"ChannelName": th.BasicChannel.DisplayName,
"SiteName": th.App.ClientConfig()["SiteName"]})
checkEmail(t, expectedSubject)
mail.DeleteMailBox(user1)
mail.DeleteMailBox(user2)
_, err = th.LocalClient.InviteUsersToTeam(th.BasicTeam.Id, emailList)
@@ -3044,6 +3057,18 @@ func TestInviteUsersToTeam(t *testing.T) {
"SiteName": th.App.ClientConfig()["SiteName"]})
checkEmail(t, expectedSubject)
// Test the invite local to team and channel
mail.DeleteMailBox(user1)
mail.DeleteMailBox(user2)
_, _, err = th.LocalClient.InviteUsersToTeamAndChannelsGracefully(th.BasicTeam.Id, []string{user1, user2}, []string{th.BasicChannel.Id}, "")
require.NoError(t, err)
expectedSubject = i18n.T("api.templates.invite_team_and_channel_subject",
map[string]interface{}{"SenderName": "Administrator",
"TeamDisplayName": th.BasicTeam.DisplayName,
"ChannelName": th.BasicChannel.DisplayName,
"SiteName": th.App.ClientConfig()["SiteName"]})
checkEmail(t, expectedSubject)
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictCreationToDomains = "@global.com,@common.com" })
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {