diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-02-12 09:09:23 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-02-12 09:09:23 +0000 |
commit | 2afd95a02520f929773990f78fdf209afc829636 (patch) | |
tree | 8535bae3b4446cf21beb461e21983455dc09d319 /app | |
parent | 0807bd51308c9f56b914a0a6a3655806d92835a9 (diff) | |
parent | b3635ee46a1e62d72ce84871e2a5984e6eabfbdf (diff) | |
download | gitlab-ce-2afd95a02520f929773990f78fdf209afc829636.tar.gz |
Merge branch 'streamline-email-validation' into 'master'
Validate email addresses using Devise.email_regexp
Also:
- Get rid of legacy `:strict_mode`
- Get rid of custom `:email` validator
- Add some shared examples to spec emails validation
This supersedes !2754 and fixes #3851.
See merge request !2771
Diffstat (limited to 'app')
-rw-r--r-- | app/models/application_setting.rb | 4 | ||||
-rw-r--r-- | app/models/email.rb | 2 | ||||
-rw-r--r-- | app/models/member.rb | 1 | ||||
-rw-r--r-- | app/models/user.rb | 7 | ||||
-rw-r--r-- | app/validators/email_validator.rb | 15 |
5 files changed, 6 insertions, 23 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index fa48fe5b9e4..269056e0e77 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -71,8 +71,8 @@ class ApplicationSetting < ActiveRecord::Base url: true validates :admin_notification_email, - allow_blank: true, - email: true + email: true, + allow_blank: true validates :two_factor_grace_period, numericality: { greater_than_or_equal_to: 0 } diff --git a/app/models/email.rb b/app/models/email.rb index 935705e2ed4..b323d1edd10 100644 --- a/app/models/email.rb +++ b/app/models/email.rb @@ -15,7 +15,7 @@ class Email < ActiveRecord::Base belongs_to :user validates :user_id, presence: true - validates :email, presence: true, email: { strict_mode: true }, uniqueness: true + validates :email, presence: true, uniqueness: true, email: true validate :unique_email, if: ->(email) { email.email_changed? } before_validation :cleanup_email diff --git a/app/models/member.rb b/app/models/member.rb index 34efcd0088d..ca08007b7eb 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -39,7 +39,6 @@ class Member < ActiveRecord::Base if: :invite? }, email: { - strict_mode: true, allow_nil: true }, uniqueness: { diff --git a/app/models/user.rb b/app/models/user.rb index 234c1cd89f9..9fe94b13e52 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -146,11 +146,8 @@ class User < ActiveRecord::Base # Validations # validates :name, presence: true - # Note that a 'uniqueness' and presence check is provided by devise :validatable for email. We do not need to - # duplicate that here as the validation framework will have duplicate errors in the event of a failure. - validates :email, presence: true, email: { strict_mode: true } - validates :notification_email, presence: true, email: { strict_mode: true } - validates :public_email, presence: true, email: { strict_mode: true }, allow_blank: true, uniqueness: true + validates :notification_email, presence: true, email: true + validates :public_email, presence: true, uniqueness: true, email: true, allow_blank: true validates :bio, length: { maximum: 255 }, allow_blank: true validates :projects_limit, presence: true, numericality: { greater_than_or_equal_to: 0 } validates :username, diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb index b35af100803..aab07a7ece4 100644 --- a/app/validators/email_validator.rb +++ b/app/validators/email_validator.rb @@ -1,18 +1,5 @@ -# EmailValidator -# -# Based on https://github.com/balexand/email_validator -# -# Extended to use only strict mode with following allowed characters: -# ' - apostrophe -# -# See http://www.remote.org/jochen/mail/info/chars.html -# class EmailValidator < ActiveModel::EachValidator - PATTERN = /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i.freeze - def validate_each(record, attribute, value) - unless value =~ PATTERN - record.errors.add(attribute, options[:message] || :invalid) - end + record.errors.add(attribute, :invalid) unless value =~ Devise.email_regexp end end |