Commit 98a06985 authored by Magdalena Frankiewicz's avatar Magdalena Frankiewicz

Skip commit email validation if it is private token

Add test
parent 5b2f000e
......@@ -231,7 +231,7 @@ class User < ApplicationRecord
validates :email, confirmation: true
validates :notification_email, devise_email: true, allow_blank: true, if: ->(user) { user.notification_email != user.email }
validates :public_email, uniqueness: true, devise_email: true, allow_blank: true
validates :commit_email, devise_email: true, allow_blank: true, if: ->(user) { user.commit_email != user.email }
validates :commit_email, devise_email: true, allow_blank: true, if: ->(user) { user.commit_email != user.email && user.commit_email != Gitlab::PrivateCommitEmail::TOKEN }
validates :projects_limit,
presence: true,
numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Gitlab::Database::MAX_INT_VALUE }
......@@ -2005,7 +2005,7 @@ class User < ApplicationRecord
def notification_email_verified
return if notification_email.blank? || temp_oauth_email?
errors.add(:notification_email, _("must be an email you have verified")) unless verified_emails.include?(notification_email)
errors.add(:notification_email, _("must be an email you have verified")) unless verified_emails.include?(notification_email_or_default)
end
def public_email_verified
......@@ -2017,7 +2017,7 @@ class User < ApplicationRecord
def commit_email_verified
return if commit_email.blank?
errors.add(:commit_email, _("must be an email you have verified")) unless verified_emails.include?(commit_email)
errors.add(:commit_email, _("must be an email you have verified")) unless verified_emails.include?(commit_email_or_default)
end
def callout_dismissed?(callout, ignore_dismissal_earlier_than)
......
......@@ -703,6 +703,15 @@ RSpec.describe User do
expect(user).to be_valid
end
end
context 'when commit_email is changed to _private' do
it 'passes user validations' do
user = create(:user)
user.commit_email = '_private'
expect(user).to be_valid
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment