From 6f55457652008e2e85706340dcd2c965924a30f3 Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Mon, 21 Oct 2024 14:37:46 +0800 Subject: [PATCH] DEV: Don't ask admin to re-confirm 'for all users' when requirement didn't change (#29307) When adding or updating a custom user field to apply to all users (retroactively) we want to alert the admin that this will force all existing users to fill up the field before they are able to access the forum again. However, we currently show this prompt when making changes only to other attributes on the custom field, i.e. the requirement hasn't changed. This commit fixes that. --- .../addon/components/admin-user-field-item.js | 8 +++++++- spec/system/admin_user_fields_spec.rb | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/addon/components/admin-user-field-item.js b/app/assets/javascripts/admin/addon/components/admin-user-field-item.js index 28fb4325c7e..e3c2609a637 100644 --- a/app/assets/javascripts/admin/addon/components/admin-user-field-item.js +++ b/app/assets/javascripts/admin/addon/components/admin-user-field-item.js @@ -19,6 +19,8 @@ export default class AdminUserFieldItem extends Component { @tracked editableDisabled = this.args.userField.requirement === "for_all_users"; + originalRequirement = this.args.userField.requirement; + get fieldName() { return UserField.fieldTypeById(this.fieldType)?.name; } @@ -85,7 +87,10 @@ export default class AdminUserFieldItem extends Component { async save(data) { let confirm = true; - if (data.requirement === "for_all_users") { + if ( + data.requirement === "for_all_users" && + this.originalRequirement !== "for_all_users" + ) { confirm = await this._confirmChanges(); } @@ -100,6 +105,7 @@ export default class AdminUserFieldItem extends Component { return; } + this.originalRequirement = data.requirement; this.isEditing = false; }) .catch(popupAjaxError); diff --git a/spec/system/admin_user_fields_spec.rb b/spec/system/admin_user_fields_spec.rb index 4d8d61612d2..b8b14fb869c 100644 --- a/spec/system/admin_user_fields_spec.rb +++ b/spec/system/admin_user_fields_spec.rb @@ -59,4 +59,22 @@ describe "Admin User Fields", type: :system, js: true do expect(page).to have_text(I18n.t("admin_js.admin.user_fields.requirement.confirmation")) end + + context "when editing an existing user field" do + fab!(:user_field) { Fabricate(:user_field, requirement: "for_all_users") } + + it "does not require confirmation if the field already applies to all users" do + user_fields_page.visit + + page.find(".user-field .edit").click + + form = page.find(".user-field") + + form.find(".user-field-name").fill_in(with: "Favourite Transformer") + + form.find(".btn-primary").click + + expect(page).to have_no_text(I18n.t("admin_js.admin.user_fields.requirement.confirmation")) + end + end end