FIX: When admin changes another user's email auto-confirm the change (PR #9001)

Discussions in meta topic: https://meta.discourse.org/t/howto-change-a-users-email-when-they-cant-access-the-email-account-and-forgot-password/56322

When admin changes a user’s email from the preferences page of that user:

  • The user will not be sent an email to confirm that their email is changing. They will be sent a reset password email so they can set the password for their account at the new email address.
  • The user will still be sent an email to their old email to inform them that it was changed.
  • Admin and staff users still need to follow the same old + new confirm process, as do users changing their own email.

GitHub

3 optional arguments might be the threshold were it’s better to use optional named arguments

  def initialize(guardian: nil, user: nil, initiating_user: nil)

Calling this admin makes it easier to read

    let(:admin) { Fabricate(:admin) }

Might be better to get rid of the string when we already have it in a variable?

      Jobs.expects(:enqueue).with(:critical_user_email, has_entries(to_address: old_email, type: :notify_old_email, user_id: user.id))

Calling this moderator makes it easier to read

      let(:moderator) { Fabricate(:moderator, email: old_email) }
  context "when an admin is changing the email of another user" do

Looks good to me :+1:

Damn I knew I should have done that!

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/changing-a-users-email/164512/1