[MM-27535] User invite limits for MM Cloud (#15197)
* Add a config for MM User Limit * Adding graceful errors for if an administrator invites people passed their user limit * Including changed vendor files * Adding unit test * Fix a bug * Push up working tests (Thanks Joram) * Add more cases, clean up logs in code * One more case * Refactoring based on PR comments * Updating i18n * Some changes based on PR review * Remove a comment * Bring back some translations that were somehow removed Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
17
api4/team.go
17
api4/team.go
@@ -1177,6 +1177,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
emailList := model.ArrayFromJson(r.Body)
|
||||
|
||||
for i := range emailList {
|
||||
emailList[i] = strings.ToLower(emailList[i])
|
||||
}
|
||||
@@ -1193,7 +1194,21 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("emails", emailList)
|
||||
|
||||
if graceful {
|
||||
invitesWithError, err := c.App.InviteNewUsersToTeamGracefully(emailList, c.Params.TeamId, c.App.Session().UserId)
|
||||
cloudUserLimit := *c.App.Config().ExperimentalSettings.CloudUserLimit
|
||||
var invitesOverLimit []*model.EmailInviteWithError
|
||||
if cloudUserLimit > 0 && c.IsSystemAdmin() {
|
||||
emailList, invitesOverLimit, _ = c.App.GetErrorListForEmailsOverLimit(emailList, cloudUserLimit)
|
||||
}
|
||||
var invitesWithError []*model.EmailInviteWithError
|
||||
var err *model.AppError
|
||||
if emailList != nil {
|
||||
invitesWithError, err = c.App.InviteNewUsersToTeamGracefully(emailList, c.Params.TeamId, c.App.Session().UserId)
|
||||
}
|
||||
|
||||
if len(invitesOverLimit) > 0 {
|
||||
invitesWithError = append(invitesWithError, invitesOverLimit...)
|
||||
}
|
||||
|
||||
if invitesWithError != nil {
|
||||
errList := make([]string, 0, len(invitesWithError))
|
||||
for _, inv := range invitesWithError {
|
||||
|
||||
@@ -2721,6 +2721,69 @@ 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 user limit of your current tier")
|
||||
require.NotNil(t, invitesWithErrors[1].Error)
|
||||
assert.Equal(t, invitesWithErrors[1].Error.Message, "You've reached the user limit of your current tier")
|
||||
})
|
||||
|
||||
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 user limit of your current tier")
|
||||
|
||||
})
|
||||
|
||||
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()
|
||||
|
||||
Ссылка в новой задаче
Block a user