diff --git a/app/team.go b/app/team.go index cfb39d7cc4..688f243524 100644 --- a/app/team.go +++ b/app/team.go @@ -89,6 +89,9 @@ func (a *App) isTeamEmailAddressAllowed(email string, allowedDomains string) boo } func (a *App) isTeamEmailAllowed(user *model.User, team *model.Team) bool { + if user.IsBot { + return true + } email := strings.ToLower(user.Email) return a.isTeamEmailAddressAllowed(email, team.AllowedDomains) } diff --git a/app/team_test.go b/app/team_test.go index 88280cdce6..159c0fd61c 100644 --- a/app/team_test.go +++ b/app/team_test.go @@ -105,7 +105,7 @@ func TestAddUserToTeam(t *testing.T) { } }) - t.Run("block user by domain", func(t *testing.T) { + t.Run("block user by domain but allow bot", func(t *testing.T) { th.BasicTeam.AllowedDomains = "example.com" if _, err := th.App.UpdateTeam(th.BasicTeam); err != nil { t.Log(err) @@ -131,10 +131,20 @@ func TestAddUserToTeam(t *testing.T) { } defer th.App.PermanentDeleteUser(&user) - if _, err := th.App.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err == nil || err.Where != "JoinUserToTeam" { + if _, err = th.App.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err == nil || err.Where != "JoinUserToTeam" { t.Log(err) t.Fatal("Should not add authservice user") } + + bot, err := th.App.CreateBot(&model.Bot{ + Username: "somebot", + Description: "a bot", + OwnerId: th.BasicUser.Id, + }) + require.Nil(t, err) + + _, err = th.App.AddUserToTeam(th.BasicTeam.Id, bot.UserId, "") + assert.Nil(t, err, "should be able to add bot to domain restricted team") }) t.Run("block user with subdomain", func(t *testing.T) {