summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordigitalMoksha <bwalker@gitlab.com>2017-11-03 18:55:15 +0100
committerdigitalMoksha <bwalker@gitlab.com>2017-11-03 18:55:15 +0100
commit98cb9b5830fa95b98ab99293c815d3cfd18d09c4 (patch)
tree563e8f1d4d38fa3e2177d39ccf98461c15a9d25c
parent4e35b4f5f6002c8854098013580f6aaed83ae1f0 (diff)
downloadgitlab-ce-38680-dont-block-unconfirmed-emails.tar.gz
inform user when adding a duplicate email that38680-dont-block-unconfirmed-emails
commits will get attributed to the other user (the one who registered it first, even if it's not verified) until the email is confirmed
-rw-r--r--app/controllers/profiles/emails_controller.rb4
-rw-r--r--spec/features/profiles/emails_spec.rb22
2 files changed, 23 insertions, 3 deletions
diff --git a/app/controllers/profiles/emails_controller.rb b/app/controllers/profiles/emails_controller.rb
index bbd7ba49d77..f62c0ee43a3 100644
--- a/app/controllers/profiles/emails_controller.rb
+++ b/app/controllers/profiles/emails_controller.rb
@@ -8,8 +8,10 @@ class Profiles::EmailsController < Profiles::ApplicationController
def create
@email = Emails::CreateService.new(current_user, email_params.merge(user: current_user)).execute
- unless @email.errors.blank?
+ if !@email.errors.blank?
flash[:alert] = @email.errors.full_messages.first
+ elsif (user = User.find_by_any_email(@email.email)) != current_user
+ flash[:alert] = "Commits made using this email address will be attributed to user '#{user.username}' until you confirm your ownership"
end
redirect_to profile_emails_url
diff --git a/spec/features/profiles/emails_spec.rb b/spec/features/profiles/emails_spec.rb
index 11cc8aae6f3..fdeb24dc656 100644
--- a/spec/features/profiles/emails_spec.rb
+++ b/spec/features/profiles/emails_spec.rb
@@ -1,7 +1,8 @@
require 'rails_helper'
feature 'Profile > Emails' do
- let(:user) { create(:user) }
+ let(:user) { create(:user) }
+ let(:user2) { create(:user) }
before do
sign_in(user)
@@ -21,34 +22,51 @@ feature 'Profile > Emails' do
expect(page).to have_content('Resend confirmation email')
end
- scenario 'does not add a duplicate email' do
+ scenario 'does not add a duplicate email for the same user' do
fill_in('Email', with: user.email)
click_button('Add email address')
email = user.emails.find_by(email: user.email)
+
expect(email).to be_nil
expect(page).to have_content('Email has already been taken')
end
+
+ scenario 'adds duplicate email and informs user' do
+ user2.emails.create(email: 'my@email.com')
+ fill_in('Email', with: 'my@email.com')
+ click_button('Add email address')
+
+ email = user.emails.find_by(email: user.email)
+
+ expect(email).to be_nil
+ expect(page).to have_content("will be attributed to user '#{user2.username}'")
+ end
end
scenario 'User removes email' do
user.emails.create(email: 'my@email.com')
visit profile_emails_path
+
expect(page).to have_content("my@email.com")
click_link('Remove')
+
expect(page).not_to have_content("my@email.com")
end
scenario 'User confirms email' do
email = user.emails.create(email: 'my@email.com')
visit profile_emails_path
+
expect(page).to have_content("#{email.email} Unverified")
email.confirm
+
expect(email.confirmed?).to be_truthy
visit profile_emails_path
+
expect(page).to have_content("#{email.email} Verified")
end