settings: Use new group setting to private channels creation permission.

This commit updates webapp code to use new group based setting to check
permission for creating private streams.
This commit is contained in:
Sahil Batra 2024-06-17 19:36:49 +05:30 committed by Tim Abbott
parent 0bae59fa4b
commit e19524ba92
13 changed files with 43 additions and 52 deletions

View File

@ -103,7 +103,6 @@ async function test_changing_create_streams_and_invite_to_stream_policies(
page: Page, page: Page,
): Promise<void> { ): Promise<void> {
const policies = { const policies = {
"create private stream": "#id_realm_create_private_stream_policy",
"invite to stream": "#id_realm_invite_to_stream_policy", "invite to stream": "#id_realm_invite_to_stream_policy",
}; };
const policy_values = { const policy_values = {

View File

@ -204,7 +204,6 @@ export function dispatch_normal_event(event) {
avatar_changes_disabled: settings_account.update_avatar_change_display, avatar_changes_disabled: settings_account.update_avatar_change_display,
bot_creation_policy: settings_bots.update_bot_permissions_ui, bot_creation_policy: settings_bots.update_bot_permissions_ui,
create_multiuse_invite_group: noop, create_multiuse_invite_group: noop,
create_private_stream_policy: noop,
create_web_public_stream_policy: noop, create_web_public_stream_policy: noop,
invite_to_stream_policy: noop, invite_to_stream_policy: noop,
default_code_block_language: noop, default_code_block_language: noop,
@ -265,15 +264,10 @@ export function dispatch_normal_event(event) {
gear_menu.rerender(); gear_menu.rerender();
} }
const stream_creation_settings = [ if (
"create_private_stream_policy", event.property === "create_web_public_stream_policy" ||
"create_web_public_stream_policy", event.property === "enable_spectator_access"
]; ) {
if (stream_creation_settings.includes(event.property)) {
stream_settings_ui.update_stream_privacy_choices(event.property);
}
if (event.property === "enable_spectator_access") {
stream_settings_ui.update_stream_privacy_choices( stream_settings_ui.update_stream_privacy_choices(
"create_web_public_stream_policy", "create_web_public_stream_policy",
); );
@ -295,7 +289,10 @@ export function dispatch_normal_event(event) {
gear_menu.rerender(); gear_menu.rerender();
} }
if (key === "can_create_public_channel_group") { if (
key === "can_create_public_channel_group" ||
key === "can_create_private_channel_group"
) {
stream_settings_ui.update_stream_privacy_choices(key); stream_settings_ui.update_stream_privacy_choices(key);
} }

View File

@ -473,6 +473,7 @@ const dropdown_widget_map = new Map<string, DropdownWidget | null>([
["realm_can_access_all_users_group", null], ["realm_can_access_all_users_group", null],
["can_mention_group", null], ["can_mention_group", null],
["realm_can_create_public_channel_group", null], ["realm_can_create_public_channel_group", null],
["realm_can_create_private_channel_group", null],
]); ]);
export function get_widget_for_dropdown_list_settings( export function get_widget_for_dropdown_list_settings(
@ -779,6 +780,7 @@ export function check_realm_settings_property_changed(elem: HTMLElement): boolea
case "realm_create_multiuse_invite_group": case "realm_create_multiuse_invite_group":
case "realm_can_access_all_users_group": case "realm_can_access_all_users_group":
case "realm_can_create_public_channel_group": case "realm_can_create_public_channel_group":
case "realm_can_create_private_channel_group":
proposed_val = get_dropdown_list_widget_setting_value($elem); proposed_val = get_dropdown_list_widget_setting_value($elem);
break; break;
case "realm_message_content_edit_limit_seconds": case "realm_message_content_edit_limit_seconds":
@ -976,6 +978,15 @@ export function populate_data_for_realm_settings_request(
}); });
continue; continue;
} }
if (property_name === "can_create_private_channel_group") {
data[property_name] = JSON.stringify({
new: input_value,
old: realm.realm_can_create_private_channel_group,
});
continue;
}
data[property_name] = input_value; data[property_name] = input_value;
} }
} }

View File

