diff --git a/app/models/email_address.rb b/app/models/email_address.rb index b4e390679..62570e508 100644 --- a/app/models/email_address.rb +++ b/app/models/email_address.rb @@ -143,6 +143,14 @@ class EmailAddress < ActiveRecord::Base end def validate_email_domain - errors.add(:address, :invalid) unless self.class.valid_domain?(address) + domain = address.partition('@').last + return if self.class.valid_domain?(domain) + + if User.current.logged? + errors.add(:address, :domain_not_allowed, :domain => domain) + else + # Don't display a detailed error message for anonymous users + errors.add(:address, :invalid) + end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 74067d42c..1ce9996cf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -136,6 +136,7 @@ en: must_contain_lowercase: "must contain lowercase letters (a-z)" must_contain_digits: "must contain digits (0-9)" must_contain_special_chars: "must contain special characters (!, $, %, ...)" + domain_not_allowed: "contains a domain not allowed (%{domain})" actionview_instancetag_blank_option: Please select diff --git a/test/functional/email_addresses_controller_test.rb b/test/functional/email_addresses_controller_test.rb index b4f631997..17afe321f 100644 --- a/test/functional/email_addresses_controller_test.rb +++ b/test/functional/email_addresses_controller_test.rb @@ -131,7 +131,7 @@ class EmailAddressesControllerTest < Redmine::ControllerTest } ) assert_response :success - assert_select_error 'Email is invalid' + assert_select_error 'Email contains a domain not allowed (black.example)' end end @@ -147,7 +147,7 @@ class EmailAddressesControllerTest < Redmine::ControllerTest } ) assert_response :success - assert_select_error 'Email is invalid' + assert_select_error 'Email contains a domain not allowed (example.fr)' end end end