mirror of https://github.com/zulip/zulip.git
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:
parent
0bae59fa4b
commit
e19524ba92
|
@ -103,7 +103,6 @@ async function test_changing_create_streams_and_invite_to_stream_policies(
|
|||
page: Page,
|
||||
): Promise<void> {
|
||||
const policies = {
|
||||
"create private stream": "#id_realm_create_private_stream_policy",
|
||||
"invite to stream": "#id_realm_invite_to_stream_policy",
|
||||
};
|
||||
const policy_values = {
|
||||
|
|
|
@ -204,7 +204,6 @@ export function dispatch_normal_event(event) {
|
|||
avatar_changes_disabled: settings_account.update_avatar_change_display,
|
||||
bot_creation_policy: settings_bots.update_bot_permissions_ui,
|
||||
create_multiuse_invite_group: noop,
|
||||
create_private_stream_policy: noop,
|
||||
create_web_public_stream_policy: noop,
|
||||
invite_to_stream_policy: noop,
|
||||
default_code_block_language: noop,
|
||||
|
@ -265,15 +264,10 @@ export function dispatch_normal_event(event) {
|
|||
gear_menu.rerender();
|
||||
}
|
||||
|
||||
const stream_creation_settings = [
|
||||
"create_private_stream_policy",
|
||||
"create_web_public_stream_policy",
|
||||
];
|
||||
if (stream_creation_settings.includes(event.property)) {
|
||||
stream_settings_ui.update_stream_privacy_choices(event.property);
|
||||
}
|
||||
|
||||
if (event.property === "enable_spectator_access") {
|
||||
if (
|
||||
event.property === "create_web_public_stream_policy" ||
|
||||
event.property === "enable_spectator_access"
|
||||
) {
|
||||
stream_settings_ui.update_stream_privacy_choices(
|
||||
"create_web_public_stream_policy",
|
||||
);
|
||||
|
@ -295,7 +289,10 @@ export function dispatch_normal_event(event) {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -473,6 +473,7 @@ const dropdown_widget_map = new Map<string, DropdownWidget | null>([
|
|||
["realm_can_access_all_users_group", null],
|
||||
["can_mention_group", null],
|
||||
["realm_can_create_public_channel_group", null],
|
||||
["realm_can_create_private_channel_group", null],
|
||||
]);
|
||||
|
||||
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_can_access_all_users_group":
|
||||
case "realm_can_create_public_channel_group":
|
||||
case "realm_can_create_private_channel_group":
|
||||
proposed_val = get_dropdown_list_widget_setting_value($elem);
|
||||
break;
|
||||
case "realm_message_content_edit_limit_seconds":
|
||||
|
@ -976,6 +978,15 @@ export function populate_data_for_realm_settings_request(
|
|||
});
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,7 +140,13 @@ export function user_can_subscribe_other_users(): 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 {
|
||||
|
|
|
@ -119,7 +119,6 @@ export function get_org_type_dropdown_options() {
|
|||
}
|
||||
|
||||
const simple_dropdown_properties = [
|
||||
"realm_create_private_stream_policy",
|
||||
"realm_create_web_public_stream_policy",
|
||||
"realm_invite_to_stream_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_can_access_all_users_group":
|
||||
case "realm_can_create_public_channel_group":
|
||||
case "realm_can_create_private_channel_group":
|
||||
settings_components.set_dropdown_list_widget_setting_value(
|
||||
property_name,
|
||||
property_value,
|
||||
|
|
|
@ -85,6 +85,7 @@ export const realm_schema = z.object({
|
|||
realm_bot_domain: z.string(),
|
||||
realm_can_access_all_users_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_private_stream_policy: z.number(),
|
||||
realm_create_web_public_stream_policy: z.number(),
|
||||
|
|
|
@ -947,7 +947,7 @@ export function update_stream_privacy_choices(policy) {
|
|||
$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);
|
||||
}
|
||||
if (policy === "can_create_public_channel_group") {
|
||||
|
|
|
@ -560,9 +560,9 @@ export function initialize_everything(state_data) {
|
|||
"realm_bot_creation_policy",
|
||||
"realm_bot_domain",
|
||||
"realm_can_access_all_users_group",
|
||||
"realm_can_create_private_channel_group",
|
||||
"realm_can_create_public_channel_group",
|
||||
"realm_create_multiuse_invite_group",
|
||||
"realm_create_private_stream_policy",
|
||||
"realm_create_web_public_stream_policy",
|
||||
"realm_date_created",
|
||||
"realm_default_code_block_language",
|
||||
|
|
|
@ -87,12 +87,12 @@
|
|||
{{> dropdown_options_widget option_values=create_web_public_stream_policy_values}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label for="realm_create_private_stream_policy" class="settings-field-label">{{t "Who can create private channels" }}</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">
|
||||
{{> dropdown_options_widget option_values=common_policy_values}}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{{> ../dropdown_widget_with_label
|
||||
widget_name="realm_can_create_private_channel_group"
|
||||
label=(t 'Who can create private channels')
|
||||
value_type="number"}}
|
||||
|
||||
<div class="input-group">
|
||||
<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">
|
||||
|
|
|
@ -489,15 +489,7 @@ run_test("realm settings", ({override}) => {
|
|||
}
|
||||
|
||||
let update_called = false;
|
||||
let event = event_fixtures.realm__update__create_private_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;
|
||||
let event = event_fixtures.realm__update__create_web_public_stream_policy;
|
||||
stream_settings_ui.update_stream_privacy_choices = (property) => {
|
||||
assert_same(property, "create_web_public_stream_policy");
|
||||
update_called = true;
|
||||
|
|
|
@ -263,13 +263,6 @@ exports.fixtures = {
|
|||
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: {
|
||||
type: "realm",
|
||||
op: "update",
|
||||
|
|
|
@ -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(
|
||||
"user_can_subscribe_other_users",
|
||||
"realm_invite_to_stream_policy",
|
||||
|
@ -471,3 +466,9 @@ test_realm_group_settings(
|
|||
"realm_can_create_public_channel_group",
|
||||
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,
|
||||
);
|
||||
|
|
|
@ -99,7 +99,6 @@ function test_submit_settings_form(override, submit_form) {
|
|||
realm_waiting_period_threshold: 1,
|
||||
realm_default_language: '"es"',
|
||||
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,
|
||||
});
|
||||
|
||||
|
@ -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.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");
|
||||
$add_custom_emoji_policy_elem.val("1");
|
||||
$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", [
|
||||
$bot_creation_policy_elem,
|
||||
$add_custom_emoji_policy_elem,
|
||||
$create_private_stream_policy_elem,
|
||||
$invite_to_realm_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_stream_policy: 1,
|
||||
add_custom_emoji_policy: 1,
|
||||
create_private_stream_policy: 2,
|
||||
};
|
||||
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_realm_policy");
|
||||
|
||||
|
|
Loading…
Reference in New Issue