mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 23:43:43 +00:00
stream_settings: Add code to save changes in stream permissions.
This commit adds code to save changes in stream permission settings. This commit makes some changes to code in settings_org.js to handle stream settings and add corresponding handler for save button in stream_edit.js. We also add a new function get_request_data_for_stream_privacy to get the data for stream privacy which can be send with the API request. Fixes part of #19519.
This commit is contained in:
committed by
Tim Abbott
parent
a2a92b52f6
commit
6237a7b284
@@ -22,6 +22,7 @@ import * as settings_realm_domains from "./settings_realm_domains";
|
||||
import * as settings_realm_user_settings_defaults from "./settings_realm_user_settings_defaults";
|
||||
import * as settings_ui from "./settings_ui";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_edit from "./stream_edit";
|
||||
import * as stream_settings_data from "./stream_settings_data";
|
||||
import * as ui_report from "./ui_report";
|
||||
|
||||
@@ -821,7 +822,7 @@ function get_time_limit_setting_value($input_elem, for_api_data = true) {
|
||||
return parse_time_limit($custom_input_elem);
|
||||
}
|
||||
|
||||
function check_property_changed(elem, for_realm_default_settings, sub) {
|
||||
export function check_property_changed(elem, for_realm_default_settings, sub) {
|
||||
const $elem = $(elem);
|
||||
const property_name = extract_property_name($elem, for_realm_default_settings);
|
||||
let current_val = get_property_value(property_name, for_realm_default_settings, sub);
|
||||
@@ -864,6 +865,7 @@ function check_property_changed(elem, for_realm_default_settings, sub) {
|
||||
break;
|
||||
case "emojiset":
|
||||
case "user_list_style":
|
||||
case "stream_privacy":
|
||||
proposed_val = get_input_element_value($elem, "radio-group");
|
||||
break;
|
||||
default:
|
||||
@@ -950,17 +952,17 @@ function enable_or_disable_save_button($subsection_elem) {
|
||||
$subsection_elem.find(".subsection-changes-save button").prop("disabled", disable_save_btn);
|
||||
}
|
||||
|
||||
function populate_data_for_request(subsection, for_realm_default_settings) {
|
||||
const data = {};
|
||||
export function populate_data_for_request(subsection, for_realm_default_settings, sub) {
|
||||
let data = {};
|
||||
const properties_elements = get_subsection_property_elements(subsection);
|
||||
|
||||
for (const input_elem of properties_elements) {
|
||||
const $input_elem = $(input_elem);
|
||||
if (check_property_changed($input_elem, for_realm_default_settings)) {
|
||||
if (check_property_changed($input_elem, for_realm_default_settings, sub)) {
|
||||
const input_value = get_input_element_value($input_elem);
|
||||
if (input_value !== undefined) {
|
||||
let property_name;
|
||||
if (for_realm_default_settings) {
|
||||
if (for_realm_default_settings || sub) {
|
||||
property_name = extract_property_name($input_elem, for_realm_default_settings);
|
||||
} else if ($input_elem.attr("id").startsWith("id_authmethod")) {
|
||||
// Authentication Method component IDs include authentication method name
|
||||
@@ -973,6 +975,14 @@ function populate_data_for_request(subsection, for_realm_default_settings) {
|
||||
} else {
|
||||
[, property_name] = /^id_realm_(.*)$/.exec($input_elem.attr("id"));
|
||||
}
|
||||
|
||||
if (property_name === "stream_privacy") {
|
||||
data = {
|
||||
...data,
|
||||
...stream_edit.get_request_data_for_stream_privacy(input_value),
|
||||
};
|
||||
continue;
|
||||
}
|
||||
data[property_name] = input_value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,6 +378,39 @@ function get_message_retention_days_from_sub(sub) {
|
||||
return sub.message_retention_days;
|
||||
}
|
||||
|
||||
export function get_request_data_for_stream_privacy(selected_val) {
|
||||
switch (selected_val) {
|
||||
case stream_data.stream_privacy_policy_values.public.code: {
|
||||
return {
|
||||
is_private: false,
|
||||
history_public_to_subscribers: true,
|
||||
is_web_public: false,
|
||||
};
|
||||
}
|
||||
case stream_data.stream_privacy_policy_values.private.code: {
|
||||
return {
|
||||
is_private: true,
|
||||
history_public_to_subscribers: false,
|
||||
is_web_public: false,
|
||||
};
|
||||
}
|
||||
case stream_data.stream_privacy_policy_values.web_public.code: {
|
||||
return {
|
||||
is_private: false,
|
||||
history_public_to_subscribers: true,
|
||||
is_web_public: true,
|
||||
};
|
||||
}
|
||||
default: {
|
||||
return {
|
||||
is_private: true,
|
||||
history_public_to_subscribers: true,
|
||||
is_web_public: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function change_stream_privacy(e) {
|
||||
e.stopPropagation();
|
||||
|
||||
@@ -789,6 +822,24 @@ export function initialize() {
|
||||
settings_org.save_discard_widget_status_handler($subsection, false, sub);
|
||||
});
|
||||
|
||||
$("#manage_streams_container").on(
|
||||
"click",
|
||||
".subsection-header .subsection-changes-save button",
|
||||
(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const $save_button = $(e.currentTarget);
|
||||
const $subsection_elem = $save_button.closest(".settings-subsection-parent");
|
||||
|
||||
const stream_id = $save_button.closest(".subscription_settings.show").data("stream-id");
|
||||
const sub = sub_store.get(stream_id);
|
||||
const data = settings_org.populate_data_for_request($subsection_elem, false, sub);
|
||||
|
||||
const url = "/json/streams/" + stream_id;
|
||||
settings_org.save_organization_settings(data, $save_button, url);
|
||||
},
|
||||
);
|
||||
|
||||
$("#manage_streams_container").on(
|
||||
"click",
|
||||
".subsection-header .subsection-changes-discard button",
|
||||
|
||||
Reference in New Issue
Block a user