mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:52:11 +08:00
FEATURE: the hide_email_address_taken setting works with the change email address form in user preferences
This commit is contained in:
parent
abdb334823
commit
c29334cf23
|
@ -2660,11 +2660,11 @@ en:
|
|||
title: "Account already exists"
|
||||
subject_template: "[%{email_prefix}] Account already exists"
|
||||
text_body_template: |
|
||||
You just tried to create an account at %{site_name}. However, an account already exists for %{email}.
|
||||
You just tried to create an account at %{site_name}, or tried to change the email of an account to %{email}. However, an account already exists for %{email}.
|
||||
|
||||
If you forgot your password, [reset it now](%{base_url}/password-reset).
|
||||
|
||||
If you didn’t try to create an account for %{email}, don’t worry – you can safely ignore this message.
|
||||
If you didn’t try to create an account for %{email} or change your email address, don’t worry – you can safely ignore this message.
|
||||
|
||||
If you have any questions, [contact our friendly staff](%{base_url}/about).
|
||||
|
||||
|
|
|
@ -27,12 +27,16 @@ class EmailUpdater
|
|||
EmailValidator.new(attributes: :email).validate_each(self, :email, email)
|
||||
|
||||
if existing_user = User.find_by_email(email)
|
||||
if SiteSetting.hide_email_address_taken
|
||||
Jobs.enqueue(:critical_user_email, type: :account_exists, user_id: existing_user.id)
|
||||
else
|
||||
error_message = 'change_email.error'
|
||||
error_message << '_staged' if existing_user.staged?
|
||||
errors.add(:base, I18n.t(error_message))
|
||||
end
|
||||
end
|
||||
|
||||
if errors.blank?
|
||||
if errors.blank? && existing_user.nil?
|
||||
args = {
|
||||
old_email: @user.email,
|
||||
new_email: email,
|
||||
|
|
|
@ -131,4 +131,25 @@ describe EmailUpdater do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'hide_email_address_taken is enabled' do
|
||||
before do
|
||||
SiteSetting.hide_email_address_taken = true
|
||||
end
|
||||
|
||||
let(:user) { Fabricate(:user, email: old_email) }
|
||||
let(:existing) { Fabricate(:user, email: new_email) }
|
||||
let(:updater) { EmailUpdater.new(user.guardian, user) }
|
||||
|
||||
it "doesn't error if user exists with new email" do
|
||||
updater.change_to(existing.email)
|
||||
expect(updater.errors).to be_blank
|
||||
expect(user.email_change_requests).to be_empty
|
||||
end
|
||||
|
||||
it 'sends an email to the owner of the account with the new email' do
|
||||
Jobs.expects(:enqueue).once.with(:critical_user_email, has_entries(type: :account_exists, user_id: existing.id))
|
||||
updater.change_to(existing.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -96,6 +96,11 @@ describe UsersEmailController do
|
|||
context 'when the new email address is taken' do
|
||||
let!(:other_user) { Fabricate(:coding_horror) }
|
||||
|
||||
context 'hide_email_address_taken is disabled' do
|
||||
before do
|
||||
SiteSetting.hide_email_address_taken = false
|
||||
end
|
||||
|
||||
it 'raises an error' do
|
||||
put "/u/#{user.username}/preferences/email.json", params: {
|
||||
email: other_user.email
|
||||
|
@ -113,6 +118,21 @@ describe UsersEmailController do
|
|||
end
|
||||
end
|
||||
|
||||
context 'hide_email_address_taken is enabled' do
|
||||
before do
|
||||
SiteSetting.hide_email_address_taken = true
|
||||
end
|
||||
|
||||
it 'responds with success' do
|
||||
put "/u/#{user.username}/preferences/email.json", params: {
|
||||
email: other_user.email
|
||||
}
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when new email is different case of existing email' do
|
||||
let!(:other_user) { Fabricate(:user, email: 'case.insensitive@gmail.com') }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user