FIX: Admin change email for user process improvements and fixes (#10755)

See https://meta.discourse.org/t/changing-a-users-email/164512 for context.

When admin changes an email for a user, we were incorrectly sending the password reset email to the user's old address. Also the new email does not come into effect until the reset password process is done, so this PR adds some notes to the admin to make this clearer.
This commit is contained in:
Martin Brennan
2020-09-29 09:45:45 +10:00
committed by GitHub
parent fe86a7c7c8
commit 3cd601dcc9
5 changed files with 33 additions and 10 deletions
@@ -1,6 +1,6 @@
import I18n from "I18n";
import discourseComputed from "discourse-common/utils/decorators";
import { empty, or } from "@ember/object/computed";
import { empty, or, alias } from "@ember/object/computed";
import Controller from "@ember/controller";
import { propertyEqual } from "discourse/lib/computed";
import EmberObject from "@ember/object";
@@ -15,6 +15,7 @@ export default Controller.extend({
success: false,
oldEmail: null,
newEmail: null,
successMessage: null,
newEmailEmpty: empty("newEmail"),
@@ -28,6 +29,8 @@ export default Controller.extend({
unchanged: propertyEqual("newEmailLower", "oldEmail"),
currentUserAdmin: alias("currentUser.admin"),
@discourseComputed("newEmail")
newEmailLower(newEmail) {
return newEmail.toLowerCase().trim();
@@ -77,7 +80,25 @@ export default Controller.extend({
? this.model.addEmail(this.newEmail)
: this.model.changeEmail(this.newEmail)
).then(
() => this.set("success", true),
() => {
this.set("success", true);
if (this.model.staff) {
this.set(
"successMessage",
I18n.t("user.change_email.success_staff")
);
} else {
if (this.currentUser.admin) {
this.set(
"successMessage",
I18n.t("user.change_email.success_via_admin")
);
} else {
this.set("successMessage", I18n.t("user.change_email.success"));
}
}
},
(e) => {
this.setProperties({ error: true, saving: false });
if (
@@ -11,13 +11,7 @@
<div class="control-group">
<div class="controls">
<div class="instructions">
<p>
{{#if model.staff}}
{{i18n "user.change_email.success_staff"}}
{{else}}
{{i18n "user.change_email.success"}}
{{/if}}
</p>
<p>{{ successMessage }}</p>
</div>
</div>
</div>
@@ -44,6 +38,9 @@
{{i18n "user.email.instructions"}}
{{/if}}
</div>
{{#if currentUserAdmin}}
<p>{{i18n "user.email.admin_note"}}</p>
{{/if}}
</div>
</div>