@ -140,7 +140,13 @@ export function user_can_subscribe_other_users(): boolean {
} }
export function user_can_create_private_streams(): boolean { export function user_can_create_private_streams(): boolean {
return user_has_permission(realm.realm_create_private_stream_policy); if (page_params.is_spectator) {
return false;
}
return user_groups.is_user_in_group(
realm.realm_can_create_private_channel_group,
current_user.user_id,
);
} }
export function user_can_create_public_streams(): boolean { export function user_can_create_public_streams(): boolean {

View File

@ -119,7 +119,6 @@ export function get_org_type_dropdown_options() {
} }
const simple_dropdown_properties = [ const simple_dropdown_properties = [
"realm_create_private_stream_policy",
"realm_create_web_public_stream_policy", "realm_create_web_public_stream_policy",
"realm_invite_to_stream_policy", "realm_invite_to_stream_policy",
"realm_user_group_edit_policy", "realm_user_group_edit_policy",
@ -487,6 +486,7 @@ export function discard_realm_property_element_changes(elem) {
case "realm_create_multiuse_invite_group": case "realm_create_multiuse_invite_group":
case "realm_can_access_all_users_group": case "realm_can_access_all_users_group":
case "realm_can_create_public_channel_group": case "realm_can_create_public_channel_group":
case "realm_can_create_private_channel_group":
settings_components.set_dropdown_list_widget_setting_value( settings_components.set_dropdown_list_widget_setting_value(
property_name, property_name,
property_value, property_value,

View File

@ -85,6 +85,7 @@ export const realm_schema = z.object({
realm_bot_domain: z.string(), realm_bot_domain: z.string(),
realm_can_access_all_users_group: z.number(), realm_can_access_all_users_group: z.number(),
realm_can_create_public_channel_group: z.number(), realm_can_create_public_channel_group: z.number(),
realm_can_create_private_channel_group: z.number(),
realm_create_multiuse_invite_group: z.number(), realm_create_multiuse_invite_group: z.number(),
realm_create_private_stream_policy: z.number(), realm_create_private_stream_policy: z.number(),
realm_create_web_public_stream_policy: z.number(), realm_create_web_public_stream_policy: z.number(),

View File

@ -947,7 +947,7 @@ export function update_stream_privacy_choices(policy) {
$container = $("#stream_permission_settings"); $container = $("#stream_permission_settings");
} }
if (policy === "create_private_stream_policy") { if (policy === "can_create_private_channel_group") {
stream_ui_updates.update_private_stream_privacy_option_state($container); stream_ui_updates.update_private_stream_privacy_option_state($container);
} }
if (policy === "can_create_public_channel_group") { if (policy === "can_create_public_channel_group") {

View File

@ -560,9 +560,9 @@ export function initialize_everything(state_data) {
"realm_bot_creation_policy", "realm_bot_creation_policy",
"realm_bot_domain", "realm_bot_domain",
"realm_can_access_all_users_group", "realm_can_access_all_users_group",
"realm_can_create_private_channel_group",
"realm_can_create_public_channel_group", "realm_can_create_public_channel_group",
"realm_create_multiuse_invite_group", "realm_create_multiuse_invite_group",
"realm_create_private_stream_policy",
"realm_create_web_public_stream_policy", "realm_create_web_public_stream_policy",
"realm_date_created", "realm_date_created",
"realm_default_code_block_language", "realm_default_code_block_language",

View File

@ -87,12 +87,12 @@
{{> dropdown_options_widget option_values=create_web_public_stream_policy_values}} {{> dropdown_options_widget option_values=create_web_public_stream_policy_values}}
</select> </select>
</div> </div>
<div class="input-group">
<label for="realm_create_private_stream_policy" class="settings-field-label">{{t "Who can create private channels" }}</label> {{> ../dropdown_widget_with_label
<select name="realm_create_private_stream_policy" id="id_realm_create_private_stream_policy" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="number"> widget_name="realm_can_create_private_channel_group"
{{> dropdown_options_widget option_values=common_policy_values}} label=(t 'Who can create private channels')
</select> value_type="number"}}
</div>
<div class="input-group"> <div class="input-group">
<label for="realm_invite_to_stream_policy" class="settings-field-label">{{t "Who can add users to channels" }}</label> <label for="realm_invite_to_stream_policy" class="settings-field-label">{{t "Who can add users to channels" }}</label>
<select name="realm_invite_to_stream_policy" id="id_realm_invite_to_stream_policy" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="number"> <select name="realm_invite_to_stream_policy" id="id_realm_invite_to_stream_policy" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="number">

View File

@ -489,15 +489,7 @@ run_test("realm settings", ({override}) => {
} }
let update_called = false; let update_called = false;
let event = event_fixtures.realm__update__create_private_stream_policy; let event = event_fixtures.realm__update__create_web_public_stream_policy;
stream_settings_ui.update_stream_privacy_choices = (property) => {
assert_same(property, "create_private_stream_policy");
update_called = true;
};
test_realm_integer(event, "realm_create_private_stream_policy");
update_called = false;
event = event_fixtures.realm__update__create_web_public_stream_policy;
stream_settings_ui.update_stream_privacy_choices = (property) => { stream_settings_ui.update_stream_privacy_choices = (property) => {
assert_same(property, "create_web_public_stream_policy"); assert_same(property, "create_web_public_stream_policy");
update_called = true; update_called = true;

View File

@ -263,13 +263,6 @@ exports.fixtures = {
value: 1, value: 1,
}, },
realm__update__create_private_stream_policy: {
type: "realm",
op: "update",
property: "create_private_stream_policy",
value: 2,
},
realm__update__create_web_public_stream_policy: { realm__update__create_web_public_stream_policy: {
type: "realm", type: "realm",
op: "update", op: "update",

View File

@ -141,11 +141,6 @@ function test_policy(label, policy, validation_func) {
}); });
} }
test_policy(
"user_can_create_private_streams",
"realm_create_private_stream_policy",
settings_data.user_can_create_private_streams,
);
test_policy( test_policy(
"user_can_subscribe_other_users", "user_can_subscribe_other_users",
"realm_invite_to_stream_policy", "realm_invite_to_stream_policy",
@ -471,3 +466,9 @@ test_realm_group_settings(
"realm_can_create_public_channel_group", "realm_can_create_public_channel_group",
settings_data.user_can_create_public_streams, settings_data.user_can_create_public_streams,
); );
test_realm_group_settings(
"user_can_create_private_streams",
"realm_can_create_private_channel_group",
settings_data.user_can_create_private_streams,
);

View File

@ -99,7 +99,6 @@ function test_submit_settings_form(override, submit_form) {
realm_waiting_period_threshold: 1, realm_waiting_period_threshold: 1,
realm_default_language: '"es"', realm_default_language: '"es"',
realm_invite_to_stream_policy: settings_config.common_policy_values.by_admins_only.code, realm_invite_to_stream_policy: settings_config.common_policy_values.by_admins_only.code,
realm_create_private_stream_policy: settings_config.common_policy_values.by_members.code,
realm_invite_to_realm_policy: settings_config.common_policy_values.by_members.code, realm_invite_to_realm_policy: settings_config.common_policy_values.by_members.code,
}); });
@ -133,11 +132,6 @@ function test_submit_settings_form(override, submit_form) {
$invite_to_stream_policy_elem.attr("id", "id_realm_invite_to_stream_policy"); $invite_to_stream_policy_elem.attr("id", "id_realm_invite_to_stream_policy");
$invite_to_stream_policy_elem.data = () => "number"; $invite_to_stream_policy_elem.data = () => "number";
const $create_private_stream_policy_elem = $("#id_realm_create_private_stream_policy");
$create_private_stream_policy_elem.val("2");
$create_private_stream_policy_elem.attr("id", "id_realm_create_private_stream_policy");
$create_private_stream_policy_elem.data = () => "number";
const $add_custom_emoji_policy_elem = $("#id_realm_add_custom_emoji_policy"); const $add_custom_emoji_policy_elem = $("#id_realm_add_custom_emoji_policy");
$add_custom_emoji_policy_elem.val("1"); $add_custom_emoji_policy_elem.val("1");
$add_custom_emoji_policy_elem.attr("id", "id_realm_add_custom_emoji_policy"); $add_custom_emoji_policy_elem.attr("id", "id_realm_add_custom_emoji_policy");
@ -157,7 +151,6 @@ function test_submit_settings_form(override, submit_form) {
$subsection_elem.set_find_results(".prop-element", [ $subsection_elem.set_find_results(".prop-element", [
$bot_creation_policy_elem, $bot_creation_policy_elem,
$add_custom_emoji_policy_elem, $add_custom_emoji_policy_elem,
$create_private_stream_policy_elem,
$invite_to_realm_policy_elem, $invite_to_realm_policy_elem,
$invite_to_stream_policy_elem, $invite_to_stream_policy_elem,
]); ]);
@ -171,7 +164,6 @@ function test_submit_settings_form(override, submit_form) {
invite_to_realm_policy: 2, invite_to_realm_policy: 2,
invite_to_stream_policy: 1, invite_to_stream_policy: 1,
add_custom_emoji_policy: 1, add_custom_emoji_policy: 1,
create_private_stream_policy: 2,
}; };
assert.deepEqual(data, expected_value); assert.deepEqual(data, expected_value);
@ -325,7 +317,6 @@ function test_sync_realm_settings() {
} }
} }
test_common_policy("create_private_stream_policy");
test_common_policy("invite_to_stream_policy"); test_common_policy("invite_to_stream_policy");
test_common_policy("invite_to_realm_policy"); test_common_policy("invite_to_realm_policy");