mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 00:11:39 +08:00
FEATURE: User fields required for existing users - Part 2 (#27172)
We want to allow admins to make new required fields apply to existing users. In order for this to work we need to have a way to make those users fill up the fields on their next page load. This is very similar to how adding a 2FA requirement post-fact works. Users will be redirected to a page where they can fill up the remaining required fields, and until they do that they won't be able to do anything else.
This commit is contained in:
@ -3,6 +3,7 @@ import { action } from "@ember/object";
|
||||
import { schedule } from "@ember/runloop";
|
||||
import { service } from "@ember/service";
|
||||
import { isEmpty } from "@ember/utils";
|
||||
import { Promise } from "rsvp";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import { i18n, propertyEqual } from "discourse/lib/computed";
|
||||
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
||||
@ -12,6 +13,7 @@ import UserField from "admin/models/user-field";
|
||||
|
||||
export default Component.extend(bufferedProperty("userField"), {
|
||||
adminCustomUserFields: service(),
|
||||
dialog: service(),
|
||||
|
||||
tagName: "",
|
||||
isEditing: false,
|
||||
@ -64,8 +66,29 @@ export default Component.extend(bufferedProperty("userField"), {
|
||||
return ret.join(", ");
|
||||
},
|
||||
|
||||
@discourseComputed("buffered.requirement")
|
||||
editableDisabled(requirement) {
|
||||
return requirement === "for_all_users";
|
||||
},
|
||||
|
||||
@action
|
||||
save() {
|
||||
changeRequirementType(requirement) {
|
||||
this.buffered.set("requirement", requirement);
|
||||
this.buffered.set("editable", requirement === "for_all_users");
|
||||
},
|
||||
|
||||
async _confirmChanges() {
|
||||
return new Promise((resolve) => {
|
||||
this.dialog.yesNoConfirm({
|
||||
message: I18n.t("admin.user_fields.requirement.confirmation"),
|
||||
didCancel: () => resolve(false),
|
||||
didConfirm: () => resolve(true),
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@action
|
||||
async save() {
|
||||
const attrs = this.buffered.getProperties(
|
||||
"name",
|
||||
"description",
|
||||
@ -79,6 +102,16 @@ export default Component.extend(bufferedProperty("userField"), {
|
||||
...this.adminCustomUserFields.additionalProperties
|
||||
);
|
||||
|
||||
let confirm = true;
|
||||
|
||||
if (attrs.requirement === "for_all_users") {
|
||||
confirm = await this._confirmChanges();
|
||||
}
|
||||
|
||||
if (!confirm) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.userField
|
||||
.save(attrs)
|
||||
.then(() => {
|
||||
|
Reference in New Issue
Block a user