mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	settings_org: Convert module to typescript.
This commit is contained in:
		@@ -47,7 +47,7 @@ organization in Zulip). The following files are involved in the process:
 | 
				
			|||||||
- `web/templates/settings/organization_permissions_admin.hbs`: defines
 | 
					- `web/templates/settings/organization_permissions_admin.hbs`: defines
 | 
				
			||||||
  the structure of the admin permissions page (checkboxes for each organization
 | 
					  the structure of the admin permissions page (checkboxes for each organization
 | 
				
			||||||
  permission setting).
 | 
					  permission setting).
 | 
				
			||||||
- `web/src/settings_org.js`: handles organization setting form submission.
 | 
					- `web/src/settings_org.ts`: handles organization setting form submission.
 | 
				
			||||||
- `web/src/server_events_dispatch.js`: handles events coming from the server
 | 
					- `web/src/server_events_dispatch.js`: handles events coming from the server
 | 
				
			||||||
  (ex: pushing an organization change to other open browsers and updating
 | 
					  (ex: pushing an organization change to other open browsers and updating
 | 
				
			||||||
  the application's state).
 | 
					  the application's state).
 | 
				
			||||||
@@ -556,7 +556,7 @@ Then add the new form control in `web/src/admin.js`.
 | 
				
			|||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The JavaScript code for organization settings and permissions can be found in
 | 
					The JavaScript code for organization settings and permissions can be found in
 | 
				
			||||||
`web/src/settings_org.js`.
 | 
					`web/src/settings_org.ts`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
In frontend, we have split the `property_types` into three objects:
 | 
					In frontend, we have split the `property_types` into three objects:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -667,7 +667,7 @@ frontend tests: [node-based unit tests](../testing/testing-with-node.md) and
 | 
				
			|||||||
[Puppeteer end-to-end tests](../testing/testing-with-puppeteer.md).
 | 
					[Puppeteer end-to-end tests](../testing/testing-with-puppeteer.md).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
At the minimum, if you created a new function to update UI in
 | 
					At the minimum, if you created a new function to update UI in
 | 
				
			||||||
`settings_org.js`, you will need to mock that function in
 | 
					`settings_org.ts`, you will need to mock that function in
 | 
				
			||||||
`web/tests/dispatch.test.js`. Add the name of the UI
 | 
					`web/tests/dispatch.test.js`. Add the name of the UI
 | 
				
			||||||
function you created to the following object with `noop` as the value:
 | 
					function you created to the following object with `noop` as the value:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -218,7 +218,7 @@ EXEMPT_FILES = make_set(
 | 
				
			|||||||
        "web/src/settings_linkifiers.ts",
 | 
					        "web/src/settings_linkifiers.ts",
 | 
				
			||||||
        "web/src/settings_muted_users.ts",
 | 
					        "web/src/settings_muted_users.ts",
 | 
				
			||||||
        "web/src/settings_notifications.ts",
 | 
					        "web/src/settings_notifications.ts",
 | 
				
			||||||
        "web/src/settings_org.js",
 | 
					        "web/src/settings_org.ts",
 | 
				
			||||||
        "web/src/settings_panel_menu.js",
 | 
					        "web/src/settings_panel_menu.js",
 | 
				
			||||||
        "web/src/settings_playgrounds.ts",
 | 
					        "web/src/settings_playgrounds.ts",
 | 
				
			||||||
        "web/src/settings_preferences.ts",
 | 
					        "web/src/settings_preferences.ts",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@ type SettingOptionValue = {
 | 
				
			|||||||
    description: string;
 | 
					    description: string;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SettingOptionValueWithKey = SettingOptionValue & {key: string};
 | 
					export type SettingOptionValueWithKey = SettingOptionValue & {key: string};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function get_sorted_options_list(
 | 
					export function get_sorted_options_list(
 | 
				
			||||||
    option_values_object: Record<string, SettingOptionValue>,
 | 
					    option_values_object: Record<string, SettingOptionValue>,
 | 
				
			||||||
@@ -80,10 +80,13 @@ export function get_sorted_options_list(
 | 
				
			|||||||
    return options_list;
 | 
					    return options_list;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MessageTimeLimitSetting =
 | 
					export type MessageMoveTimeLimitSetting =
 | 
				
			||||||
    | "realm_message_content_edit_limit_seconds"
 | 
					 | 
				
			||||||
    | "realm_move_messages_between_streams_limit_seconds"
 | 
					 | 
				
			||||||
    | "realm_move_messages_within_stream_limit_seconds"
 | 
					    | "realm_move_messages_within_stream_limit_seconds"
 | 
				
			||||||
 | 
					    | "realm_move_messages_between_streams_limit_seconds";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type MessageTimeLimitSetting =
 | 
				
			||||||
 | 
					    | MessageMoveTimeLimitSetting
 | 
				
			||||||
 | 
					    | "realm_message_content_edit_limit_seconds"
 | 
				
			||||||
    | "realm_message_content_delete_limit_seconds";
 | 
					    | "realm_message_content_delete_limit_seconds";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function get_realm_time_limits_in_minutes(property: MessageTimeLimitSetting): string {
 | 
					export function get_realm_time_limits_in_minutes(property: MessageTimeLimitSetting): string {
 | 
				
			||||||
@@ -239,7 +242,7 @@ export const simple_dropdown_realm_settings_schema = realm_schema.pick({
 | 
				
			|||||||
    realm_edit_topic_policy: true,
 | 
					    realm_edit_topic_policy: true,
 | 
				
			||||||
    realm_org_type: true,
 | 
					    realm_org_type: true,
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
type SimpleDropdownRealmSettings = z.infer<typeof simple_dropdown_realm_settings_schema>;
 | 
					export type SimpleDropdownRealmSettings = z.infer<typeof simple_dropdown_realm_settings_schema>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function set_property_dropdown_value(
 | 
					export function set_property_dropdown_value(
 | 
				
			||||||
    property_name: keyof SimpleDropdownRealmSettings,
 | 
					    property_name: keyof SimpleDropdownRealmSettings,
 | 
				
			||||||
@@ -654,7 +657,7 @@ export function change_save_button_state($element: JQuery, state: string): void
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_input_type($input_elem: JQuery, input_type?: string): string {
 | 
					export function get_input_type($input_elem: JQuery, input_type?: string): string {
 | 
				
			||||||
    if (input_type !== undefined && ["boolean", "string", "number"].includes(input_type)) {
 | 
					    if (input_type !== undefined && ["boolean", "string", "number"].includes(input_type)) {
 | 
				
			||||||
        return input_type;
 | 
					        return input_type;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -234,7 +234,7 @@ export function set_up(settings_panel: SettingsPanel): void {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (for_realm_settings) {
 | 
					    if (for_realm_settings) {
 | 
				
			||||||
        // For the realm-level defaults page, we use the common
 | 
					        // For the realm-level defaults page, we use the common
 | 
				
			||||||
        // settings_org.js handlers, so we can return early here.
 | 
					        // settings_org.ts handlers, so we can return early here.
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -247,7 +247,7 @@ export function set_up(settings_panel: SettingsPanel): void {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (for_realm_settings) {
 | 
					    if (for_realm_settings) {
 | 
				
			||||||
        // For the realm-level defaults page, we use the common
 | 
					        // For the realm-level defaults page, we use the common
 | 
				
			||||||
        // settings_org.js handlers, so we can return early here.
 | 
					        // settings_org.ts handlers, so we can return early here.
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -88,7 +88,7 @@ export function disable_sub_setting_onchange(
 | 
				
			|||||||
    is_checked: boolean,
 | 
					    is_checked: boolean,
 | 
				
			||||||
    sub_setting_id: string,
 | 
					    sub_setting_id: string,
 | 
				
			||||||
    disable_on_uncheck: boolean,
 | 
					    disable_on_uncheck: boolean,
 | 
				
			||||||
    include_label: boolean,
 | 
					    include_label = false,
 | 
				
			||||||
): void {
 | 
					): void {
 | 
				
			||||||
    if ((is_checked && disable_on_uncheck) || (!is_checked && !disable_on_uncheck)) {
 | 
					    if ((is_checked && disable_on_uncheck) || (!is_checked && !disable_on_uncheck)) {
 | 
				
			||||||
        $(`#${CSS.escape(sub_setting_id)}`).prop("disabled", false);
 | 
					        $(`#${CSS.escape(sub_setting_id)}`).prop("disabled", false);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ export const user_group_schema = raw_user_group_schema.extend({
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
export type UserGroup = z.infer<typeof user_group_schema>;
 | 
					export type UserGroup = z.infer<typeof user_group_schema>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type UserGroupForDropdownListWidget = {
 | 
					export type UserGroupForDropdownListWidget = {
 | 
				
			||||||
    name: string;
 | 
					    name: string;
 | 
				
			||||||
    unique_id: number;
 | 
					    unique_id: number;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,6 @@ const assert = require("node:assert/strict");
 | 
				
			|||||||
const {$t} = require("./lib/i18n");
 | 
					const {$t} = require("./lib/i18n");
 | 
				
			||||||
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
 | 
					const {mock_esm, set_global, zrequire} = require("./lib/namespace");
 | 
				
			||||||
const {run_test, noop} = require("./lib/test");
 | 
					const {run_test, noop} = require("./lib/test");
 | 
				
			||||||
const blueslip = require("./lib/zblueslip");
 | 
					 | 
				
			||||||
const $ = require("./lib/zjquery");
 | 
					const $ = require("./lib/zjquery");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const realm_icon = mock_esm("../src/realm_icon");
 | 
					const realm_icon = mock_esm("../src/realm_icon");
 | 
				
			||||||
@@ -291,22 +290,12 @@ function test_sync_realm_settings({override}) {
 | 
				
			|||||||
        $.create("save-button-controls-stub").addClass("hide"),
 | 
					        $.create("save-button-controls-stub").addClass("hide"),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        /* Test invalid settings property sync */
 | 
					 | 
				
			||||||
        const $property_elem = $("#id_realm_invalid_settings_property");
 | 
					 | 
				
			||||||
        $property_elem.attr("id", "id_realm_invalid_settings_property");
 | 
					 | 
				
			||||||
        $property_elem.closest = () => $subsection_stub;
 | 
					 | 
				
			||||||
        $property_elem.length = 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        blueslip.expect("error", "Element refers to unknown property");
 | 
					 | 
				
			||||||
        settings_org.sync_realm_settings("invalid_settings_property");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    function test_common_policy(property_name) {
 | 
					    function test_common_policy(property_name) {
 | 
				
			||||||
        const $property_elem = $(`#id_realm_${CSS.escape(property_name)}`);
 | 
					        const $property_elem = $(`#id_realm_${CSS.escape(property_name)}`);
 | 
				
			||||||
        $property_elem.length = 1;
 | 
					        $property_elem.length = 1;
 | 
				
			||||||
        $property_elem.attr("id", `id_realm_${CSS.escape(property_name)}`);
 | 
					        $property_elem.attr("id", `id_realm_${CSS.escape(property_name)}`);
 | 
				
			||||||
        $property_elem.closest = () => $subsection_stub;
 | 
					        $property_elem.closest = () => $subsection_stub;
 | 
				
			||||||
 | 
					        $property_elem[0] = `#id_realm_${CSS.escape(property_name)}`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Each policy is initialized to 'by_members' and then all the values are tested
 | 
					        /* Each policy is initialized to 'by_members' and then all the values are tested
 | 
				
			||||||
        in the following order - by_admins_only, by_moderators_only, by_full_members,
 | 
					        in the following order - by_admins_only, by_moderators_only, by_full_members,
 | 
				
			||||||
@@ -338,6 +327,7 @@ function test_sync_realm_settings({override}) {
 | 
				
			|||||||
        $property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
 | 
					        $property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
 | 
				
			||||||
        $property_dropdown_elem.attr("id", "id_realm_message_content_edit_limit_seconds");
 | 
					        $property_dropdown_elem.attr("id", "id_realm_message_content_edit_limit_seconds");
 | 
				
			||||||
        $property_dropdown_elem.closest = () => $subsection_stub;
 | 
					        $property_dropdown_elem.closest = () => $subsection_stub;
 | 
				
			||||||
 | 
					        $property_dropdown_elem[0] = "#id_realm_message_content_edit_limit_seconds";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        override(realm, "realm_message_content_edit_limit_seconds", 120);
 | 
					        override(realm, "realm_message_content_edit_limit_seconds", 120);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -362,6 +352,7 @@ function test_sync_realm_settings({override}) {
 | 
				
			|||||||
        $property_elem.length = 1;
 | 
					        $property_elem.length = 1;
 | 
				
			||||||
        $property_elem.attr("id", "id_realm_org_join_restrictions");
 | 
					        $property_elem.attr("id", "id_realm_org_join_restrictions");
 | 
				
			||||||
        $property_elem.closest = () => $subsection_stub;
 | 
					        $property_elem.closest = () => $subsection_stub;
 | 
				
			||||||
 | 
					        $property_elem[0] = "#id_realm_org_join_restrictions";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        override(realm, "realm_emails_restricted_to_domains", true);
 | 
					        override(realm, "realm_emails_restricted_to_domains", true);
 | 
				
			||||||
        override(realm, "realm_disallow_disposable_email_addresses", false);
 | 
					        override(realm, "realm_disallow_disposable_email_addresses", false);
 | 
				
			||||||
@@ -529,6 +520,7 @@ test("set_up", ({override, override_rewire}) => {
 | 
				
			|||||||
            name: "BigBlueButton",
 | 
					            name: "BigBlueButton",
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					    override(realm, "realm_message_retention_days", null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let upload_realm_logo_or_icon;
 | 
					    let upload_realm_logo_or_icon;
 | 
				
			||||||
    realm_icon.build_realm_icon_widget = (f) => {
 | 
					    realm_icon.build_realm_icon_widget = (f) => {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user