mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	settings_config: Use a common object for different policy values.
This commit replaces different objects - create_stream_policy_values, invite_to_realm_policy_values and invite_to_stream_policy_values, with a single object common_policy_values. Though invite_to_realm_policy do not use other fields of objects like description, order, etc. but we can keep it as it is for now as we would separate this setting from "Are invitations required...." dropdown and these fields will be used then. This is a prep commit for commits that will add helper functions in settings_data for these policies replacing the usage of page_params object.
This commit is contained in:
		@@ -179,9 +179,8 @@ function test_submit_settings_form(override, submit_form) {
 | 
			
		||||
        realm_waiting_period_threshold: 1,
 | 
			
		||||
        realm_default_language: '"es"',
 | 
			
		||||
        realm_default_twenty_four_hour_time: false,
 | 
			
		||||
        realm_invite_to_stream_policy:
 | 
			
		||||
            settings_config.invite_to_stream_policy_values.by_admins_only.code,
 | 
			
		||||
        realm_create_stream_policy: settings_config.create_stream_policy_values.by_members.code,
 | 
			
		||||
        realm_invite_to_stream_policy: settings_config.common_policy_values.by_admins_only.code,
 | 
			
		||||
        realm_create_stream_policy: settings_config.common_policy_values.by_members.code,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    override(global, "setTimeout", (func) => func());
 | 
			
		||||
@@ -466,7 +465,7 @@ function test_sync_realm_settings() {
 | 
			
		||||
        settings_org.sync_realm_settings("create_stream_policy");
 | 
			
		||||
        assert.equal(
 | 
			
		||||
            $("#id_realm_create_stream_policy").val(),
 | 
			
		||||
            settings_config.create_stream_policy_values.by_full_members.code,
 | 
			
		||||
            settings_config.common_policy_values.by_full_members.code,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -484,7 +483,7 @@ function test_sync_realm_settings() {
 | 
			
		||||
        settings_org.sync_realm_settings("create_stream_policy");
 | 
			
		||||
        assert.equal(
 | 
			
		||||
            $("#id_realm_create_stream_policy").val(),
 | 
			
		||||
            settings_config.create_stream_policy_values.by_members.code,
 | 
			
		||||
            settings_config.common_policy_values.by_members.code,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -502,7 +501,7 @@ function test_sync_realm_settings() {
 | 
			
		||||
        settings_org.sync_realm_settings("create_stream_policy");
 | 
			
		||||
        assert.equal(
 | 
			
		||||
            $("#id_realm_create_stream_policy").val(),
 | 
			
		||||
            settings_config.create_stream_policy_values.by_admins_only.code,
 | 
			
		||||
            settings_config.common_policy_values.by_admins_only.code,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -520,7 +519,7 @@ function test_sync_realm_settings() {
 | 
			
		||||
        settings_org.sync_realm_settings("invite_to_stream_policy");
 | 
			
		||||
        assert.equal(
 | 
			
		||||
            $("#id_realm_invite_to_stream_policy").val(),
 | 
			
		||||
            settings_config.create_stream_policy_values.by_full_members.code,
 | 
			
		||||
            settings_config.common_policy_values.by_full_members.code,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -538,7 +537,7 @@ function test_sync_realm_settings() {
 | 
			
		||||
        settings_org.sync_realm_settings("invite_to_stream_policy");
 | 
			
		||||
        assert.equal(
 | 
			
		||||
            $("#id_realm_invite_to_stream_policy").val(),
 | 
			
		||||
            settings_config.create_stream_policy_values.by_members.code,
 | 
			
		||||
            settings_config.common_policy_values.by_members.code,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -556,7 +555,7 @@ function test_sync_realm_settings() {
 | 
			
		||||
        settings_org.sync_realm_settings("invite_to_stream_policy");
 | 
			
		||||
        assert.equal(
 | 
			
		||||
            $("#id_realm_invite_to_stream_policy").val(),
 | 
			
		||||
            settings_config.create_stream_policy_values.by_admins_only.code,
 | 
			
		||||
            settings_config.common_policy_values.by_admins_only.code,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -807,8 +806,8 @@ test("set_up", (override) => {
 | 
			
		||||
 | 
			
		||||
test("test get_organization_settings_options", () => {
 | 
			
		||||
    const sorted_option_values = settings_org.get_organization_settings_options();
 | 
			
		||||
    const sorted_create_stream_policy_values = sorted_option_values.create_stream_policy_values;
 | 
			
		||||
    const expected_create_stream_policy_values = [
 | 
			
		||||
    const sorted_common_policy_values = sorted_option_values.common_policy_values;
 | 
			
		||||
    const expected_common_policy_values = [
 | 
			
		||||
        {
 | 
			
		||||
            key: "by_admins_only",
 | 
			
		||||
            order: 1,
 | 
			
		||||
@@ -828,7 +827,7 @@ test("test get_organization_settings_options", () => {
 | 
			
		||||
            description: $t({defaultMessage: "Admins and members"}),
 | 
			
		||||
        },
 | 
			
		||||
    ];
 | 
			
		||||
    assert.deepEqual(sorted_create_stream_policy_values, expected_create_stream_policy_values);
 | 
			
		||||
    assert.deepEqual(sorted_common_policy_values, expected_common_policy_values);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test("test get_sorted_options_list", () => {
 | 
			
		||||
 
 | 
			
		||||
@@ -103,7 +103,7 @@ export const email_address_visibility_values = {
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const create_stream_policy_values = {
 | 
			
		||||
export const common_policy_values = {
 | 
			
		||||
    by_admins_only: {
 | 
			
		||||
        order: 1,
 | 
			
		||||
        code: 2,
 | 
			
		||||
@@ -121,14 +121,6 @@ export const create_stream_policy_values = {
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const invite_to_stream_policy_values = create_stream_policy_values;
 | 
			
		||||
 | 
			
		||||
export const invite_to_realm_policy_values = {
 | 
			
		||||
    by_members: 1,
 | 
			
		||||
    by_admins_only: 2,
 | 
			
		||||
    by_full_members: 3,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const user_group_edit_policy_values = {
 | 
			
		||||
    by_admins_only: {
 | 
			
		||||
        order: 1,
 | 
			
		||||
 
 | 
			
		||||
@@ -92,12 +92,7 @@ export function get_sorted_options_list(option_values_object) {
 | 
			
		||||
 | 
			
		||||
export function get_organization_settings_options() {
 | 
			
		||||
    const options = {};
 | 
			
		||||
    options.create_stream_policy_values = get_sorted_options_list(
 | 
			
		||||
        settings_config.create_stream_policy_values,
 | 
			
		||||
    );
 | 
			
		||||
    options.invite_to_stream_policy_values = get_sorted_options_list(
 | 
			
		||||
        settings_config.invite_to_stream_policy_values,
 | 
			
		||||
    );
 | 
			
		||||
    options.common_policy_values = get_sorted_options_list(settings_config.common_policy_values);
 | 
			
		||||
    options.user_group_edit_policy_values = get_sorted_options_list(
 | 
			
		||||
        settings_config.user_group_edit_policy_values,
 | 
			
		||||
    );
 | 
			
		||||
@@ -189,13 +184,13 @@ function get_property_value(property_name) {
 | 
			
		||||
        if (!page_params.realm_invite_required) {
 | 
			
		||||
            if (
 | 
			
		||||
                page_params.realm_invite_to_realm_policy ===
 | 
			
		||||
                settings_config.invite_to_realm_policy_values.by_admins_only
 | 
			
		||||
                settings_config.common_policy_values.by_admins_only.code
 | 
			
		||||
            ) {
 | 
			
		||||
                return "no_invite_required_by_admins_only";
 | 
			
		||||
            }
 | 
			
		||||
            if (
 | 
			
		||||
                page_params.realm_invite_to_realm_policy ===
 | 
			
		||||
                settings_config.invite_to_realm_policy_values.by_full_members
 | 
			
		||||
                settings_config.common_policy_values.by_full_members.code
 | 
			
		||||
            ) {
 | 
			
		||||
                return "no_invite_required_by_full_members";
 | 
			
		||||
            }
 | 
			
		||||
@@ -203,13 +198,13 @@ function get_property_value(property_name) {
 | 
			
		||||
        }
 | 
			
		||||
        if (
 | 
			
		||||
            page_params.realm_invite_to_realm_policy ===
 | 
			
		||||
            settings_config.invite_to_realm_policy_values.by_admins_only
 | 
			
		||||
            settings_config.common_policy_values.by_admins_only.code
 | 
			
		||||
        ) {
 | 
			
		||||
            return "by_admins_only";
 | 
			
		||||
        }
 | 
			
		||||
        if (
 | 
			
		||||
            page_params.realm_invite_to_realm_policy ===
 | 
			
		||||
            settings_config.invite_to_realm_policy_values.by_full_members
 | 
			
		||||
            settings_config.common_policy_values.by_full_members.code
 | 
			
		||||
        ) {
 | 
			
		||||
            return "by_full_members";
 | 
			
		||||
        }
 | 
			
		||||
@@ -838,28 +833,26 @@ export function build_page() {
 | 
			
		||||
            const user_invite_restriction = $("#id_realm_user_invite_restriction").val();
 | 
			
		||||
            if (user_invite_restriction === "no_invite_required") {
 | 
			
		||||
                data.invite_required = false;
 | 
			
		||||
                data.invite_to_realm_policy =
 | 
			
		||||
                    settings_config.invite_to_realm_policy_values.by_members;
 | 
			
		||||
                data.invite_to_realm_policy = settings_config.common_policy_values.by_members.code;
 | 
			
		||||
            } else if (user_invite_restriction === "no_invite_required_by_admins_only") {
 | 
			
		||||
                data.invite_required = false;
 | 
			
		||||
                data.invite_to_realm_policy =
 | 
			
		||||
                    settings_config.invite_to_realm_policy_values.by_admins_only;
 | 
			
		||||
                    settings_config.common_policy_values.by_admins_only.code;
 | 
			
		||||
            } else if (user_invite_restriction === "no_invite_required_by_full_members") {
 | 
			
		||||
                data.invite_required = false;
 | 
			
		||||
                data.invite_to_realm_policy =
 | 
			
		||||
                    settings_config.invite_to_realm_policy_values.by_full_members;
 | 
			
		||||
                    settings_config.common_policy_values.by_full_members.code;
 | 
			
		||||
            } else if (user_invite_restriction === "by_admins_only") {
 | 
			
		||||
                data.invite_required = true;
 | 
			
		||||
                data.invite_to_realm_policy =
 | 
			
		||||
                    settings_config.invite_to_realm_policy_values.by_admins_only;
 | 
			
		||||
                    settings_config.common_policy_values.by_admins_only.code;
 | 
			
		||||
            } else if (user_invite_restriction === "by_full_members") {
 | 
			
		||||
                data.invite_required = true;
 | 
			
		||||
                data.invite_to_realm_policy =
 | 
			
		||||
                    settings_config.invite_to_realm_policy_values.by_full_members;
 | 
			
		||||
                    settings_config.common_policy_values.by_full_members.code;
 | 
			
		||||
            } else {
 | 
			
		||||
                data.invite_required = true;
 | 
			
		||||
                data.invite_to_realm_policy =
 | 
			
		||||
                    settings_config.invite_to_realm_policy_values.by_members;
 | 
			
		||||
                data.invite_to_realm_policy = settings_config.common_policy_values.by_members.code;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            const waiting_period_threshold = $("#id_realm_waiting_period_setting").val();
 | 
			
		||||
 
 | 
			
		||||
@@ -98,13 +98,13 @@
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
                    <label for="realm_create_stream_policy" class="dropdown-title">{{t "Who can create streams" }}</label>
 | 
			
		||||
                    <select name="realm_create_stream_policy" id="id_realm_create_stream_policy" class="prop-element" data-setting-widget-type="number">
 | 
			
		||||
                        {{> dropdown_options_widget option_values=create_stream_policy_values}}
 | 
			
		||||
                        {{> dropdown_options_widget option_values=common_policy_values}}
 | 
			
		||||
                    </select>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
                    <label for="realm_invite_to_stream_policy" class="dropdown-title">{{t "Who can add users to streams" }}</label>
 | 
			
		||||
                    <select name="realm_invite_to_stream_policy" id="id_realm_invite_to_stream_policy" class="prop-element" data-setting-widget-type="number">
 | 
			
		||||
                        {{> dropdown_options_widget option_values=invite_to_stream_policy_values}}
 | 
			
		||||
                        {{> dropdown_options_widget option_values=common_policy_values}}
 | 
			
		||||
                    </select>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user