diff --git a/web/src/settings_components.ts b/web/src/settings_components.ts index 79a684611b..ac53b7c897 100644 --- a/web/src/settings_components.ts +++ b/web/src/settings_components.ts @@ -1353,6 +1353,40 @@ function should_disable_save_button_for_time_limit_settings( return disable_save_btn; } +function should_disable_save_button_for_group_settings(settings: string[]): boolean { + for (const setting_name of settings) { + let group_setting_config; + if (setting_name.startsWith("realm_")) { + const setting_name_without_prefix = /^realm_(.*)$/.exec(setting_name)![1]!; + group_setting_config = group_permission_settings.get_group_permission_setting_config( + setting_name_without_prefix, + "realm", + ); + } else { + // We do not have any stream settings using the new UI currently, + // so we know that this block will be called for group setting only. + group_setting_config = group_permission_settings.get_group_permission_setting_config( + setting_name, + "group", + ); + } + assert(group_setting_config !== undefined); + if (group_setting_config.allow_nobody_group) { + continue; + } + + const pill_widget = get_group_setting_widget(setting_name); + assert(pill_widget !== null); + + const setting_value = get_group_setting_widget_value(pill_widget); + const nobody_group = user_groups.get_user_group_from_name("role:nobody")!; + if (setting_value === nobody_group.id) { + return true; + } + } + return false; +} + function enable_or_disable_save_button($subsection_elem: JQuery): void { const time_limit_settings = [...$subsection_elem.find(".time-limit-setting")]; @@ -1382,6 +1416,15 @@ function enable_or_disable_save_button($subsection_elem: JQuery): void { } } + if (!disable_save_btn) { + const group_settings = [...$subsection_elem.find(".pill-container")].map((elem) => + extract_property_name($(elem)), + ); + if (group_settings.length) { + disable_save_btn = should_disable_save_button_for_group_settings(group_settings); + } + } + $subsection_elem.find(".subsection-changes-save button").prop("disabled", disable_save_btn); } diff --git a/web/tests/settings_org.test.js b/web/tests/settings_org.test.js index 2d17074d19..26c58b235d 100644 --- a/web/tests/settings_org.test.js +++ b/web/tests/settings_org.test.js @@ -86,6 +86,7 @@ function createSaveButtons(subsection) { $save_button_controls.closest = () => $stub_save_button_header; $stub_save_button_header.set_find_results(".time-limit-setting", []); + $stub_save_button_header.set_find_results(".pill-container", []); $stub_save_button_header.set_find_results(".subsection-changes-save button", $stub_save_button); return {