page_params: Split out state data for realm.

For spectators, the chunk of page_params that originates from
do_events_register isn’t assigned until ui_init.js.  That means the
TypeScript type of page_params is mostly a lie during module load
time: reading a parameter too early silently results in undefined
rather than the declared type, with unpredictable results later on.

We want to make such an early read into an immediate runtime error,
for both users and spectators consistently, and pave the way for
runtime validation of the page_params type.  As a second step, split
out the subset of fields that pertain to the entire realm.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-02-12 17:08:24 -08:00
committed by Tim Abbott
parent e96ede0ef6
commit b9e62c7af8
109 changed files with 1029 additions and 941 deletions

View File

@@ -19,12 +19,11 @@ import * as dropdown_widget from "./dropdown_widget";
import {$t, $t_html} from "./i18n";
import * as keydown_util from "./keydown_util";
import * as narrow_state from "./narrow_state";
import {page_params} from "./page_params";
import * as scroll_util from "./scroll_util";
import * as settings_components from "./settings_components";
import * as settings_config from "./settings_config";
import * as settings_org from "./settings_org";
import {current_user} from "./state_data";
import {current_user, realm} from "./state_data";
import * as stream_color from "./stream_color";
import * as stream_data from "./stream_data";
import * as stream_edit_subscribers from "./stream_edit_subscribers";
@@ -54,7 +53,7 @@ export function setup_subscriptions_tab_hash(tab_key_value) {
}
export function get_display_text_for_realm_message_retention_setting() {
const realm_message_retention_days = page_params.realm_message_retention_days;
const realm_message_retention_days = realm.realm_message_retention_days;
if (realm_message_retention_days === settings_config.retain_message_forever) {
return $t({defaultMessage: "(forever)"});
}
@@ -251,11 +250,10 @@ export function show_settings_for(node) {
stream_privacy_policy_values: settings_config.stream_privacy_policy_values,
stream_privacy_policy: stream_data.get_stream_privacy_policy(stream_id),
check_default_stream: stream_data.is_default_stream_id(stream_id),
zulip_plan_is_not_limited: page_params.zulip_plan_is_not_limited,
upgrade_text_for_wide_organization_logo:
page_params.upgrade_text_for_wide_organization_logo,
zulip_plan_is_not_limited: realm.zulip_plan_is_not_limited,
upgrade_text_for_wide_organization_logo: realm.upgrade_text_for_wide_organization_logo,
is_business_type_org:
page_params.realm_org_type === settings_config.all_org_type_values.business.code,
realm.realm_org_type === settings_config.all_org_type_values.business.code,
is_admin: current_user.is_admin,
org_level_message_retention_setting: get_display_text_for_realm_message_retention_setting(),
can_access_stream_email: stream_data.can_access_stream_email(sub),
@@ -439,8 +437,8 @@ export function initialize() {
const template_data = {
stream_name: stream.name,
stream_description: stream.description,
max_stream_name_length: page_params.max_stream_name_length,
max_stream_description_length: page_params.max_stream_description_length,
max_stream_name_length: realm.max_stream_name_length,
max_stream_description_length: realm.max_stream_description_length,
};
const change_stream_info_modal = render_change_stream_info_modal(template_data);
dialog_widget.launch({
@@ -608,10 +606,9 @@ export function initialize() {
const stream_name_with_privacy_symbol_html = render_inline_decorated_stream_name({stream});
const is_new_stream_notification_stream =
stream_id === page_params.realm_notifications_stream_id;
const is_new_stream_notification_stream = stream_id === realm.realm_notifications_stream_id;
const is_signup_notification_stream =
stream_id === page_params.realm_signup_notifications_stream_id;
stream_id === realm.realm_signup_notifications_stream_id;
const is_notification_stream =
is_new_stream_notification_stream || is_signup_notification_stream;