diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index 6f9dc58585..531356e638 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -277,6 +277,7 @@ run_test("allow normal typing when processing text", ({override}) => { run_test("streams", ({override}) => { settings_data.user_can_create_private_streams = () => true; settings_data.user_can_create_public_streams = () => true; + settings_data.user_can_create_web_public_streams = () => true; override(overlays, "streams_open", () => true); override(overlays, "is_active", () => true); assert_mapping("S", stream_settings_ui, "keyboard_sub"); @@ -284,6 +285,7 @@ run_test("streams", ({override}) => { assert_mapping("n", stream_settings_ui, "open_create_stream"); settings_data.user_can_create_private_streams = () => false; settings_data.user_can_create_public_streams = () => false; + settings_data.user_can_create_web_public_streams = () => false; assert_unmapped("n"); }); diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index b8ee6101e1..34ecfea6c2 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -685,6 +685,9 @@ test("set_up", ({override, mock_template}) => { $("#allowed_domains_label").set_parent($.create("")); const waiting_period_parent_elem = $.create("waiting-period-parent-stub"); $("#id_realm_waiting_period_threshold").set_parent(waiting_period_parent_elem); + $("#id_realm_create_web_public_stream_policy").set_parent( + $.create(""), + ); // TEST set_up() here, but this mostly just allows us to // get access to the click handlers. diff --git a/static/js/admin.js b/static/js/admin.js index b5a6277531..639ada286f 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -158,6 +158,8 @@ export function build_page() { email_notifications_batching_period_values: settings_config.email_notifications_batching_period_values, twenty_four_hour_time_values: settings_config.twenty_four_hour_time_values, + create_web_public_stream_policy_values: + settings_config.create_web_public_stream_policy_values, }; if (options.realm_logo_source !== "D" && options.realm_night_logo_source === "D") { diff --git a/static/js/hotkey.js b/static/js/hotkey.js index e0930f34f3..bb4173e2ef 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -746,7 +746,8 @@ export function process_hotkey(e, hotkey) { event_name === "n_key" && overlays.streams_open() && (settings_data.user_can_create_private_streams() || - settings_data.user_can_create_public_streams()) + settings_data.user_can_create_public_streams() || + settings_data.user_can_create_web_public_streams()) ) { stream_settings_ui.open_create_stream(); return true; diff --git a/static/js/popover_menus.js b/static/js/popover_menus.js index 822a1df528..a946632136 100644 --- a/static/js/popover_menus.js +++ b/static/js/popover_menus.js @@ -44,7 +44,8 @@ export function initialize() { render_left_sidebar_stream_setting_popover({ can_create_streams: settings_data.user_can_create_private_streams() || - settings_data.user_can_create_public_streams(), + settings_data.user_can_create_public_streams() || + settings_data.user_can_create_web_public_streams(), }), ); left_sidebar_stream_setting_popover_displayed = true; diff --git a/static/js/settings_org.js b/static/js/settings_org.js index 7fc17fd94c..a1f87edc46 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -218,6 +218,7 @@ function get_subsection_property_elements(element) { const simple_dropdown_properties = [ "realm_create_private_stream_policy", "realm_create_public_stream_policy", + "realm_create_web_public_stream_policy", "realm_invite_to_stream_policy", "realm_user_group_edit_policy", "realm_private_message_policy", @@ -349,6 +350,13 @@ function set_digest_emails_weekday_visibility() { ); } +function set_create_web_public_stream_dropdown_visibility() { + change_element_block_display_property( + "id_realm_create_web_public_stream_policy", + page_params.server_web_public_streams_enabled && page_params.realm_enable_spectator_access, + ); +} + export function populate_realm_domains(realm_domains) { if (!meta.loaded) { return; @@ -445,6 +453,9 @@ function update_dependent_subsettings(property_name) { ); set_digest_emails_weekday_visibility(); break; + case "realm_enable_spectator_access": + set_create_web_public_stream_dropdown_visibility(); + break; } } @@ -988,6 +999,7 @@ export function build_page() { set_org_join_restrictions_dropdown(); set_message_content_in_email_notifications_visiblity(); set_digest_emails_weekday_visibility(); + set_create_web_public_stream_dropdown_visibility(); register_save_discard_widget_handlers($(".admin-realm-form"), "/json/realm", false); diff --git a/static/js/stream_create.js b/static/js/stream_create.js index 91d82f8244..2ed4b68a31 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -301,6 +301,7 @@ function clear_error_display() { export function show_new_stream_modal() { $("#stream-creation").removeClass("hide"); $(".right .settings").hide(); + stream_settings_ui.hide_or_disable_stream_privacy_options_if_required($("#stream-creation")); const add_people_container = $("#people_to_add"); add_people_container.html( diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index e43e951a8c..8b6e893b44 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -794,6 +794,11 @@ export function initialize() { change_stream_message_retention_days_block_display_property(dropdown_value); }); }, + on_show: () => { + stream_settings_ui.hide_or_disable_stream_privacy_options_if_required( + $("#stream_privacy_modal"), + ); + }, }); e.preventDefault(); e.stopPropagation(); diff --git a/static/js/stream_settings_ui.js b/static/js/stream_settings_ui.js index f2cc455fd6..6418707f2f 100644 --- a/static/js/stream_settings_ui.js +++ b/static/js/stream_settings_ui.js @@ -607,7 +607,8 @@ export function setup_page(callback) { const template_data = { can_create_streams: settings_data.user_can_create_private_streams() || - settings_data.user_can_create_public_streams(), + settings_data.user_can_create_public_streams() || + settings_data.user_can_create_web_public_streams(), hide_all_streams: !should_list_all_streams(), max_name_length: page_params.max_stream_name_length, max_description_length: page_params.max_stream_description_length, @@ -651,6 +652,7 @@ export function setup_page(callback) { if ( settings_data.user_can_create_private_streams() || settings_data.user_can_create_public_streams() || + settings_data.user_can_create_web_public_streams() || page_params.realm_is_zephyr_mirror_realm ) { open_create_stream(); @@ -986,6 +988,29 @@ export function sub_or_unsub(sub, stream_row) { } } +export function hide_or_disable_stream_privacy_options_if_required(container) { + if (!settings_data.user_can_create_web_public_streams()) { + const web_public_stream_elem = container.find( + `input[value='${CSS.escape( + stream_data.stream_privacy_policy_values.web_public.code, + )}']`, + ); + if (!web_public_stream_elem.is(":checked")) { + if ( + !page_params.server_web_public_streams_enabled || + !page_params.realm_enable_spectator_access + ) { + web_public_stream_elem.closest(".radio-input-parent").hide(); + container + .find(".stream-privacy-values .radio-input-parent:visible:last") + .css("border-bottom", "none"); + } else { + web_public_stream_elem.prop("disabled", true); + } + } + } +} + export function initialize() { $("#subscriptions_table").on("click", ".create_stream_button", (e) => { e.preventDefault(); diff --git a/static/templates/settings/organization_permissions_admin.hbs b/static/templates/settings/organization_permissions_admin.hbs index 4848ce6390..8b2387c1fa 100644 --- a/static/templates/settings/organization_permissions_admin.hbs +++ b/static/templates/settings/organization_permissions_admin.hbs @@ -109,6 +109,12 @@ is_checked=realm_enable_spectator_access render_only=page_params.server_web_public_streams_enabled label=admin_settings_label.realm_enable_spectator_access}} +
+ + +