]> source.dussan.org Git - redmine.git/commitdiff
Better validation error message when the domain of email is not allowed (#35450).
authorGo MAEDA <maeda@farend.jp>
Wed, 27 Jul 2022 14:05:06 +0000 (14:05 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 27 Jul 2022 14:05:06 +0000 (14:05 +0000)
Patch by  Yuichi HARADA.

git-svn-id: https://svn.redmine.org/redmine/trunk@21739 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/email_address.rb
config/locales/en.yml
test/functional/email_addresses_controller_test.rb

index b4e390679a5bb5b9c66143b584d950aa7958910c..62570e5086a684319809018dacbb626ee7833079 100644 (file)
@@ -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
index 74067d42cce4ef951ee60a66d9ddd78948200dbc..1ce9996cf124b9ef1293a1a9621929194f095110 100644 (file)
@@ -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
 
index b4f631997f87a98eb57d17444799ee9643eb5d7f..17afe321f80145a51057b4f1e50ddc9fb23523bc 100644 (file)
@@ -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