A platform for community discussion. Free, open, simple.
FIX: send email to normalized email owner when hiding emails (#23524)
Samb3bef96744a8
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex ba705c123bf..d1c6b6ca010 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -767,7 +767,12 @@ class UsersController < ApplicationControlleruser.errors[:primary_email]&.include?(I18n.t("errors.messages.taken"))session["user_created_message"] = activation.success_message- if existing_user = User.find_by_email(user.primary_email&.email)+ existing_user = User.find_by_email(user.primary_email&.email)+ if !existing_user && SiteSetting.normalize_emails+ existing_user =+ UserEmail.find_by_normalized_email(user.primary_email&.normalized_email)&.user+ end+ if existing_userJobs.enqueue(:critical_user_email, type: "account_exists", user_id: existing_user.id)enddiff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex 410e9b1542f..4ddad06890c 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -834,6 +834,46 @@ RSpec.describe UsersController doendend+ context "when normalize_emails is enabled" do+ let (:email) {+ }+ let (:dupe_email) {+ }+ let! (:user) {+ Fabricate(:user, email: email, password: "strongpassword")+ }++ before do+ SiteSetting.hide_email_address_taken = true+ SiteSetting.normalize_emails = true+ end++ it "sends an email to normalized email owner when hide_email_address_taken is enabled" do+ expect do+ expect_enqueued_with(+ job: Jobs::CriticalUserEmail,+ args: {+ type: "account_exists",+ user_id: user.id,+ },+ ) do+ post "/u.json",+ params: {+ name: "Jane Doe",+ username: "janedoe9999",+ password: "strongpassword",+ email: dupe_email,+ }+ end+ end.to_not change { User.count }++ expect(response.status).to eq(200)+ expect(session["user_created_message"]).to be_present+ end+ end+context "when users already exists with given email" dolet!(:existing) { Fabricate(:user, email: post_user_params[:email]) }@@ -850,7 +890,15 @@ RSpec.describe UsersController doit "returns success if hide_email_address_taken is enabled" doSiteSetting.hide_email_address_taken = true- expect { post_user }.to_not change { User.count }+ expect {+ expect_enqueued_with(+ job: Jobs::CriticalUserEmail,+ args: {+ type: "account_exists",+ user_id: existing.id,+ },+ ) { post_user }+ }.to_not change { User.count }expect(response.status).to eq(200)expect(session["user_created_message"]).to be_presentdiff --git a/spec/support/sidekiq_helpers.rb b/spec/support/sidekiq_helpers.rbindex 883fe0fde05..73cffb463f7 100644--- a/spec/support/sidekiq_helpers.rb+++ b/spec/support/sidekiq_helpers.rb@@ -32,7 +32,7 @@ module SidekiqHelperseq(expectation),(if expectation- "No enqueued job with #{expected} found"+ "No enqueued job with #{expected}\nFound:\n #{jobs.inspect}"else"Enqueued job with #{expected} found"end