mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[PLT-5639] Show a message when invited addresses are blocked (#6691)
* Show a message when invited addresses are blocked When using the "Send Email Invite" functionality. Emails were sent to domains that were not on the `RestrictCreationToDomains` list. This would lead to users getting a message that they can't create an account if they follow the link in the email. This commit will check the email addresses before the mails are sent and warn the user typing them in which ones are blocked. * Add unit test for domain restrictions on invite * Invite Member: Clear serverError on toggle
This commit is contained in:
committed by
Harrison Healey
parent
976030ea25
commit
227586e09a
33
app/team.go
33
app/team.go
@@ -55,13 +55,8 @@ func CreateTeamWithUser(team *model.Team, userId string) (*model.Team, *model.Ap
|
||||
return rteam, nil
|
||||
}
|
||||
|
||||
func isTeamEmailAllowed(user *model.User) bool {
|
||||
email := strings.ToLower(user.Email)
|
||||
|
||||
if len(user.AuthService) > 0 && len(*user.AuthData) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
func isTeamEmailAddressAllowed(email string) bool {
|
||||
email = strings.ToLower(email)
|
||||
// commas and @ signs are optional
|
||||
// can be in the form of "@corp.mattermost.com, mattermost.com mattermost.org" -> corp.mattermost.com mattermost.com mattermost.org
|
||||
domains := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(utils.Cfg.TeamSettings.RestrictCreationToDomains, "@", " ", -1), ",", " ", -1))))
|
||||
@@ -81,6 +76,16 @@ func isTeamEmailAllowed(user *model.User) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func isTeamEmailAllowed(user *model.User) bool {
|
||||
email := strings.ToLower(user.Email)
|
||||
|
||||
if len(user.AuthService) > 0 && len(*user.AuthData) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return isTeamEmailAddressAllowed(email)
|
||||
}
|
||||
|
||||
func UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
||||
var oldTeam *model.Team
|
||||
var err *model.AppError
|
||||
@@ -621,6 +626,20 @@ func InviteNewUsersToTeam(emailList []string, teamId, senderId string) *model.Ap
|
||||
return err
|
||||
}
|
||||
|
||||
var invalidEmailList []string
|
||||
|
||||
for _, email := range emailList {
|
||||
if ! isTeamEmailAddressAllowed(email) {
|
||||
invalidEmailList = append(invalidEmailList, email)
|
||||
}
|
||||
}
|
||||
|
||||
if len(invalidEmailList) > 0 {
|
||||
s := strings.Join(invalidEmailList, ", ")
|
||||
err := model.NewAppError("InviteNewUsersToTeam", "api.team.invite_members.invalid_email.app_error", map[string]interface{}{"Addresses": s}, "", http.StatusBadRequest)
|
||||
return err
|
||||
}
|
||||
|
||||
tchan := Srv.Store.Team().Get(teamId)
|
||||
uchan := Srv.Store.User().Get(senderId)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user