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 64c8262eaf.

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.
This commit is contained in:
Sahil Batra 2024-05-21 21:29:05 +05:30 committed by Tim Abbott
parent ed8d7ed864
commit 39c6a01c74
3 changed files with 35 additions and 19 deletions

View File

@ -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;
}
}

View File

@ -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(

View File

@ -30,7 +30,7 @@
<div class="input-group">
<label for="realm_org_join_restrictions" class="settings-field-label">{{t "Restrict email domains of new users?" }}</label>
<select name="realm_org_join_restrictions" id="id_realm_org_join_restrictions" class="prop-element settings_select bootstrap-focus-style">
<select name="realm_org_join_restrictions" id="id_realm_org_join_restrictions" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="string">
<option value="no_restriction">{{t "No restrictions" }}</option>
<option value="no_disposable_email">{{t "Dont allow disposable email addresses" }}</option>
<option value="only_selected_domain">{{t "Restrict to a list of domains" }}</option>