From 39c6a01c7493ba55277c31ba9034ebc05dcbd9c3 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Tue, 21 May 2024 21:29:05 +0530 Subject: [PATCH] settings: Fix updating realm join restrictions setting. This commit fixes the bug when updating "Restrict email domains of new users?" setting by adding data-setting-widget-type attribute to the select element as get_input_element_value now expects every element to have that attribute after 64c8262eafb. Due to this change, we also need to update the code in populate_data_for_request function to not send invalid parameter in the request. This change resulted in some refactoring which now helps in not passing in the "disallow_disposable_email_addresses" and "email_restricted_to_domains" when these fields are not changed. --- web/src/settings_components.ts | 34 +++++++++++++++++++ web/src/settings_org.js | 18 ---------- .../organization_permissions_admin.hbs | 2 +- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/web/src/settings_components.ts b/web/src/settings_components.ts index bfdce0d5ea..bb41cd48c6 100644 --- a/web/src/settings_components.ts +++ b/web/src/settings_components.ts @@ -901,6 +901,32 @@ export function check_property_changed( return current_val !== proposed_val; } +function get_request_data_for_org_join_restrictions(selected_val: string): { + disallow_disposable_email_addresses: boolean; + emails_restricted_to_domains: boolean; +} { + switch (selected_val) { + case "only_selected_domain": { + return { + emails_restricted_to_domains: true, + disallow_disposable_email_addresses: false, + }; + } + case "no_disposable_email": { + return { + emails_restricted_to_domains: false, + disallow_disposable_email_addresses: true, + }; + } + default: { + return { + disallow_disposable_email_addresses: false, + emails_restricted_to_domains: false, + }; + } + } +} + export function populate_data_for_request( $subsection_elem: JQuery, for_realm_default_settings: boolean, @@ -966,6 +992,14 @@ export function populate_data_for_request( }); continue; } + + if (property_name === "org_join_restrictions") { + data = { + ...data, + ...get_request_data_for_org_join_restrictions(input_value.toString()), + }; + continue; + } data[property_name] = input_value; } } diff --git a/web/src/settings_org.js b/web/src/settings_org.js index cc801bc269..63a3cbea29 100644 --- a/web/src/settings_org.js +++ b/web/src/settings_org.js @@ -880,24 +880,6 @@ export function register_save_discard_widget_handlers( let data = {}; switch (subsection) { - case "join_settings": { - const org_join_restrictions = $("#id_realm_org_join_restrictions").val(); - switch (org_join_restrictions) { - case "only_selected_domain": - data.emails_restricted_to_domains = true; - data.disallow_disposable_email_addresses = false; - break; - case "no_disposable_email": - data.emails_restricted_to_domains = false; - data.disallow_disposable_email_addresses = true; - break; - case "no_restriction": - data.disallow_disposable_email_addresses = false; - data.emails_restricted_to_domains = false; - break; - } - break; - } case "auth_settings": data = {}; data.authentication_methods = JSON.stringify( diff --git a/web/templates/settings/organization_permissions_admin.hbs b/web/templates/settings/organization_permissions_admin.hbs index 5e38eb1d9b..5c6ae77aa6 100644 --- a/web/templates/settings/organization_permissions_admin.hbs +++ b/web/templates/settings/organization_permissions_admin.hbs @@ -30,7 +30,7 @@
-