[MM-29646] Add check for IsPaidTier, and don't send emails over limit for guest invites (#15958)

* Add check for ispaidtier to email invites

* Add same check for guest emails

* Update api4/team.go

Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org>

* Update api4/team.go

Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org>

* Check for an error and return if there is one

* Fix tests

* Remove test to move to enterprise repo

Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org>
Этот коммит содержится в:
Nick Misasi
2020-10-14 19:44:44 -04:00
коммит произвёл GitHub
родитель 07948ae7bc
Коммит e27a75fba6
2 изменённых файлов: 33 добавлений и 66 удалений

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

@@ -2726,69 +2726,6 @@ func TestImportTeam(t *testing.T) {
})
}
func TestInviteUsersToTeamWithUserLimit(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
email1 := th.GenerateTestEmail()
email2 := th.GenerateTestEmail()
email3 := th.GenerateTestEmail()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.EnableEmailInvitations = true
*cfg.ExperimentalSettings.CloudUserLimit = 2
})
t.Run("System admin, invite when at limit should fail", func(t *testing.T) {
invitesWithErrors, resp := th.SystemAdminClient.InviteUsersToTeamGracefully(th.BasicTeam.Id, []string{email1, email2})
CheckNoError(t, resp)
require.Len(t, invitesWithErrors, 2)
require.NotNil(t, invitesWithErrors[0].Error)
assert.Equal(t, invitesWithErrors[0].Error.Message, "You've reached the free tier user limit")
require.NotNil(t, invitesWithErrors[1].Error)
assert.Equal(t, invitesWithErrors[1].Error.Message, "You've reached the free tier user limit")
})
t.Run("Regular user, invite when at limit should succeed", func(t *testing.T) {
invitesWithErrors, resp := th.Client.InviteUsersToTeamGracefully(th.BasicTeam.Id, []string{email3})
CheckNoError(t, resp)
require.Len(t, invitesWithErrors, 1)
assert.Nil(t, invitesWithErrors[0].Error)
})
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ExperimentalSettings.CloudUserLimit = 5
})
t.Run("With one remaining user inviting more than one user as admin invites only one user", func(t *testing.T) {
invitesWithErrors, resp := th.SystemAdminClient.InviteUsersToTeamGracefully(th.BasicTeam.Id, []string{email1, email2})
CheckNoError(t, resp)
require.Len(t, invitesWithErrors, 2)
require.Nil(t, invitesWithErrors[0].Error)
require.NotNil(t, invitesWithErrors[1].Error)
assert.Equal(t, invitesWithErrors[1].Error.Message, "You've reached the free tier user limit")
})
t.Run("With one remaining user inviting more than one user as a regular user sends all invites", func(t *testing.T) {
invitesWithErrors, resp := th.Client.InviteUsersToTeamGracefully(th.BasicTeam.Id, []string{email1, email2})
CheckNoError(t, resp)
require.Len(t, invitesWithErrors, 2)
assert.Nil(t, invitesWithErrors[0].Error)
assert.Nil(t, invitesWithErrors[1].Error)
})
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ExperimentalSettings.CloudUserLimit = 100
})
t.Run("Invited user count is well below limit", func(t *testing.T) {
invitesWithErrors, resp := th.SystemAdminClient.InviteUsersToTeamGracefully(th.BasicTeam.Id, []string{email1, email2})
CheckNoError(t, resp)
require.Len(t, invitesWithErrors, 2)
require.Nil(t, invitesWithErrors[0].Error)
})
}
func TestInviteUsersToTeam(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()