diff --git a/app/controllers/users_email_controller.rb b/app/controllers/users_email_controller.rb index a34cf215927..ae7b4c56230 100644 --- a/app/controllers/users_email_controller.rb +++ b/app/controllers/users_email_controller.rb @@ -35,7 +35,7 @@ class UsersEmailController < ApplicationController RateLimiter.new(user, "change-email-hr-#{request.remote_ip}", 6, 1.hour).performed! RateLimiter.new(user, "change-email-min-#{request.remote_ip}", 3, 1.minute).performed! - updater = EmailUpdater.new(guardian: guardian, user: user, initiating_user: current_user) + updater = EmailUpdater.new(guardian: guardian, user: user) updater.change_to(params[:email]) if updater.errors.present? diff --git a/lib/email_updater.rb b/lib/email_updater.rb index 68799e304a1..b3f4371c989 100644 --- a/lib/email_updater.rb +++ b/lib/email_updater.rb @@ -5,10 +5,9 @@ class EmailUpdater attr_reader :user - def initialize(guardian: nil, user: nil, initiating_user: nil) + def initialize(guardian: nil, user: nil) @guardian = guardian @user = user - @initiating_user = initiating_user end def self.human_attribute_name(name, options = {}) @@ -135,7 +134,7 @@ class EmailUpdater end def initiating_admin_changing_another_user_email? - @initiating_user&.admin? && @initiating_user != @user + @guardian.is_admin? && @guardian.user != @user end def auto_confirm_and_send_password_reset(email_token) diff --git a/spec/components/email_updater_spec.rb b/spec/components/email_updater_spec.rb index b5a06937e68..b2cae4d24d2 100644 --- a/spec/components/email_updater_spec.rb +++ b/spec/components/email_updater_spec.rb @@ -19,7 +19,7 @@ describe EmailUpdater do context "when an admin is changing the email of another user" do let(:admin) { Fabricate(:admin) } - let(:updater) { EmailUpdater.new(guardian: user.guardian, user: user, initiating_user: admin) } + let(:updater) { EmailUpdater.new(guardian: admin.guardian, user: user) } def expect_old_email_job Jobs.expects(:enqueue).with(:critical_user_email, has_entries(to_address: old_email, type: :notify_old_email, user_id: user.id))