mirror of
https://github.com/discourse/discourse.git
synced 2026-07-29 15:54:48 -05:00
FIX: When admin changes an email for the user the user must confirm the change (#10830)
See https://meta.discourse.org/t/changing-a-users-email/164512 for additional context. Previously when an admin user changed a user's email we assumed that they would need a password reset too because they likely did not have access to their account. This proved to be incorrect, as there are other reasons a user needs admin to change their email. This PR: * Changes the admin change email for user flow so the user is sent an email to confirm the change * We now record who the email change request was requested by * If the requested by user is admin and not the user we note this in the email sent to the user * We also make the confirm change email route open to anonymous users, so it can be clicked by the user even if they do not have access to their account. If there is a logged in user we make sure the confirmation matches the current user.
This commit is contained in:
@@ -78,7 +78,33 @@ describe UserNotifications do
|
||||
expect(subject.from).to eq([SiteSetting.notification_email])
|
||||
expect(subject.body).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
describe ".confirm_new_email" do
|
||||
let(:opts) do
|
||||
{ requested_by_admin: requested_by_admin, email_token: token }
|
||||
end
|
||||
let(:token) { "test123" }
|
||||
|
||||
context "when requested by admin" do
|
||||
let(:requested_by_admin) { true }
|
||||
|
||||
it "uses the requested by admin template" do
|
||||
expect(UserNotifications.confirm_new_email(user, opts).body).to include(
|
||||
"This email change was requested by a site admin."
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when not requested by admin" do
|
||||
let(:requested_by_admin) { false }
|
||||
|
||||
it "uses the normal template" do
|
||||
expect(UserNotifications.confirm_new_email(user, opts).body).not_to include(
|
||||
"This email change was requested by a site admin."
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.email_login' do
|
||||
|
||||
Reference in New Issue
Block a user