realm_user_settings_defaults: Validate parameters with Zod.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-06-21 00:44:10 -07:00
committed by Tim Abbott
parent 282ea2d77f
commit 02e236f58a
2 changed files with 61 additions and 55 deletions

View File

@@ -1,59 +1,64 @@
export type RealmDefaultSettings = { import {z} from "zod";
automatically_follow_topics_policy: number;
automatically_follow_topics_where_mentioned: boolean; import type {StateData} from "./state_data";
automatically_unmute_topics_in_muted_streams_policy: number;
color_scheme: number; export const realm_default_settings_schema = z.object({
default_language: string; automatically_follow_topics_policy: z.number(),
demote_inactive_streams: number; automatically_follow_topics_where_mentioned: z.boolean(),
dense_mode: boolean; automatically_unmute_topics_in_muted_streams_policy: z.number(),
desktop_icon_count_display: number; color_scheme: z.number(),
display_emoji_reaction_users: boolean; default_language: z.string(),
email_notifications_batching_period_seconds: number; demote_inactive_streams: z.number(),
emojiset: string; dense_mode: z.boolean(),
enable_desktop_notifications: boolean; desktop_icon_count_display: z.number(),
enable_digest_emails: boolean; display_emoji_reaction_users: z.boolean(),
enable_drafts_synchronization: boolean; email_notifications_batching_period_seconds: z.number(),
enable_followed_topic_audible_notifications: boolean; emojiset: z.string(),
enable_followed_topic_desktop_notifications: boolean; enable_desktop_notifications: z.boolean(),
enable_followed_topic_email_notifications: boolean; enable_digest_emails: z.boolean(),
enable_followed_topic_push_notifications: boolean; enable_drafts_synchronization: z.boolean(),
enable_followed_topic_wildcard_mentions_notify: boolean; enable_followed_topic_audible_notifications: z.boolean(),
enable_login_emails: boolean; enable_followed_topic_desktop_notifications: z.boolean(),
enable_marketing_emails: boolean; enable_followed_topic_email_notifications: z.boolean(),
enable_offline_email_notifications: boolean; enable_followed_topic_push_notifications: z.boolean(),
enable_offline_push_notifications: boolean; enable_followed_topic_wildcard_mentions_notify: z.boolean(),
enable_online_push_notifications: boolean; enable_login_emails: z.boolean(),
enable_sounds: boolean; enable_marketing_emails: z.boolean(),
enable_stream_audible_notifications: boolean; enable_offline_email_notifications: z.boolean(),
enable_stream_desktop_notifications: boolean; enable_offline_push_notifications: z.boolean(),
enable_stream_email_notifications: boolean; enable_online_push_notifications: z.boolean(),
enable_stream_push_notifications: boolean; enable_sounds: z.boolean(),
enter_sends: boolean; enable_stream_audible_notifications: z.boolean(),
fluid_layout_width: boolean; enable_stream_desktop_notifications: z.boolean(),
high_contrast_mode: boolean; enable_stream_email_notifications: z.boolean(),
message_content_in_email_notifications: boolean; enable_stream_push_notifications: z.boolean(),
notification_sound: string; enter_sends: z.boolean(),
pm_content_in_desktop_notifications: boolean; fluid_layout_width: z.boolean(),
presence_enabled: boolean; high_contrast_mode: z.boolean(),
realm_name_in_email_notifications_policy: number; message_content_in_email_notifications: z.boolean(),
receives_typing_notifications: boolean; notification_sound: z.string(),
send_private_typing_notifications: boolean; pm_content_in_desktop_notifications: z.boolean(),
send_stream_typing_notifications: boolean; presence_enabled: z.boolean(),
starred_message_counts: boolean; realm_name_in_email_notifications_policy: z.number(),
translate_emoticons: boolean; receives_typing_notifications: z.boolean(),
twenty_four_hour_time: boolean; send_private_typing_notifications: z.boolean(),
user_list_style: number; send_stream_typing_notifications: z.boolean(),
web_escape_navigates_to_home_view: boolean; starred_message_counts: z.boolean(),
web_font_size_px: number; translate_emoticons: z.boolean(),
web_home_view: string; twenty_four_hour_time: z.boolean(),
web_line_height_percent: number; user_list_style: z.number(),
web_mark_read_on_scroll_policy: number; web_escape_navigates_to_home_view: z.boolean(),
web_stream_unreads_count_display_policy: number; web_font_size_px: z.number(),
wildcard_mentions_notify: boolean; web_home_view: z.string(),
}; web_line_height_percent: z.number(),
web_mark_read_on_scroll_policy: z.number(),
web_stream_unreads_count_display_policy: z.number(),
wildcard_mentions_notify: z.boolean(),
});
export type RealmDefaultSettings = z.infer<typeof realm_default_settings_schema>;
export let realm_user_settings_defaults: RealmDefaultSettings; export let realm_user_settings_defaults: RealmDefaultSettings;
export function initialize(params: {realm_user_settings_defaults: RealmDefaultSettings}): void { export function initialize(params: StateData["realm_settings_defaults"]): void {
realm_user_settings_defaults = params.realm_user_settings_defaults; realm_user_settings_defaults = params.realm_user_settings_defaults;
} }

View File

@@ -1,5 +1,6 @@
import {z} from "zod"; import {z} from "zod";
import {realm_default_settings_schema} from "./realm_user_settings_defaults";
import {user_settings_schema} from "./user_settings"; import {user_settings_schema} from "./user_settings";
const NOT_TYPED_YET = z.unknown(); const NOT_TYPED_YET = z.unknown();
@@ -312,7 +313,7 @@ export const state_data_schema = z
) )
.and( .and(
z z
.object({realm_user_settings_defaults: NOT_TYPED_YET}) .object({realm_user_settings_defaults: realm_default_settings_schema})
.transform((realm_settings_defaults) => ({realm_settings_defaults})), .transform((realm_settings_defaults) => ({realm_settings_defaults})),
) )
.and( .and(