page_params: Split out state data for current user.

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 first step, split
out the subset of fields that pertain to the current user.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-02-12 17:08:16 -08:00 committed by Tim Abbott
parent fd2ad130f9
commit e96ede0ef6
98 changed files with 526 additions and 438 deletions

View File

@ -546,7 +546,7 @@ Then add the new form control in `web/src/admin.js`.
export function build_page() { export function build_page() {
const options = { const options = {
custom_profile_field_types: page_params.custom_profile_field_types, custom_profile_field_types: page_params.custom_profile_field_types,
full_name: page_params.full_name, full_name: current_user.full_name,
realm_name: page_params.realm_name, realm_name: page_params.realm_name,
// ... // ...
+ realm_mandatory_topics: page_params.realm_mandatory_topics, + realm_mandatory_topics: page_params.realm_mandatory_topics,

View File

@ -224,6 +224,7 @@ EXEMPT_FILES = make_set(
"web/src/spectators.ts", "web/src/spectators.ts",
"web/src/spoilers.ts", "web/src/spoilers.ts",
"web/src/starred_messages_ui.js", "web/src/starred_messages_ui.js",
"web/src/state_data.ts",
"web/src/stream_color.ts", "web/src/stream_color.ts",
"web/src/stream_color_events.js", "web/src/stream_color_events.js",
"web/src/stream_create.js", "web/src/stream_create.js",

View File

@ -20,6 +20,7 @@ import * as settings_panel_menu from "./settings_panel_menu";
import * as settings_sections from "./settings_sections"; import * as settings_sections from "./settings_sections";
import * as settings_toggle from "./settings_toggle"; import * as settings_toggle from "./settings_toggle";
import * as settings_users from "./settings_users"; import * as settings_users from "./settings_users";
import {current_user} from "./state_data";
const admin_settings_label = { const admin_settings_label = {
// Organization profile // Organization profile
@ -70,10 +71,10 @@ const admin_settings_label = {
}; };
function insert_tip_box() { function insert_tip_box() {
if (page_params.is_admin) { if (current_user.is_admin) {
return; return;
} }
const tip_box = render_settings_organization_settings_tip({is_admin: page_params.is_admin}); const tip_box = render_settings_organization_settings_tip({is_admin: current_user.is_admin});
$(".organization-box") $(".organization-box")
.find(".settings-section") .find(".settings-section")
.not("#emoji-settings") .not("#emoji-settings")
@ -102,7 +103,7 @@ function get_realm_level_notification_settings(options) {
export function build_page() { export function build_page() {
const options = { const options = {
custom_profile_field_types: page_params.custom_profile_field_types, custom_profile_field_types: page_params.custom_profile_field_types,
full_name: page_params.full_name, full_name: current_user.full_name,
realm_name: page_params.realm_name, realm_name: page_params.realm_name,
realm_org_type: page_params.realm_org_type, realm_org_type: page_params.realm_org_type,
realm_available_video_chat_providers: page_params.realm_available_video_chat_providers, realm_available_video_chat_providers: page_params.realm_available_video_chat_providers,
@ -138,9 +139,9 @@ export function build_page() {
realm_waiting_period_threshold: page_params.realm_waiting_period_threshold, realm_waiting_period_threshold: page_params.realm_waiting_period_threshold,
realm_notifications_stream_id: page_params.realm_notifications_stream_id, realm_notifications_stream_id: page_params.realm_notifications_stream_id,
realm_signup_notifications_stream_id: page_params.realm_signup_notifications_stream_id, realm_signup_notifications_stream_id: page_params.realm_signup_notifications_stream_id,
is_admin: page_params.is_admin, is_admin: current_user.is_admin,
is_guest: page_params.is_guest, is_guest: current_user.is_guest,
is_owner: page_params.is_owner, is_owner: current_user.is_owner,
user_can_change_logo: settings_data.user_can_change_logo(), user_can_change_logo: settings_data.user_can_change_logo(),
realm_icon_source: page_params.realm_icon_source, realm_icon_source: page_params.realm_icon_source,
realm_icon_url: page_params.realm_icon_url, realm_icon_url: page_params.realm_icon_url,
@ -244,7 +245,7 @@ export function build_page() {
settings_invites.update_invite_user_panel(); settings_invites.update_invite_user_panel();
insert_tip_box(); insert_tip_box();
if (page_params.demo_organization_scheduled_deletion_date && page_params.is_admin) { if (page_params.demo_organization_scheduled_deletion_date && current_user.is_admin) {
demo_organizations_ui.insert_demo_organization_warning(); demo_organizations_ui.insert_demo_organization_warning();
demo_organizations_ui.handle_demo_organization_conversion(); demo_organizations_ui.handle_demo_organization_conversion();
} }
@ -255,7 +256,7 @@ export function build_page() {
const is_plan_plus = page_params.realm_plan_type === 10; const is_plan_plus = page_params.realm_plan_type === 10;
const is_plan_self_hosted = page_params.realm_plan_type === 1; const is_plan_self_hosted = page_params.realm_plan_type === 1;
if (page_params.is_admin && !(is_plan_plus || is_plan_self_hosted)) { if (current_user.is_admin && !(is_plan_plus || is_plan_self_hosted)) {
$("#realm_can_access_all_users_group_widget").prop("disabled", true); $("#realm_can_access_all_users_group_widget").prop("disabled", true);
const opts = { const opts = {
content: $t({ content: $t({

View File

@ -7,6 +7,7 @@ import * as confirm_dialog from "./confirm_dialog";
import {$t_html} from "./i18n"; import {$t_html} from "./i18n";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as upload_widget from "./upload_widget"; import * as upload_widget from "./upload_widget";
import type {UploadFunction, UploadWidget} from "./upload_widget"; import type {UploadFunction, UploadWidget} from "./upload_widget";
@ -75,7 +76,7 @@ export function build_user_avatar_widget(upload_function: UploadFunction): void
return $<HTMLInputElement>("#user-avatar-upload-widget input.image_file_input").expectOne(); return $<HTMLInputElement>("#user-avatar-upload-widget input.image_file_input").expectOne();
}; };
if (page_params.avatar_source === "G") { if (current_user.avatar_source === "G") {
$("#user-avatar-upload-widget .image-delete-button").hide(); $("#user-avatar-upload-widget .image-delete-button").hide();
$("#user-avatar-source").show(); $("#user-avatar-source").show();
} else { } else {

View File

@ -20,12 +20,12 @@ import * as loading from "./loading";
import * as markdown from "./markdown"; import * as markdown from "./markdown";
import * as message_events from "./message_events"; import * as message_events from "./message_events";
import * as onboarding_steps from "./onboarding_steps"; import * as onboarding_steps from "./onboarding_steps";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as rendered_markdown from "./rendered_markdown"; import * as rendered_markdown from "./rendered_markdown";
import * as scheduled_messages from "./scheduled_messages"; import * as scheduled_messages from "./scheduled_messages";
import * as sent_messages from "./sent_messages"; import * as sent_messages from "./sent_messages";
import * as server_events from "./server_events"; import * as server_events from "./server_events";
import {current_user} from "./state_data";
import * as transmit from "./transmit"; import * as transmit from "./transmit";
import {user_settings} from "./user_settings"; import {user_settings} from "./user_settings";
import * as util from "./util"; import * as util from "./util";
@ -89,7 +89,7 @@ export function create_message_object() {
const message = { const message = {
type: compose_state.get_message_type(), type: compose_state.get_message_type(),
content: compose_state.message_content(), content: compose_state.message_content(),
sender_id: page_params.user_id, sender_id: current_user.user_id,
queue_id: server_events.queue_id, queue_id: server_events.queue_id,
stream_id: undefined, stream_id: undefined,
}; };
@ -332,7 +332,7 @@ export function render_and_show_preview($preview_spinner, $preview_content_box,
// Handle previews of /me messages // Handle previews of /me messages
rendered_preview_html = rendered_preview_html =
"<p><strong>" + "<p><strong>" +
_.escape(page_params.full_name) + _.escape(current_user.full_name) +
"</strong>" + "</strong>" +
rendered_content.slice("<p>/me".length); rendered_content.slice("<p>/me".length);
} else { } else {

View File

@ -7,6 +7,7 @@ import * as compose_ui from "./compose_ui";
import {$t, $t_html} from "./i18n"; import {$t, $t_html} from "./i18n";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as rows from "./rows"; import * as rows from "./rows";
import {current_user} from "./state_data";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as util from "./util"; import * as util from "./util";
@ -79,7 +80,7 @@ export function generate_and_insert_audio_or_video_call_link($target_element, is
xhr.responseJSON && xhr.responseJSON &&
xhr.responseJSON.code === "INVALID_ZOOM_TOKEN" xhr.responseJSON.code === "INVALID_ZOOM_TOKEN"
) { ) {
page_params.has_zoom_token = false; current_user.has_zoom_token = false;
} }
if (status !== "abort") { if (status !== "abort") {
ui_report.generic_embed_error( ui_report.generic_embed_error(
@ -91,7 +92,7 @@ export function generate_and_insert_audio_or_video_call_link($target_element, is
); );
}; };
if (page_params.has_zoom_token) { if (current_user.has_zoom_token) {
make_zoom_call(); make_zoom_call();
} else { } else {
compose_call.zoom_token_callbacks.set(key, make_zoom_call); compose_call.zoom_token_callbacks.set(key, make_zoom_call);

View File

@ -23,6 +23,7 @@ import * as reactions from "./reactions";
import * as recent_senders from "./recent_senders"; import * as recent_senders from "./recent_senders";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import * as util from "./util"; import * as util from "./util";
@ -481,31 +482,31 @@ function wildcard_mention_policy_authorizes_user() {
page_params.realm_wildcard_mention_policy === page_params.realm_wildcard_mention_policy ===
settings_config.wildcard_mention_policy_values.by_admins_only.code settings_config.wildcard_mention_policy_values.by_admins_only.code
) { ) {
return page_params.is_admin; return current_user.is_admin;
} }
if ( if (
page_params.realm_wildcard_mention_policy === page_params.realm_wildcard_mention_policy ===
settings_config.wildcard_mention_policy_values.by_moderators_only.code settings_config.wildcard_mention_policy_values.by_moderators_only.code
) { ) {
return page_params.is_admin || page_params.is_moderator; return current_user.is_admin || current_user.is_moderator;
} }
if ( if (
page_params.realm_wildcard_mention_policy === page_params.realm_wildcard_mention_policy ===
settings_config.wildcard_mention_policy_values.by_full_members.code settings_config.wildcard_mention_policy_values.by_full_members.code
) { ) {
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
const person = people.get_by_user_id(page_params.user_id); const person = people.get_by_user_id(current_user.user_id);
const current_datetime = new Date(Date.now()); const current_datetime = new Date(Date.now());
const person_date_joined = new Date(person.date_joined); const person_date_joined = new Date(person.date_joined);
const days = (current_datetime - person_date_joined) / 1000 / 86400; const days = (current_datetime - person_date_joined) / 1000 / 86400;
return days >= page_params.realm_waiting_period_threshold && !page_params.is_guest; return days >= page_params.realm_waiting_period_threshold && !current_user.is_guest;
} }
return !page_params.is_guest; return !current_user.is_guest;
} }
export function stream_wildcard_mention_allowed() { export function stream_wildcard_mention_allowed() {

View File

@ -12,12 +12,13 @@ import {page_params} from "./page_params";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
import {current_user} from "./state_data";
export function insert_demo_organization_warning() { export function insert_demo_organization_warning() {
const days_remaining = get_demo_organization_deadline_days_remaining(); const days_remaining = get_demo_organization_deadline_days_remaining();
const rendered_demo_organization_warning = render_demo_organization_warning({ const rendered_demo_organization_warning = render_demo_organization_warning({
is_demo_organization: page_params.demo_organization_scheduled_deletion_date, is_demo_organization: page_params.demo_organization_scheduled_deletion_date,
is_owner: page_params.is_owner, is_owner: current_user.is_owner,
days_remaining, days_remaining,
}); });
$(".organization-box").find(".settings-section").prepend(rendered_demo_organization_warning); $(".organization-box").find(".settings-section").prepend(rendered_demo_organization_warning);
@ -25,7 +26,7 @@ export function insert_demo_organization_warning() {
export function handle_demo_organization_conversion() { export function handle_demo_organization_conversion() {
$(".convert-demo-organization-button").on("click", () => { $(".convert-demo-organization-button").on("click", () => {
if (!page_params.is_owner) { if (!current_user.is_owner) {
return; return;
} }

View File

@ -12,12 +12,12 @@ import * as message_lists from "./message_lists";
import * as message_live_update from "./message_live_update"; import * as message_live_update from "./message_live_update";
import * as message_store from "./message_store"; import * as message_store from "./message_store";
import * as narrow_state from "./narrow_state"; import * as narrow_state from "./narrow_state";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as pm_list from "./pm_list"; import * as pm_list from "./pm_list";
import * as recent_view_data from "./recent_view_data"; import * as recent_view_data from "./recent_view_data";
import * as rows from "./rows"; import * as rows from "./rows";
import * as sent_messages from "./sent_messages"; import * as sent_messages from "./sent_messages";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_list from "./stream_list"; import * as stream_list from "./stream_list";
import * as stream_topic_history from "./stream_topic_history"; import * as stream_topic_history from "./stream_topic_history";
@ -185,7 +185,7 @@ export function insert_local_message(message_request, local_id_float, insert_new
message.content_type = "text/html"; message.content_type = "text/html";
message.sender_email = people.my_current_email(); message.sender_email = people.my_current_email();
message.sender_full_name = people.my_full_name(); message.sender_full_name = people.my_full_name();
message.avatar_url = page_params.avatar_url; message.avatar_url = current_user.avatar_url;
message.timestamp = Date.now() / 1000; message.timestamp = Date.now() / 1000;
message.local_id = local_id_float.toString(); message.local_id = local_id_float.toString();
message.locally_echoed = true; message.locally_echoed = true;

View File

@ -27,6 +27,7 @@ import * as settings_panel_menu from "./settings_panel_menu";
import * as settings_toggle from "./settings_toggle"; import * as settings_toggle from "./settings_toggle";
import * as sidebar_ui from "./sidebar_ui"; import * as sidebar_ui from "./sidebar_ui";
import * as spectators from "./spectators"; import * as spectators from "./spectators";
import {current_user} from "./state_data";
import * as stream_settings_ui from "./stream_settings_ui"; import * as stream_settings_ui from "./stream_settings_ui";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as user_group_edit from "./user_group_edit"; import * as user_group_edit from "./user_group_edit";
@ -213,7 +214,7 @@ function do_hashchange_overlay(old_hash) {
const old_base = hash_parser.get_hash_category(old_hash); const old_base = hash_parser.get_hash_category(old_hash);
let section = hash_parser.get_current_hash_section(); let section = hash_parser.get_current_hash_section();
if (base === "groups" && page_params.is_guest) { if (base === "groups" && current_user.is_guest) {
// The #groups settings page is unfinished, and disabled in production. // The #groups settings page is unfinished, and disabled in production.
show_home_view(); show_home_view();
return; return;

View File

@ -9,7 +9,7 @@ import * as blueslip from "./blueslip";
import * as message_viewport from "./message_viewport"; import * as message_viewport from "./message_viewport";
import * as onboarding_steps from "./onboarding_steps"; import * as onboarding_steps from "./onboarding_steps";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import {page_params} from "./page_params"; import {current_user} from "./state_data";
// popover orientations // popover orientations
const TOP = "top"; const TOP = "top";
@ -336,7 +336,7 @@ export function load_new(new_hotspots) {
} }
export function initialize() { export function initialize() {
load_new(onboarding_steps.filter_new_hotspots(page_params.onboarding_steps)); load_new(onboarding_steps.filter_new_hotspots(current_user.onboarding_steps));
// open // open
$("body").on("click", ".hotspot-icon", function (e) { $("body").on("click", ".hotspot-icon", function (e) {

View File

@ -21,6 +21,7 @@ import {page_params} from "./page_params";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
@ -161,10 +162,10 @@ function submit_invitation_form(): void {
const error_response = render_invitation_failed_error({ const error_response = render_invitation_failed_error({
error_message: response_body.msg, error_message: response_body.msg,
error_list, error_list,
is_admin: page_params.is_admin, is_admin: current_user.is_admin,
is_invitee_deactivated, is_invitee_deactivated,
license_limit_reached: response_body.license_limit_reached, license_limit_reached: response_body.license_limit_reached,
has_billing_access: page_params.is_owner || page_params.is_billing_admin, has_billing_access: current_user.is_owner || current_user.is_billing_admin,
daily_limit_reached: response_body.daily_limit_reached, daily_limit_reached: response_body.daily_limit_reached,
}); });
ui_report.message(error_response, $invite_status, "alert-warning"); ui_report.message(error_response, $invite_status, "alert-warning");
@ -310,8 +311,8 @@ function open_invite_user_modal(e: JQuery.ClickEvent<Document, undefined>): void
const time_unit_choices = ["minutes", "hours", "days", "weeks"]; const time_unit_choices = ["minutes", "hours", "days", "weeks"];
const html_body = render_invite_user_modal({ const html_body = render_invite_user_modal({
is_admin: page_params.is_admin, is_admin: current_user.is_admin,
is_owner: page_params.is_owner, is_owner: current_user.is_owner,
development_environment: page_params.development_environment, development_environment: page_params.development_environment,
invite_as_options: settings_config.user_role_values, invite_as_options: settings_config.user_role_values,
expires_in_options: settings_config.expires_in_values, expires_in_options: settings_config.expires_in_values,

View File

@ -37,6 +37,7 @@ import * as people from "./people";
import * as resize from "./resize"; import * as resize from "./resize";
import * as rows from "./rows"; import * as rows from "./rows";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
@ -70,7 +71,7 @@ export function is_topic_editable(message, edit_limit_seconds_buffer = 0) {
// Organization admins and moderators can edit message topics indefinitely, // Organization admins and moderators can edit message topics indefinitely,
// irrespective of the topic editing deadline, if edit_topic_policy allows // irrespective of the topic editing deadline, if edit_topic_policy allows
// them to do so. // them to do so.
if (page_params.is_admin || page_params.is_moderator) { if (current_user.is_admin || current_user.is_moderator) {
return true; return true;
} }
@ -167,7 +168,7 @@ export function is_message_sent_by_my_bot(message) {
} }
export function get_deletability(message) { export function get_deletability(message) {
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
@ -212,7 +213,7 @@ export function is_stream_editable(message, edit_limit_seconds_buffer = 0) {
// Organization admins and moderators can edit stream indefinitely, // Organization admins and moderators can edit stream indefinitely,
// irrespective of the stream editing deadline, if // irrespective of the stream editing deadline, if
// move_messages_between_streams_policy allows them to do so. // move_messages_between_streams_policy allows them to do so.
if (page_params.is_admin || page_params.is_moderator) { if (current_user.is_admin || current_user.is_moderator) {
return true; return true;
} }

View File

@ -3,7 +3,7 @@ import {FetchStatus} from "./fetch_status";
import type {Filter} from "./filter"; import type {Filter} from "./filter";
import type {Message} from "./message_store"; import type {Message} from "./message_store";
import * as muted_users from "./muted_users"; import * as muted_users from "./muted_users";
import {page_params} from "./page_params"; import {current_user} from "./state_data";
import * as unread from "./unread"; import * as unread from "./unread";
import * as user_topics from "./user_topics"; import * as user_topics from "./user_topics";
import * as util from "./util"; import * as util from "./util";
@ -605,7 +605,9 @@ export class MessageListData {
} }
get_last_message_sent_by_me(): Message | undefined { get_last_message_sent_by_me(): Message | undefined {
const msg_index = this._items.findLastIndex((msg) => msg.sender_id === page_params.user_id); const msg_index = this._items.findLastIndex(
(msg) => msg.sender_id === current_user.user_id,
);
if (msg_index === -1) { if (msg_index === -1) {
return undefined; return undefined;
} }

View File

@ -14,6 +14,7 @@ import * as desktop_notifications from "./desktop_notifications";
import * as keydown_util from "./keydown_util"; import * as keydown_util from "./keydown_util";
import {localstorage} from "./localstorage"; import {localstorage} from "./localstorage";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import {current_user} from "./state_data";
import {should_display_profile_incomplete_alert} from "./timerender"; import {should_display_profile_incomplete_alert} from "./timerender";
import * as unread from "./unread"; import * as unread from "./unread";
import * as unread_ops from "./unread_ops"; import * as unread_ops from "./unread_ops";
@ -77,7 +78,7 @@ export function dismiss_upgrade_nag(ls) {
} }
export function check_profile_incomplete() { export function check_profile_incomplete() {
if (!page_params.is_admin) { if (!current_user.is_admin) {
return false; return false;
} }
if (!should_display_profile_incomplete_alert(page_params.realm_date_created)) { if (!should_display_profile_incomplete_alert(page_params.realm_date_created)) {
@ -141,7 +142,7 @@ export function initialize() {
rendered_alert_content_html: render_server_needs_upgrade_alert_content(), rendered_alert_content_html: render_server_needs_upgrade_alert_content(),
}); });
} }
} else if (page_params.warn_no_email === true && page_params.is_admin) { } else if (page_params.warn_no_email === true && current_user.is_admin) {
// if email has not been set up and the user is the admin, // if email has not been set up and the user is the admin,
// display a warning to tell them to set up an email server. // display a warning to tell them to set up an email server.
open({ open({

View File

@ -1,6 +1,6 @@
import * as blueslip from "./blueslip"; import * as blueslip from "./blueslip";
import * as channel from "./channel"; import * as channel from "./channel";
import {page_params} from "./page_params"; import {current_user} from "./state_data";
export const ONE_TIME_NOTICES_TO_DISPLAY = new Set(); export const ONE_TIME_NOTICES_TO_DISPLAY = new Set();
@ -35,5 +35,5 @@ export function update_notice_to_display(onboarding_steps) {
} }
export function initialize() { export function initialize() {
update_notice_to_display(page_params.onboarding_steps); update_notice_to_display(current_user.onboarding_steps);
} }

View File

@ -6,7 +6,6 @@ import type {GroupPermissionSetting} from "./types";
const t1 = performance.now(); const t1 = performance.now();
export const page_params: { export const page_params: {
apps_page_url: string; apps_page_url: string;
avatar_source: string;
bot_types: { bot_types: {
type_id: number; type_id: number;
name: string; name: string;
@ -56,14 +55,8 @@ export const page_params: {
name: string; name: string;
}; };
}; };
delivery_email: string;
development_environment: boolean; development_environment: boolean;
furthest_read_time: number | null; furthest_read_time: number | null;
is_admin: boolean;
is_billing_admin: boolean;
is_guest: boolean;
is_moderator: boolean;
is_owner: boolean;
is_spectator: boolean; is_spectator: boolean;
language_list: { language_list: {
code: string; code: string;
@ -150,7 +143,6 @@ export const page_params: {
sponsorship_pending: boolean; sponsorship_pending: boolean;
stop_words: string[]; stop_words: string[];
translation_data: Record<string, string>; translation_data: Record<string, string>;
user_id: number;
zulip_merge_base: string; zulip_merge_base: string;
zulip_plan_is_not_limited: boolean; zulip_plan_is_not_limited: boolean;
zulip_version: string; zulip_version: string;

View File

@ -13,6 +13,7 @@ import {page_params} from "./page_params";
import * as reload_state from "./reload_state"; import * as reload_state from "./reload_state";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import {user_settings} from "./user_settings"; import {user_settings} from "./user_settings";
import * as util from "./util"; import * as util from "./util";
@ -190,7 +191,7 @@ export function get_bot_owner_user(user: User & {is_bot: true}): User | undefine
export function can_admin_user(user: User): boolean { export function can_admin_user(user: User): boolean {
return ( return (
(user.is_bot && user.bot_owner_id !== null && user.bot_owner_id === page_params.user_id) || (user.is_bot && user.bot_owner_id !== null && user.bot_owner_id === current_user.user_id) ||
is_my_user_id(user.user_id) is_my_user_id(user.user_id)
); );
} }
@ -978,7 +979,7 @@ export function is_active_user_for_popover(user_id: number): boolean {
} }
export function is_current_user_only_owner(): boolean { export function is_current_user_only_owner(): boolean {
if (!page_params.is_owner) { if (!current_user.is_owner) {
return false; return false;
} }

View File

@ -4,11 +4,11 @@ import tippy from "tippy.js";
import render_personal_menu from "../templates/personal_menu.hbs"; import render_personal_menu from "../templates/personal_menu.hbs";
import * as narrow from "./narrow"; import * as narrow from "./narrow";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as popover_menus from "./popover_menus"; import * as popover_menus from "./popover_menus";
import * as popover_menus_data from "./popover_menus_data"; import * as popover_menus_data from "./popover_menus_data";
import * as popovers from "./popovers"; import * as popovers from "./popovers";
import {current_user} from "./state_data";
import {parse_html} from "./ui_util"; import {parse_html} from "./ui_util";
import * as user_profile from "./user_profile"; import * as user_profile from "./user_profile";
import * as user_status from "./user_status"; import * as user_status from "./user_status";
@ -47,7 +47,7 @@ export function initialize() {
$popper.one("click", ".personal-menu-clear-status", (e) => { $popper.one("click", ".personal-menu-clear-status", (e) => {
e.preventDefault(); e.preventDefault();
const me = page_params.user_id; const me = current_user.user_id;
user_status.server_update_status({ user_status.server_update_status({
user_id: me, user_id: me,
status_text: "", status_text: "",
@ -68,7 +68,7 @@ export function initialize() {
}); });
$popper.one("click", ".narrow-self-direct-message", (e) => { $popper.one("click", ".narrow-self-direct-message", (e) => {
const user_id = page_params.user_id; const user_id = current_user.user_id;
const email = people.get_by_user_id(user_id).email; const email = people.get_by_user_id(user_id).email;
narrow.by("dm", email, {trigger: "personal menu"}); narrow.by("dm", email, {trigger: "personal menu"});
popovers.hide_all(); popovers.hide_all();
@ -76,7 +76,7 @@ export function initialize() {
}); });
$popper.one("click", ".narrow-messages-sent", (e) => { $popper.one("click", ".narrow-messages-sent", (e) => {
const user_id = page_params.user_id; const user_id = current_user.user_id;
const email = people.get_by_user_id(user_id).email; const email = people.get_by_user_id(user_id).email;
narrow.by("sender", email, {trigger: "personal menu"}); narrow.by("sender", email, {trigger: "personal menu"});
popovers.hide_all(); popovers.hide_all();

View File

@ -14,6 +14,7 @@ import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as starred_messages from "./starred_messages"; import * as starred_messages from "./starred_messages";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import {num_unread_for_topic} from "./unread"; import {num_unread_for_topic} from "./unread";
@ -132,7 +133,7 @@ export function get_topic_popover_content_context({stream_id, topic_name, url})
topic_unmuted, topic_unmuted,
can_move_topic, can_move_topic,
can_rename_topic, can_rename_topic,
is_realm_admin: page_params.is_admin, is_realm_admin: current_user.is_admin,
topic_is_resolved: resolved_topic.is_resolved(topic_name), topic_is_resolved: resolved_topic.is_resolved(topic_name),
has_starred_messages, has_starred_messages,
has_unread_messages, has_unread_messages,
@ -158,22 +159,22 @@ export function get_change_visibility_policy_popover_content_context(stream_id,
} }
export function get_personal_menu_content_context() { export function get_personal_menu_content_context() {
const my_user_id = page_params.user_id; const my_user_id = current_user.user_id;
const invisible_mode = !user_settings.presence_enabled; const invisible_mode = !user_settings.presence_enabled;
const status_text = user_status.get_status_text(my_user_id); const status_text = user_status.get_status_text(my_user_id);
const status_emoji_info = user_status.get_status_emoji(my_user_id); const status_emoji_info = user_status.get_status_emoji(my_user_id);
return { return {
user_id: my_user_id, user_id: my_user_id,
invisible_mode, invisible_mode,
user_is_guest: page_params.is_guest, user_is_guest: current_user.is_guest,
spectator_view: page_params.is_spectator, spectator_view: page_params.is_spectator,
// user information // user information
user_avatar: page_params.avatar_url_medium, user_avatar: current_user.avatar_url_medium,
is_active: people.is_active_user_for_popover(my_user_id), is_active: people.is_active_user_for_popover(my_user_id),
user_circle_class: buddy_data.get_user_circle_class(my_user_id), user_circle_class: buddy_data.get_user_circle_class(my_user_id),
user_last_seen_time_status: buddy_data.user_last_seen_time_status(my_user_id), user_last_seen_time_status: buddy_data.user_last_seen_time_status(my_user_id),
user_full_name: page_params.full_name, user_full_name: current_user.full_name,
user_type: people.get_user_type(my_user_id), user_type: people.get_user_type(my_user_id),
// user status // user status
@ -186,15 +187,15 @@ export function get_personal_menu_content_context() {
} }
export function get_gear_menu_content_context() { export function get_gear_menu_content_context() {
const user_has_billing_access = page_params.is_billing_admin || page_params.is_owner; const user_has_billing_access = current_user.is_billing_admin || current_user.is_owner;
const is_plan_standard = page_params.realm_plan_type === 3; const is_plan_standard = page_params.realm_plan_type === 3;
const is_plan_plus = page_params.realm_plan_type === 10; const is_plan_plus = page_params.realm_plan_type === 10;
const is_org_on_paid_plan = is_plan_standard || is_plan_plus; const is_org_on_paid_plan = is_plan_standard || is_plan_plus;
return { return {
realm_name: page_params.realm_name, realm_name: page_params.realm_name,
realm_url: new URL(page_params.realm_uri).hostname, realm_url: new URL(page_params.realm_uri).hostname,
is_owner: page_params.is_owner, is_owner: current_user.is_owner,
is_admin: page_params.is_admin, is_admin: current_user.is_admin,
is_spectator: page_params.is_spectator, is_spectator: page_params.is_spectator,
is_self_hosted: page_params.realm_plan_type === 1, is_self_hosted: page_params.realm_plan_type === 1,
is_development_environment: page_params.development_environment, is_development_environment: page_params.development_environment,
@ -211,7 +212,7 @@ export function get_gear_menu_content_context() {
apps_page_url: page_params.apps_page_url, apps_page_url: page_params.apps_page_url,
can_create_multiuse_invite: settings_data.user_can_create_multiuse_invite(), can_create_multiuse_invite: settings_data.user_can_create_multiuse_invite(),
can_invite_users_by_email: settings_data.user_can_invite_users_by_email(), can_invite_users_by_email: settings_data.user_can_invite_users_by_email(),
is_guest: page_params.is_guest, is_guest: current_user.is_guest,
login_link: page_params.development_environment ? "/devlogin/" : "/login/", login_link: page_params.development_environment ? "/devlogin/" : "/login/",
promote_sponsoring_zulip: page_params.promote_sponsoring_zulip, promote_sponsoring_zulip: page_params.promote_sponsoring_zulip,
show_billing: page_params.show_billing, show_billing: page_params.show_billing,

View File

@ -11,6 +11,7 @@ import * as message_store from "./message_store";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as spectators from "./spectators"; import * as spectators from "./spectators";
import {current_user} from "./state_data";
import {user_settings} from "./user_settings"; import {user_settings} from "./user_settings";
const waiting_for_server_request_ids = new Set(); const waiting_for_server_request_ids = new Set();
@ -23,7 +24,7 @@ export function current_user_has_reacted_to_emoji(message, local_id) {
set_clean_reactions(message); set_clean_reactions(message);
const clean_reaction_object = message.clean_reactions.get(local_id); const clean_reaction_object = message.clean_reactions.get(local_id);
return clean_reaction_object && clean_reaction_object.user_ids.includes(page_params.user_id); return clean_reaction_object && clean_reaction_object.user_ids.includes(current_user.user_id);
} }
function get_message(message_id) { function get_message(message_id) {
@ -40,7 +41,7 @@ function get_message(message_id) {
function create_reaction(message_id, rendering_details) { function create_reaction(message_id, rendering_details) {
return { return {
message_id, message_id,
user_id: page_params.user_id, user_id: current_user.user_id,
local_id: get_local_reaction_id(rendering_details), local_id: get_local_reaction_id(rendering_details),
reaction_type: rendering_details.reaction_type, reaction_type: rendering_details.reaction_type,
emoji_name: rendering_details.emoji_name, emoji_name: rendering_details.emoji_name,
@ -143,7 +144,7 @@ export function process_reaction_click(message_id, local_id) {
function generate_title(emoji_name, user_ids) { function generate_title(emoji_name, user_ids) {
const usernames = people.get_display_full_names( const usernames = people.get_display_full_names(
user_ids.filter((user_id) => user_id !== page_params.user_id), user_ids.filter((user_id) => user_id !== current_user.user_id),
); );
const current_user_reacted = user_ids.length !== usernames.length; const current_user_reacted = user_ids.length !== usernames.length;
@ -278,7 +279,7 @@ export function update_existing_reaction(clean_reaction_object, message, acting_
); );
$reaction.attr("aria-label", new_label); $reaction.attr("aria-label", new_label);
if (acting_user_id === page_params.user_id) { if (acting_user_id === current_user.user_id) {
$reaction.addClass("reacted"); $reaction.addClass("reacted");
} }
@ -308,7 +309,7 @@ export function insert_new_reaction(clean_reaction_object, message, user_id) {
context.reaction_type === "realm_emoji" || context.reaction_type === "zulip_extra_emoji"; context.reaction_type === "realm_emoji" || context.reaction_type === "zulip_extra_emoji";
context.vote_text = ""; // Updated below context.vote_text = ""; // Updated below
if (user_id === page_params.user_id) { if (user_id === current_user.user_id) {
context.class = "message_reaction reacted"; context.class = "message_reaction reacted";
} else { } else {
context.class = "message_reaction"; context.class = "message_reaction";
@ -380,7 +381,7 @@ export function remove_reaction_from_view(clean_reaction_object, message, user_i
clean_reaction_object.user_ids, clean_reaction_object.user_ids,
); );
$reaction.attr("aria-label", new_label); $reaction.attr("aria-label", new_label);
if (user_id === page_params.user_id) { if (user_id === current_user.user_id) {
$reaction.removeClass("reacted"); $reaction.removeClass("reacted");
} }
@ -388,7 +389,7 @@ export function remove_reaction_from_view(clean_reaction_object, message, user_i
} }
export function get_emojis_used_by_user_for_message_id(message_id) { export function get_emojis_used_by_user_for_message_id(message_id) {
const user_id = page_params.user_id; const user_id = current_user.user_id;
const message = message_store.get(message_id); const message = message_store.get(message_id);
set_clean_reactions(message); set_clean_reactions(message);
@ -509,7 +510,7 @@ export function update_user_fields(clean_reaction_object, should_display_reactor
clean_reaction_object.emoji_name, clean_reaction_object.emoji_name,
clean_reaction_object.user_ids, clean_reaction_object.user_ids,
); );
if (clean_reaction_object.user_ids.includes(page_params.user_id)) { if (clean_reaction_object.user_ids.includes(current_user.user_id)) {
clean_reaction_object.class = "message_reaction reacted"; clean_reaction_object.class = "message_reaction reacted";
} else { } else {
clean_reaction_object.class = "message_reaction"; clean_reaction_object.class = "message_reaction";
@ -549,10 +550,10 @@ function check_should_display_reactors(cleaned_reactions) {
function comma_separated_usernames(user_list) { function comma_separated_usernames(user_list) {
const usernames = people.get_display_full_names(user_list); const usernames = people.get_display_full_names(user_list);
const current_user_has_reacted = user_list.includes(page_params.user_id); const current_user_has_reacted = user_list.includes(current_user.user_id);
if (current_user_has_reacted) { if (current_user_has_reacted) {
const current_user_index = user_list.indexOf(page_params.user_id); const current_user_index = user_list.indexOf(current_user.user_id);
usernames[current_user_index] = $t({ usernames[current_user_index] = $t({
defaultMessage: "You", defaultMessage: "You",
}); });

View File

@ -2,6 +2,7 @@ import $ from "jquery";
import * as channel from "./channel"; import * as channel from "./channel";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import {current_user} from "./state_data";
import * as upload_widget from "./upload_widget"; import * as upload_widget from "./upload_widget";
import type {UploadFunction} from "./upload_widget"; import type {UploadFunction} from "./upload_widget";
@ -10,7 +11,7 @@ export function build_realm_icon_widget(upload_function: UploadFunction): void {
return $<HTMLInputElement>("#realm-icon-upload-widget .image_file_input").expectOne(); return $<HTMLInputElement>("#realm-icon-upload-widget .image_file_input").expectOne();
}; };
if (!page_params.is_admin) { if (!current_user.is_admin) {
return; return;
} }
if (page_params.realm_icon_source === "G") { if (page_params.realm_icon_source === "G") {

View File

@ -3,6 +3,7 @@ import $ from "jquery";
import * as channel from "./channel"; import * as channel from "./channel";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
import * as upload_widget from "./upload_widget"; import * as upload_widget from "./upload_widget";
import type {UploadFunction} from "./upload_widget"; import type {UploadFunction} from "./upload_widget";
@ -25,7 +26,7 @@ export function build_realm_logo_widget(upload_function: UploadFunction, is_nigh
return $file_input_elem.expectOne(); return $file_input_elem.expectOne();
}; };
if (!page_params.is_admin) { if (!current_user.is_admin) {
return; return;
} }

View File

@ -2,6 +2,7 @@ import * as Sentry from "@sentry/browser";
import _ from "lodash"; import _ from "lodash";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import {current_user} from "./state_data";
type UserInfo = { type UserInfo = {
id?: string; id?: string;
@ -51,21 +52,21 @@ if (page_params.server_sentry_dsn) {
realm: sentry_key, realm: sentry_key,
}; };
if (sentry_key !== "www") { if (sentry_key !== "www") {
user_info.role = page_params.is_owner user_info.role = current_user.is_owner
? "Organization owner" ? "Organization owner"
: page_params.is_admin : current_user.is_admin
? "Organization administrator" ? "Organization administrator"
: page_params.is_moderator : current_user.is_moderator
? "Moderator" ? "Moderator"
: page_params.is_guest : current_user.is_guest
? "Guest" ? "Guest"
: page_params.is_spectator : page_params.is_spectator
? "Spectator" ? "Spectator"
: page_params.user_id : current_user.user_id
? "Member" ? "Member"
: "Logged out"; : "Logged out";
if (page_params.user_id) { if (current_user.user_id) {
user_info.id = page_params.user_id.toString(); user_info.id = current_user.user_id.toString();
} }
} }

View File

@ -67,6 +67,7 @@ import * as settings_users from "./settings_users";
import * as sidebar_ui from "./sidebar_ui"; import * as sidebar_ui from "./sidebar_ui";
import * as starred_messages from "./starred_messages"; import * as starred_messages from "./starred_messages";
import * as starred_messages_ui from "./starred_messages_ui"; import * as starred_messages_ui from "./starred_messages_ui";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_events from "./stream_events"; import * as stream_events from "./stream_events";
import * as stream_list from "./stream_list"; import * as stream_list from "./stream_list";
@ -134,7 +135,7 @@ export function dispatch_normal_event(event) {
} }
case "has_zoom_token": case "has_zoom_token":
page_params.has_zoom_token = event.value; current_user.has_zoom_token = event.value;
if (event.value) { if (event.value) {
for (const callback of compose_call.zoom_token_callbacks.values()) { for (const callback of compose_call.zoom_token_callbacks.values()) {
callback(); callback();
@ -146,8 +147,8 @@ export function dispatch_normal_event(event) {
case "onboarding_steps": case "onboarding_steps":
hotspots.load_new(onboarding_steps.filter_new_hotspots(event.onboarding_steps)); hotspots.load_new(onboarding_steps.filter_new_hotspots(event.onboarding_steps));
onboarding_steps.update_notice_to_display(event.onboarding_steps); onboarding_steps.update_notice_to_display(event.onboarding_steps);
page_params.onboarding_steps = page_params.onboarding_steps current_user.onboarding_steps = current_user.onboarding_steps
? [...page_params.onboarding_steps, ...event.onboarding_steps] ? [...current_user.onboarding_steps, ...event.onboarding_steps]
: event.onboarding_steps; : event.onboarding_steps;
break; break;
@ -346,7 +347,7 @@ export function dispatch_normal_event(event) {
window.location.href = "/accounts/deactivated/"; window.location.href = "/accounts/deactivated/";
break; break;
} }
if (page_params.is_admin) { if (current_user.is_admin) {
// Update the UI notice about the user's profile being // Update the UI notice about the user's profile being
// incomplete, as we might have filled in the missing field(s). // incomplete, as we might have filled in the missing field(s).
navbar_alerts.show_profile_incomplete(navbar_alerts.check_profile_incomplete()); navbar_alerts.show_profile_incomplete(navbar_alerts.check_profile_incomplete());
@ -639,7 +640,7 @@ export function dispatch_normal_event(event) {
} }
break; break;
case "typing": case "typing":
if (event.sender.user_id === page_params.user_id) { if (event.sender.user_id === current_user.user_id) {
// typing notifications are sent to the user who is typing // typing notifications are sent to the user who is typing
// as well as recipients; we ignore such self-generated events. // as well as recipients; we ignore such self-generated events.
return; return;
@ -817,7 +818,7 @@ export function dispatch_normal_event(event) {
if (event.property === "presence_enabled") { if (event.property === "presence_enabled") {
user_settings.presence_enabled = event.value; user_settings.presence_enabled = event.value;
$("#user_presence_enabled").prop("checked", user_settings.presence_enabled); $("#user_presence_enabled").prop("checked", user_settings.presence_enabled);
activity_ui.redraw_user(page_params.user_id); activity_ui.redraw_user(current_user.user_id);
break; break;
} }
if (event.property === "email_address_visibility") { if (event.property === "email_address_visibility") {

View File

@ -19,6 +19,7 @@ import * as settings_panel_menu from "./settings_panel_menu";
import * as settings_preferences from "./settings_preferences"; import * as settings_preferences from "./settings_preferences";
import * as settings_sections from "./settings_sections"; import * as settings_sections from "./settings_sections";
import * as settings_toggle from "./settings_toggle"; import * as settings_toggle from "./settings_toggle";
import {current_user} from "./state_data";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import {user_settings} from "./user_settings"; import {user_settings} from "./user_settings";
@ -66,7 +67,7 @@ function setup_settings_label() {
} }
function get_parsed_date_of_joining() { function get_parsed_date_of_joining() {
const user_date_joined = people.get_by_user_id(page_params.user_id, false).date_joined; const user_date_joined = people.get_by_user_id(current_user.user_id, false).date_joined;
return timerender.get_localized_date_or_time_for_format( return timerender.get_localized_date_or_time_for_format(
parseISO(user_date_joined), parseISO(user_date_joined),
"dayofyear_year", "dayofyear_year",
@ -81,11 +82,11 @@ function user_can_change_password() {
} }
export function update_lock_icon_in_sidebar() { export function update_lock_icon_in_sidebar() {
if (page_params.is_owner) { if (current_user.is_owner) {
$(".org-settings-list .locked").hide(); $(".org-settings-list .locked").hide();
return; return;
} }
if (page_params.is_admin) { if (current_user.is_admin) {
$(".org-settings-list .locked").hide(); $(".org-settings-list .locked").hide();
$(".org-settings-list li[data-section='auth-methods'] .locked").show(); $(".org-settings-list li[data-section='auth-methods'] .locked").show();
return; return;
@ -108,6 +109,7 @@ export function build_page() {
const rendered_settings_tab = render_settings_tab({ const rendered_settings_tab = render_settings_tab({
full_name: people.my_full_name(), full_name: people.my_full_name(),
date_joined_text: get_parsed_date_of_joining(), date_joined_text: get_parsed_date_of_joining(),
current_user,
page_params, page_params,
enable_sound_select: enable_sound_select:
user_settings.enable_sounds || user_settings.enable_stream_audible_notifications, user_settings.enable_sounds || user_settings.enable_stream_audible_notifications,
@ -138,7 +140,7 @@ export function build_page() {
user_can_change_name: settings_data.user_can_change_name(), user_can_change_name: settings_data.user_can_change_name(),
user_can_change_avatar: settings_data.user_can_change_avatar(), user_can_change_avatar: settings_data.user_can_change_avatar(),
user_can_change_email: settings_data.user_can_change_email(), user_can_change_email: settings_data.user_can_change_email(),
user_role_text: people.get_user_type(page_params.user_id), user_role_text: people.get_user_type(current_user.user_id),
default_language_name: settings_preferences.user_default_language_name, default_language_name: settings_preferences.user_default_language_name,
default_language: user_settings.default_language, default_language: user_settings.default_language,
realm_push_notifications_enabled: page_params.realm_push_notifications_enabled, realm_push_notifications_enabled: page_params.realm_push_notifications_enabled,
@ -182,9 +184,9 @@ export function launch(section) {
export function initialize() { export function initialize() {
const rendered_settings_overlay = render_settings_overlay({ const rendered_settings_overlay = render_settings_overlay({
is_owner: page_params.is_owner, is_owner: current_user.is_owner,
is_admin: page_params.is_admin, is_admin: current_user.is_admin,
is_guest: page_params.is_guest, is_guest: current_user.is_guest,
show_uploaded_files_section: page_params.max_file_upload_size_mib > 0, show_uploaded_files_section: page_params.max_file_upload_size_mib > 0,
show_emoji_settings_lock: !settings_data.user_can_add_custom_emoji(), show_emoji_settings_lock: !settings_data.user_can_add_custom_emoji(),
can_create_new_bots: settings_bots.can_create_new_bots(), can_create_new_bots: settings_bots.can_create_new_bots(),

View File

@ -25,6 +25,7 @@ import * as settings_bots from "./settings_bots";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
import * as settings_ui from "./settings_ui"; import * as settings_ui from "./settings_ui";
import {current_user} from "./state_data";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
import * as user_pill from "./user_pill"; import * as user_pill from "./user_pill";
@ -115,7 +116,7 @@ function upload_avatar($file_input) {
}, },
error(xhr) { error(xhr) {
display_avatar_upload_complete(); display_avatar_upload_complete();
if (page_params.avatar_source === "G") { if (current_user.avatar_source === "G") {
$("#user-avatar-source").show(); $("#user-avatar-source").show();
} }
if (xhr.responseJSON?.msg) { if (xhr.responseJSON?.msg) {
@ -156,7 +157,7 @@ export function update_account_settings_display() {
} }
export function maybe_update_deactivate_account_button() { export function maybe_update_deactivate_account_button() {
if (!page_params.is_owner) { if (!current_user.is_owner) {
return; return;
} }
@ -318,7 +319,7 @@ export function set_up() {
} }
$("#regenerate_api_key").on("click", (e) => { $("#regenerate_api_key").on("click", (e) => {
const email = page_params.delivery_email; const email = current_user.delivery_email;
const api_key = $("#api_key_value").text(); const api_key = $("#api_key_value").text();
const authorization_header = "Basic " + btoa(`${email}:${api_key}`); const authorization_header = "Basic " + btoa(`${email}:${api_key}`);
@ -343,7 +344,7 @@ export function set_up() {
$("#download_zuliprc").on("click", function () { $("#download_zuliprc").on("click", function () {
const bot_object = { const bot_object = {
user_id: people.my_current_user_id(), user_id: people.my_current_user_id(),
email: page_params.delivery_email, email: current_user.delivery_email,
api_key: $("#api_key_value").text(), api_key: $("#api_key_value").text(),
}; };
const data = settings_bots.generate_zuliprc_content(bot_object); const data = settings_bots.generate_zuliprc_content(bot_object);
@ -567,7 +568,7 @@ export function set_up() {
if (settings_data.user_can_change_email()) { if (settings_data.user_can_change_email()) {
dialog_widget.launch({ dialog_widget.launch({
html_heading: $t_html({defaultMessage: "Change email"}), html_heading: $t_html({defaultMessage: "Change email"}),
html_body: render_change_email_modal({delivery_email: page_params.delivery_email}), html_body: render_change_email_modal({delivery_email: current_user.delivery_email}),
html_submit_button: $t_html({defaultMessage: "Change"}), html_submit_button: $t_html({defaultMessage: "Change"}),
loading_spinner: true, loading_spinner: true,
id: "change_email_modal", id: "change_email_modal",
@ -644,14 +645,14 @@ export function set_up() {
if ( if (
page_params.demo_organization_scheduled_deletion_date && page_params.demo_organization_scheduled_deletion_date &&
page_params.is_owner && current_user.is_owner &&
page_params.delivery_email === "" current_user.delivery_email === ""
) { ) {
dialog_widget.launch({ dialog_widget.launch({
html_heading: $t_html({defaultMessage: "Add email"}), html_heading: $t_html({defaultMessage: "Add email"}),
html_body: render_demo_organization_add_email_modal({ html_body: render_demo_organization_add_email_modal({
delivery_email: page_params.delivery_email, delivery_email: current_user.delivery_email,
full_name: page_params.full_name, full_name: current_user.full_name,
}), }),
html_submit_button: $t_html({defaultMessage: "Add"}), html_submit_button: $t_html({defaultMessage: "Add"}),
loading_spinner: true, loading_spinner: true,

View File

@ -18,6 +18,7 @@ import * as list_widget from "./list_widget";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as user_deactivation_ui from "./user_deactivation_ui"; import * as user_deactivation_ui from "./user_deactivation_ui";
import * as user_profile from "./user_profile"; import * as user_profile from "./user_profile";
@ -139,11 +140,11 @@ export const bot_creation_policy_values = {
}; };
export function can_create_new_bots() { export function can_create_new_bots() {
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
if (page_params.is_guest) { if (current_user.is_guest) {
return false; return false;
} }
@ -152,14 +153,14 @@ export function can_create_new_bots() {
export function update_bot_settings_tip($tip_container, for_org_settings) { export function update_bot_settings_tip($tip_container, for_org_settings) {
if ( if (
!page_params.is_admin && !current_user.is_admin &&
page_params.realm_bot_creation_policy === bot_creation_policy_values.everyone.code page_params.realm_bot_creation_policy === bot_creation_policy_values.everyone.code
) { ) {
$tip_container.hide(); $tip_container.hide();
return; return;
} }
if (page_params.is_admin && !for_org_settings) { if (current_user.is_admin && !for_org_settings) {
$tip_container.hide(); $tip_container.hide();
return; return;
} }

View File

@ -1,5 +1,6 @@
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import {current_user} from "./state_data";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
import {user_settings} from "./user_settings"; import {user_settings} from "./user_settings";
@ -20,7 +21,7 @@ export function initialize(current_user_join_date: Date): void {
*/ */
export function user_can_change_name(): boolean { export function user_can_change_name(): boolean {
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
if (page_params.realm_name_changes_disabled || page_params.server_name_changes_disabled) { if (page_params.realm_name_changes_disabled || page_params.server_name_changes_disabled) {
@ -30,7 +31,7 @@ export function user_can_change_name(): boolean {
} }
export function user_can_change_avatar(): boolean { export function user_can_change_avatar(): boolean {
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
if (page_params.realm_avatar_changes_disabled || page_params.server_avatar_changes_disabled) { if (page_params.realm_avatar_changes_disabled || page_params.server_avatar_changes_disabled) {
@ -40,7 +41,7 @@ export function user_can_change_avatar(): boolean {
} }
export function user_can_change_email(): boolean { export function user_can_change_email(): boolean {
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
if (page_params.realm_email_changes_disabled) { if (page_params.realm_email_changes_disabled) {
@ -50,7 +51,7 @@ export function user_can_change_email(): boolean {
} }
export function user_can_change_logo(): boolean { export function user_can_change_logo(): boolean {
return page_params.is_admin && page_params.zulip_plan_is_not_limited; return current_user.is_admin && page_params.zulip_plan_is_not_limited;
} }
function user_has_permission(policy_value: number): boolean { function user_has_permission(policy_value: number): boolean {
@ -62,7 +63,7 @@ function user_has_permission(policy_value: number): boolean {
return false; return false;
} }
if (page_params.is_owner) { if (current_user.is_owner) {
return true; return true;
} }
@ -72,7 +73,7 @@ function user_has_permission(policy_value: number): boolean {
return false; return false;
} }
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
@ -87,7 +88,7 @@ function user_has_permission(policy_value: number): boolean {
return true; return true;
} }
if (page_params.is_guest) { if (current_user.is_guest) {
return false; return false;
} }
@ -95,7 +96,7 @@ function user_has_permission(policy_value: number): boolean {
return false; return false;
} }
if (page_params.is_moderator) { if (current_user.is_moderator) {
return true; return true;
} }
@ -125,12 +126,12 @@ export function user_can_invite_users_by_email(): boolean {
} }
export function user_can_create_multiuse_invite(): boolean { export function user_can_create_multiuse_invite(): boolean {
if (!page_params.user_id) { if (!current_user.user_id) {
return false; return false;
} }
return user_groups.is_user_in_group( return user_groups.is_user_in_group(
page_params.realm_create_multiuse_invite_group, page_params.realm_create_multiuse_invite_group,
page_params.user_id, current_user.user_id,
); );
} }
@ -166,7 +167,7 @@ export function user_can_edit_user_groups(): boolean {
} }
export function can_edit_user_group(group_id: number): boolean { export function can_edit_user_group(group_id: number): boolean {
if (!page_params.user_id) { if (!current_user.user_id) {
return false; return false;
} }
@ -177,11 +178,11 @@ export function can_edit_user_group(group_id: number): boolean {
// Admins and moderators are allowed to edit user groups even if they // Admins and moderators are allowed to edit user groups even if they
// are not a member of that user group. Members can edit user groups // are not a member of that user group. Members can edit user groups
// only if they belong to that group. // only if they belong to that group.
if (page_params.is_admin || page_params.is_moderator) { if (current_user.is_admin || current_user.is_moderator) {
return true; return true;
} }
return user_groups.is_direct_member_of(page_params.user_id, group_id); return user_groups.is_direct_member_of(current_user.user_id, group_id);
} }
export function user_can_add_custom_emoji(): boolean { export function user_can_add_custom_emoji(): boolean {
@ -233,7 +234,7 @@ export function user_email_not_configured(): boolean {
// The following should also be true in the only circumstance // The following should also be true in the only circumstance
// under which we expect this condition to be possible: // under which we expect this condition to be possible:
// page_params.demo_organization_scheduled_deletion_date // page_params.demo_organization_scheduled_deletion_date
return page_params.is_owner && page_params.delivery_email === ""; return current_user.is_owner && current_user.delivery_email === "";
} }
export function bot_type_id_to_string(type_id: number): string | undefined { export function bot_type_id_to_string(type_id: number): string | undefined {
@ -247,13 +248,13 @@ export function bot_type_id_to_string(type_id: number): string | undefined {
} }
export function user_can_access_all_other_users(): boolean { export function user_can_access_all_other_users(): boolean {
if (!page_params.user_id) { if (!current_user.user_id) {
return true; return true;
} }
return user_groups.is_user_in_group( return user_groups.is_user_in_group(
page_params.realm_can_access_all_users_group, page_params.realm_can_access_all_users_group,
page_params.user_id, current_user.user_id,
); );
} }

View File

@ -20,6 +20,7 @@ import * as people from "./people";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as upload_widget from "./upload_widget"; import * as upload_widget from "./upload_widget";
import * as util from "./util"; import * as util from "./util";
@ -29,7 +30,7 @@ const meta = {
}; };
function can_delete_emoji(emoji: ServerEmoji): boolean { function can_delete_emoji(emoji: ServerEmoji): boolean {
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
if (emoji.author_id === null) { if (emoji.author_id === null) {
@ -56,7 +57,7 @@ export function update_custom_emoji_ui(): void {
} else { } else {
$(".add-emoji-text").show(); $(".add-emoji-text").show();
$("#add-custom-emoji-button").show(); $("#add-custom-emoji-button").show();
if (page_params.is_admin) { if (current_user.is_admin) {
$("#emoji-settings .emoji-settings-tip-container").show(); $("#emoji-settings .emoji-settings-tip-container").show();
} else { } else {
$("#emoji-settings .emoji-settings-tip-container").hide(); $("#emoji-settings .emoji-settings-tip-container").hide();
@ -269,7 +270,7 @@ function show_modal(): void {
} }
if (is_default_emoji(emoji.name)) { if (is_default_emoji(emoji.name)) {
if (!page_params.is_admin) { if (!current_user.is_admin) {
ui_report.client_error( ui_report.client_error(
$t_html({ $t_html({
defaultMessage: defaultMessage:

View File

@ -15,6 +15,7 @@ import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as util from "./util"; import * as util from "./util";
@ -96,10 +97,10 @@ function populate_invites(invites_data: {invites: Invite[]}): void {
if (item.expiry_date !== null) { if (item.expiry_date !== null) {
item.expiry_date_absolute_time = timerender.absolute_time(item.expiry_date * 1000); item.expiry_date_absolute_time = timerender.absolute_time(item.expiry_date * 1000);
} }
item.is_admin = page_params.is_admin; item.is_admin = current_user.is_admin;
item.disable_buttons = item.disable_buttons =
item.invited_as === settings_config.user_role_values.owner.code && item.invited_as === settings_config.user_role_values.owner.code &&
!page_params.is_owner; !current_user.is_owner;
item.referrer_name = people.get_by_user_id(item.invited_by_user_id).full_name; item.referrer_name = people.get_by_user_id(item.invited_by_user_id).full_name;
return render_admin_invites_list({invite: item}); return render_admin_invites_list({invite: item});
}, },
@ -289,7 +290,7 @@ export function on_load_success(
} }
export function update_invite_users_setting_tip(): void { export function update_invite_users_setting_tip(): void {
if (settings_data.user_can_invite_users_by_email() && !page_params.is_admin) { if (settings_data.user_can_invite_users_by_email() && !current_user.is_admin) {
$(".invite-user-settings-tip").hide(); $(".invite-user-settings-tip").hide();
return; return;
} }

View File

@ -13,6 +13,7 @@ import * as ListWidget from "./list_widget";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import * as settings_ui from "./settings_ui"; import * as settings_ui from "./settings_ui";
import {current_user} from "./state_data";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
const meta = { const meta = {
@ -24,7 +25,7 @@ export function reset() {
} }
export function maybe_disable_widgets() { export function maybe_disable_widgets() {
if (page_params.is_admin) { if (current_user.is_admin) {
return; return;
} }
} }
@ -140,7 +141,7 @@ export function populate_linkifiers(linkifiers_data) {
url_template: linkifier.url_template, url_template: linkifier.url_template,
id: linkifier.id, id: linkifier.id,
}, },
can_modify: page_params.is_admin, can_modify: current_user.is_admin,
can_drag: filter_value.length === 0, can_drag: filter_value.length === 0,
}); });
}, },
@ -160,7 +161,7 @@ export function populate_linkifiers(linkifiers_data) {
$simplebar_container: $("#linkifier-settings .progressive-table-wrapper"), $simplebar_container: $("#linkifier-settings .progressive-table-wrapper"),
}); });
if (page_params.is_admin) { if (current_user.is_admin) {
Sortable.create($linkifiers_table[0], { Sortable.create($linkifiers_table[0], {
onUpdate: update_linkifiers_order, onUpdate: update_linkifiers_order,
handle: ".move-handle", handle: ".move-handle",

View File

@ -23,6 +23,7 @@ import * as settings_data from "./settings_data";
import * as settings_notifications from "./settings_notifications"; import * as settings_notifications from "./settings_notifications";
import * as settings_realm_domains from "./settings_realm_domains"; import * as settings_realm_domains from "./settings_realm_domains";
import * as settings_ui from "./settings_ui"; import * as settings_ui from "./settings_ui";
import {current_user} from "./state_data";
import * as stream_settings_data from "./stream_settings_data"; import * as stream_settings_data from "./stream_settings_data";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
@ -39,7 +40,7 @@ export function reset() {
const DISABLED_STATE_ID = -1; const DISABLED_STATE_ID = -1;
export function maybe_disable_widgets() { export function maybe_disable_widgets() {
if (page_params.is_owner) { if (current_user.is_owner) {
return; return;
} }
@ -47,7 +48,7 @@ export function maybe_disable_widgets() {
.find("input, button, select, checked") .find("input, button, select, checked")
.prop("disabled", true); .prop("disabled", true);
if (page_params.is_admin) { if (current_user.is_admin) {
$(".deactivate_realm_button").prop("disabled", true); $(".deactivate_realm_button").prop("disabled", true);
$("#deactivate_realm_button_container").addClass("disabled_setting_tooltip"); $("#deactivate_realm_button_container").addClass("disabled_setting_tooltip");
$("#org-message-retention").find("input, select").prop("disabled", true); $("#org-message-retention").find("input, select").prop("disabled", true);
@ -382,7 +383,7 @@ function can_configure_auth_methods() {
if (settings_data.user_email_not_configured()) { if (settings_data.user_email_not_configured()) {
return false; return false;
} }
if (page_params.is_owner) { if (current_user.is_owner) {
return true; return true;
} }
return false; return false;

View File

@ -11,6 +11,7 @@ import * as ListWidget from "./list_widget";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as realm_playground from "./realm_playground"; import * as realm_playground from "./realm_playground";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import {current_user} from "./state_data";
import {render_typeahead_item} from "./typeahead_helper"; import {render_typeahead_item} from "./typeahead_helper";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
@ -23,7 +24,7 @@ export function reset() {
} }
export function maybe_disable_widgets() { export function maybe_disable_widgets() {
if (page_params.is_admin) { if (current_user.is_admin) {
return; return;
} }
} }
@ -45,7 +46,7 @@ export function populate_playgrounds(playgrounds_data) {
url_template: playground.url_template, url_template: playground.url_template,
id: playground.id, id: playground.id,
}, },
can_modify: page_params.is_admin, can_modify: current_user.is_admin,
}); });
}, },
filter: { filter: {

View File

@ -16,6 +16,7 @@ import * as loading from "./loading";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as settings_ui from "./settings_ui"; import * as settings_ui from "./settings_ui";
import {current_user} from "./state_data";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
const meta = { const meta = {
@ -30,7 +31,7 @@ function display_success_status() {
} }
export function maybe_disable_widgets() { export function maybe_disable_widgets() {
if (page_params.is_admin) { if (current_user.is_admin) {
return; return;
} }
@ -663,7 +664,7 @@ export function do_populate_profile_fields(profile_fields_data) {
display_in_profile_summary, display_in_profile_summary,
valid_to_display_in_summary: is_valid_to_display_in_summary(profile_field.type), valid_to_display_in_summary: is_valid_to_display_in_summary(profile_field.type),
}, },
can_modify: page_params.is_admin, can_modify: current_user.is_admin,
realm_default_external_accounts: page_params.realm_default_external_accounts, realm_default_external_accounts: page_params.realm_default_external_accounts,
}), }),
); );
@ -677,7 +678,7 @@ export function do_populate_profile_fields(profile_fields_data) {
// Update whether we're at the limit for display_in_profile_summary. // Update whether we're at the limit for display_in_profile_summary.
display_in_profile_summary_fields_limit_reached = display_in_profile_summary_fields_count >= 2; display_in_profile_summary_fields_limit_reached = display_in_profile_summary_fields_count >= 2;
if (page_params.is_admin) { if (current_user.is_admin) {
const field_list = $("#admin_profile_fields_table")[0]; const field_list = $("#admin_profile_fields_table")[0];
Sortable.create(field_list, { Sortable.create(field_list, {
onUpdate: update_field_order, onUpdate: update_field_order,
@ -695,7 +696,7 @@ function set_up_select_field() {
create_choice_row("#profile_field_choices"); create_choice_row("#profile_field_choices");
if (page_params.is_admin) { if (current_user.is_admin) {
const choice_list = $("#profile_field_choices")[0]; const choice_list = $("#profile_field_choices")[0];
Sortable.create(choice_list, { Sortable.create(choice_list, {
onUpdate() {}, onUpdate() {},

View File

@ -2,17 +2,17 @@ import $ from "jquery";
import * as audible_notifications from "./audible_notifications"; import * as audible_notifications from "./audible_notifications";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import {page_params} from "./page_params";
import {realm_user_settings_defaults} from "./realm_user_settings_defaults"; import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
import * as settings_components from "./settings_components"; import * as settings_components from "./settings_components";
import * as settings_notifications from "./settings_notifications"; import * as settings_notifications from "./settings_notifications";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
import * as settings_preferences from "./settings_preferences"; import * as settings_preferences from "./settings_preferences";
import {current_user} from "./state_data";
export const realm_default_settings_panel = {}; export const realm_default_settings_panel = {};
export function maybe_disable_widgets() { export function maybe_disable_widgets() {
if (!page_params.is_admin) { if (!current_user.is_admin) {
$(".organization-box [data-name='organization-level-user-defaults']") $(".organization-box [data-name='organization-level-user-defaults']")
.find("input, select") .find("input, select")
.prop("disabled", true); .prop("disabled", true);

View File

@ -11,9 +11,9 @@ import * as hash_parser from "./hash_parser";
import {$t_html} from "./i18n"; import {$t_html} from "./i18n";
import * as ListWidget from "./list_widget"; import * as ListWidget from "./list_widget";
import * as loading from "./loading"; import * as loading from "./loading";
import {page_params} from "./page_params";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import * as settings_profile_fields from "./settings_profile_fields"; import * as settings_profile_fields from "./settings_profile_fields";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
@ -87,7 +87,7 @@ export function reset() {
} }
export function maybe_disable_widgets() { export function maybe_disable_widgets() {
if (page_params.is_admin) { if (current_user.is_admin) {
return; return;
} }
@ -108,7 +108,7 @@ export function build_default_stream_table() {
modifier_html(item) { modifier_html(item) {
return render_admin_default_streams_list({ return render_admin_default_streams_list({
stream: item, stream: item,
can_modify: page_params.is_admin, can_modify: current_user.is_admin,
}); });
}, },
filter: { filter: {

View File

@ -9,12 +9,12 @@ import * as dialog_widget from "./dialog_widget";
import {$t} from "./i18n"; import {$t} from "./i18n";
import * as ListWidget from "./list_widget"; import * as ListWidget from "./list_widget";
import * as loading from "./loading"; import * as loading from "./loading";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as presence from "./presence"; import * as presence from "./presence";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import * as settings_bots from "./settings_bots"; import * as settings_bots from "./settings_bots";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import * as user_deactivation_ui from "./user_deactivation_ui"; import * as user_deactivation_ui from "./user_deactivation_ui";
import * as user_profile from "./user_profile"; import * as user_profile from "./user_profile";
@ -157,7 +157,7 @@ function bot_info(bot_user_id) {
} }
info.is_current_user = false; info.is_current_user = false;
info.can_modify = page_params.is_admin; info.can_modify = current_user.is_admin;
info.cannot_deactivate = bot_user.is_system_bot; info.cannot_deactivate = bot_user.is_system_bot;
info.cannot_edit = bot_user.is_system_bot; info.cannot_edit = bot_user.is_system_bot;
@ -186,9 +186,9 @@ function human_info(person) {
info.full_name = person.full_name; info.full_name = person.full_name;
info.bot_owner_id = person.bot_owner_id; info.bot_owner_id = person.bot_owner_id;
info.can_modify = page_params.is_admin; info.can_modify = current_user.is_admin;
info.is_current_user = people.is_my_user_id(person.user_id); info.is_current_user = people.is_my_user_id(person.user_id);
info.cannot_deactivate = info.is_current_user || (person.is_owner && !page_params.is_owner); info.cannot_deactivate = info.is_current_user || (person.is_owner && !current_user.is_owner);
info.display_email = person.delivery_email; info.display_email = person.delivery_email;
if (info.is_active) { if (info.is_active) {

View File

@ -9,6 +9,7 @@ import * as resize from "./resize";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as spectators from "./spectators"; import * as spectators from "./spectators";
import {current_user} from "./state_data";
import {user_settings} from "./user_settings"; import {user_settings} from "./user_settings";
export let left_sidebar_expanded_as_overlay = false; export let left_sidebar_expanded_as_overlay = false;
@ -136,7 +137,7 @@ export function initialize() {
export function initialize_left_sidebar() { export function initialize_left_sidebar() {
const rendered_sidebar = render_left_sidebar({ const rendered_sidebar = render_left_sidebar({
is_guest: page_params.is_guest, is_guest: current_user.is_guest,
development_environment: page_params.development_environment, development_environment: page_params.development_environment,
is_inbox_home_view: is_inbox_home_view:
user_settings.web_home_view === settings_config.web_home_view_values.inbox.code, user_settings.web_home_view === settings_config.web_home_view_values.inbox.code,

14
web/src/state_data.ts Normal file
View File

@ -0,0 +1,14 @@
export let current_user: {
avatar_source: string;
delivery_email: string;
is_admin: boolean;
is_billing_admin: boolean;
is_guest: boolean;
is_moderator: boolean;
is_owner: boolean;
user_id: number;
};
export function set_current_user(initial_current_user: typeof current_user): void {
current_user = initial_current_user;
}

View File

@ -12,6 +12,7 @@ import * as loading from "./loading";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as stream_create_subscribers from "./stream_create_subscribers"; import * as stream_create_subscribers from "./stream_create_subscribers";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_settings_components from "./stream_settings_components"; import * as stream_settings_components from "./stream_settings_components";
@ -338,7 +339,7 @@ export function show_new_stream_modal() {
// The message retention setting is visible to owners only. The below block // The message retention setting is visible to owners only. The below block
// sets the default state of setting if it is visible. // sets the default state of setting if it is visible.
if (page_params.is_owner) { if (current_user.is_owner) {
$("#stream_creation_form .stream-message-retention-days-input").hide(); $("#stream_creation_form .stream-message-retention-days-input").hide();
$("#stream_creation_form select[name=stream_message_retention_setting]").val( $("#stream_creation_form select[name=stream_message_retention_setting]").val(
"realm_default", "realm_default",
@ -415,7 +416,7 @@ export function set_up_handlers() {
stream_subscription_error.report_no_subs_to_stream(); stream_subscription_error.report_no_subs_to_stream();
return; return;
} }
if (!principals.includes(people.my_current_user_id()) && !page_params.is_admin) { if (!principals.includes(people.my_current_user_id()) && !current_user.is_admin) {
stream_subscription_error.cant_create_stream_without_subscribing(); stream_subscription_error.cant_create_stream_without_subscribing();
return; return;
} }

View File

@ -5,8 +5,8 @@ import render_new_stream_users from "../templates/stream_settings/new_stream_use
import * as add_subscribers_pill from "./add_subscribers_pill"; import * as add_subscribers_pill from "./add_subscribers_pill";
import * as ListWidget from "./list_widget"; import * as ListWidget from "./list_widget";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import {current_user} from "./state_data";
import * as stream_create_subscribers_data from "./stream_create_subscribers_data"; import * as stream_create_subscribers_data from "./stream_create_subscribers_data";
import * as user_sort from "./user_sort"; import * as user_sort from "./user_sort";
@ -84,7 +84,7 @@ export function build_widgets() {
build_pill_widget({$parent_container: $add_people_container}); build_pill_widget({$parent_container: $add_people_container});
stream_create_subscribers_data.initialize_with_current_user(); stream_create_subscribers_data.initialize_with_current_user();
const current_user_id = page_params.user_id; const current_user_id = current_user.user_id;
all_users_list_widget = ListWidget.create($("#create_stream_subscribers"), [current_user_id], { all_users_list_widget = ListWidget.create($("#create_stream_subscribers"), [current_user_id], {
name: "new_stream_add_users", name: "new_stream_add_users",

View File

@ -1,11 +1,11 @@
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import type {User} from "./people"; import type {User} from "./people";
import {current_user} from "./state_data";
let user_id_set: Set<number>; let user_id_set: Set<number>;
export function initialize_with_current_user(): void { export function initialize_with_current_user(): void {
user_id_set = new Set([page_params.user_id]); user_id_set = new Set([current_user.user_id]);
} }
export function sorted_user_ids(): number[] { export function sorted_user_ids(): number[] {
@ -33,7 +33,7 @@ export function get_potential_subscribers(): User[] {
} }
export function must_be_subscribed(user_id: number): boolean { export function must_be_subscribed(user_id: number): boolean {
return !page_params.is_admin && user_id === page_params.user_id; return !current_user.is_admin && user_id === current_user.user_id;
} }
export function add_user_ids(user_ids: number[]): void { export function add_user_ids(user_ids: number[]): void {

View File

@ -6,6 +6,7 @@ import * as peer_data from "./peer_data";
import * as people from "./people"; import * as people from "./people";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import type { import type {
ApiStreamSubscription, ApiStreamSubscription,
@ -498,13 +499,14 @@ export function can_toggle_subscription(sub: StreamSubscription): boolean {
// deactivated streams are automatically made private during the // deactivated streams are automatically made private during the
// archive stream process. // archive stream process.
return ( return (
(sub.subscribed || (!page_params.is_guest && !sub.invite_only)) && !page_params.is_spectator (sub.subscribed || (!current_user.is_guest && !sub.invite_only)) &&
!page_params.is_spectator
); );
} }
export function can_access_stream_email(sub: StreamSubscription): boolean { export function can_access_stream_email(sub: StreamSubscription): boolean {
return ( return (
(sub.subscribed || sub.is_web_public || (!page_params.is_guest && !sub.invite_only)) && (sub.subscribed || sub.is_web_public || (!current_user.is_guest && !sub.invite_only)) &&
!page_params.is_spectator !page_params.is_spectator
); );
} }
@ -521,19 +523,19 @@ export function can_preview(sub: StreamSubscription): boolean {
} }
export function can_change_permissions(sub: StreamSubscription): boolean { export function can_change_permissions(sub: StreamSubscription): boolean {
return page_params.is_admin && (!sub.invite_only || sub.subscribed); return current_user.is_admin && (!sub.invite_only || sub.subscribed);
} }
export function can_view_subscribers(sub: StreamSubscription): boolean { export function can_view_subscribers(sub: StreamSubscription): boolean {
// Guest users can't access subscribers of any(public or private) non-subscribed streams. // Guest users can't access subscribers of any(public or private) non-subscribed streams.
return page_params.is_admin || sub.subscribed || (!page_params.is_guest && !sub.invite_only); return current_user.is_admin || sub.subscribed || (!current_user.is_guest && !sub.invite_only);
} }
export function can_subscribe_others(sub: StreamSubscription): boolean { export function can_subscribe_others(sub: StreamSubscription): boolean {
// User can add other users to stream if stream is public or user is subscribed to stream // User can add other users to stream if stream is public or user is subscribed to stream
// and realm level setting allows user to add subscribers. // and realm level setting allows user to add subscribers.
return ( return (
!page_params.is_guest && !current_user.is_guest &&
(!sub.invite_only || sub.subscribed) && (!sub.invite_only || sub.subscribed) &&
settings_data.user_can_subscribe_other_users() settings_data.user_can_subscribe_other_users()
); );
@ -567,7 +569,7 @@ export function can_unsubscribe_others(sub: StreamSubscription): boolean {
return false; return false;
} }
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
@ -582,7 +584,7 @@ export function can_post_messages_in_stream(stream: StreamSubscription): boolean
return false; return false;
} }
if (page_params.is_admin) { if (current_user.is_admin) {
return true; return true;
} }
@ -590,7 +592,7 @@ export function can_post_messages_in_stream(stream: StreamSubscription): boolean
return false; return false;
} }
if (page_params.is_moderator) { if (current_user.is_moderator) {
return true; return true;
} }
@ -599,7 +601,7 @@ export function can_post_messages_in_stream(stream: StreamSubscription): boolean
} }
if ( if (
page_params.is_guest && current_user.is_guest &&
stream.stream_post_policy !== settings_config.stream_post_policy_values.everyone.code stream.stream_post_policy !== settings_config.stream_post_policy_values.everyone.code
) { ) {
return false; return false;

View File

@ -24,6 +24,7 @@ import * as scroll_util from "./scroll_util";
import * as settings_components from "./settings_components"; import * as settings_components from "./settings_components";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
import {current_user} from "./state_data";
import * as stream_color from "./stream_color"; import * as stream_color from "./stream_color";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_edit_subscribers from "./stream_edit_subscribers"; import * as stream_edit_subscribers from "./stream_edit_subscribers";
@ -255,7 +256,7 @@ export function show_settings_for(node) {
page_params.upgrade_text_for_wide_organization_logo, page_params.upgrade_text_for_wide_organization_logo,
is_business_type_org: is_business_type_org:
page_params.realm_org_type === settings_config.all_org_type_values.business.code, page_params.realm_org_type === settings_config.all_org_type_values.business.code,
is_admin: page_params.is_admin, is_admin: current_user.is_admin,
org_level_message_retention_setting: get_display_text_for_realm_message_retention_setting(), org_level_message_retention_setting: get_display_text_for_realm_message_retention_setting(),
can_access_stream_email: stream_data.can_access_stream_email(sub), can_access_stream_email: stream_data.can_access_stream_email(sub),
}); });

View File

@ -12,10 +12,10 @@ import * as confirm_dialog from "./confirm_dialog";
import * as hash_parser from "./hash_parser"; import * as hash_parser from "./hash_parser";
import {$t, $t_html} from "./i18n"; import {$t, $t_html} from "./i18n";
import * as ListWidget from "./list_widget"; import * as ListWidget from "./list_widget";
import {page_params} from "./page_params";
import * as peer_data from "./peer_data"; import * as peer_data from "./peer_data";
import * as people from "./people"; import * as people from "./people";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_settings_containers from "./stream_settings_containers"; import * as stream_settings_containers from "./stream_settings_containers";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
@ -30,7 +30,7 @@ function format_member_list_elem(person, user_can_remove_subscribers) {
return render_stream_member_list_entry({ return render_stream_member_list_entry({
name: person.full_name, name: person.full_name,
user_id: person.user_id, user_id: person.user_id,
is_current_user: person.user_id === page_params.user_id, is_current_user: person.user_id === current_user.user_id,
email: person.delivery_email, email: person.delivery_email,
can_remove_subscribers: user_can_remove_subscribers, can_remove_subscribers: user_can_remove_subscribers,
for_user_group_members: false, for_user_group_members: false,
@ -157,11 +157,11 @@ function subscribe_new_users({pill_user_ids}) {
const user_id_set = new Set(active_user_ids); const user_id_set = new Set(active_user_ids);
if (user_id_set.has(page_params.user_id) && sub.subscribed) { if (user_id_set.has(current_user.user_id) && sub.subscribed) {
// We don't want to send a request to subscribe ourselves // We don't want to send a request to subscribe ourselves
// if we are already subscribed to this stream. This // if we are already subscribed to this stream. This
// case occurs when creating user pills from a stream. // case occurs when creating user pills from a stream.
user_id_set.delete(page_params.user_id); user_id_set.delete(current_user.user_id);
} }
let ignored_deactivated_users; let ignored_deactivated_users;
if (deactivated_users.size > 0) { if (deactivated_users.size > 0) {

View File

@ -11,11 +11,11 @@ import * as hash_util from "./hash_util";
import {$t, $t_html} from "./i18n"; import {$t, $t_html} from "./i18n";
import * as loading from "./loading"; import * as loading from "./loading";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import {page_params} from "./page_params";
import * as peer_data from "./peer_data"; import * as peer_data from "./peer_data";
import * as people from "./people"; import * as people from "./people";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as stream_ui_updates from "./stream_ui_updates"; import * as stream_ui_updates from "./stream_ui_updates";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
@ -228,7 +228,7 @@ export function unsubscribe_from_private_stream(sub) {
export function sub_or_unsub(sub, $stream_row) { export function sub_or_unsub(sub, $stream_row) {
if (sub.subscribed) { if (sub.subscribed) {
// TODO: This next line should allow guests to access web-public streams. // TODO: This next line should allow guests to access web-public streams.
if (sub.invite_only || page_params.is_guest) { if (sub.invite_only || current_user.is_guest) {
unsubscribe_from_private_stream(sub); unsubscribe_from_private_stream(sub);
return; return;
} }

View File

@ -1,7 +1,7 @@
import * as hash_util from "./hash_util"; import * as hash_util from "./hash_util";
import {page_params} from "./page_params";
import * as peer_data from "./peer_data"; import * as peer_data from "./peer_data";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import type {StreamSpecificNotificationSettings, StreamSubscription} from "./sub_store"; import type {StreamSpecificNotificationSettings, StreamSubscription} from "./sub_store";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
@ -26,10 +26,10 @@ export function get_sub_for_settings(sub: StreamSubscription): SettingsSubscript
return { return {
...sub, ...sub,
is_realm_admin: page_params.is_admin, is_realm_admin: current_user.is_admin,
// Admin can change any stream's name & description either stream is public or // Admin can change any stream's name & description either stream is public or
// private, subscribed or unsubscribed. // private, subscribed or unsubscribed.
can_change_name_description: page_params.is_admin, can_change_name_description: current_user.is_admin,
should_display_subscription_button: stream_data.can_toggle_subscription(sub), should_display_subscription_button: stream_data.can_toggle_subscription(sub),
should_display_preview_button: stream_data.can_preview(sub), should_display_preview_button: stream_data.can_preview(sub),
@ -57,7 +57,7 @@ export function get_updated_unsorted_subs(): SettingsSubscription[] {
let all_subs = stream_data.get_unsorted_subs(); let all_subs = stream_data.get_unsorted_subs();
// We don't display unsubscribed streams to guest users. // We don't display unsubscribed streams to guest users.
if (page_params.is_guest) { if (current_user.is_guest) {
all_subs = all_subs.filter((sub) => sub.subscribed); all_subs = all_subs.filter((sub) => sub.subscribed);
} }

View File

@ -25,6 +25,7 @@ import * as scroll_util from "./scroll_util";
import * as search_util from "./search_util"; import * as search_util from "./search_util";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as stream_create from "./stream_create"; import * as stream_create from "./stream_create";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_edit from "./stream_edit"; import * as stream_edit from "./stream_edit";
@ -299,7 +300,7 @@ export function update_settings_for_unsubscribed(slim_sub) {
if (!stream_data.can_toggle_subscription(sub)) { if (!stream_data.can_toggle_subscription(sub)) {
stream_ui_updates.update_add_subscriptions_elements(sub); stream_ui_updates.update_add_subscriptions_elements(sub);
} }
if (page_params.is_guest) { if (current_user.is_guest) {
stream_edit.open_edit_panel_empty(); stream_edit.open_edit_panel_empty();
} }
@ -582,7 +583,7 @@ export function setup_page(callback) {
const toggler_elem = toggler.get(); const toggler_elem = toggler.get();
$("#streams_overlay_container .list-toggler-container").prepend(toggler_elem); $("#streams_overlay_container .list-toggler-container").prepend(toggler_elem);
} }
if (page_params.is_guest) { if (current_user.is_guest) {
toggler.disable_tab("all-streams"); toggler.disable_tab("all-streams");
} }
@ -606,10 +607,10 @@ export function setup_page(callback) {
settings_data.user_can_create_private_streams() || settings_data.user_can_create_private_streams() ||
settings_data.user_can_create_public_streams() || settings_data.user_can_create_public_streams() ||
settings_data.user_can_create_web_public_streams(), settings_data.user_can_create_web_public_streams(),
can_view_all_streams: !page_params.is_guest && should_list_all_streams(), can_view_all_streams: !current_user.is_guest && should_list_all_streams(),
max_stream_name_length: page_params.max_stream_name_length, max_stream_name_length: page_params.max_stream_name_length,
max_stream_description_length: page_params.max_stream_description_length, max_stream_description_length: page_params.max_stream_description_length,
is_owner: page_params.is_owner, is_owner: current_user.is_owner,
stream_privacy_policy_values: settings_config.stream_privacy_policy_values, stream_privacy_policy_values: settings_config.stream_privacy_policy_values,
stream_privacy_policy, stream_privacy_policy,
stream_post_policy_values: settings_config.stream_post_policy_values, stream_post_policy_values: settings_config.stream_post_policy_values,
@ -622,7 +623,7 @@ export function setup_page(callback) {
is_business_type_org: is_business_type_org:
page_params.realm_org_type === settings_config.all_org_type_values.business.code, page_params.realm_org_type === settings_config.all_org_type_values.business.code,
disable_message_retention_setting: disable_message_retention_setting:
!page_params.zulip_plan_is_not_limited || !page_params.is_owner, !page_params.zulip_plan_is_not_limited || !current_user.is_owner,
}; };
const rendered = render_stream_settings_overlay(template_data); const rendered = render_stream_settings_overlay(template_data);
@ -701,7 +702,7 @@ function show_right_section() {
export function change_state(section, right_side_tab) { export function change_state(section, right_side_tab) {
// if in #streams/new form. // if in #streams/new form.
if (section === "new") { if (section === "new") {
if (!page_params.is_guest) { if (!current_user.is_guest) {
do_open_create_stream(); do_open_create_stream();
show_right_section(); show_right_section();
} else { } else {
@ -735,7 +736,7 @@ export function change_state(section, right_side_tab) {
// not be in sub_store). // not be in sub_store).
// //
// In all these cases we redirect the user to 'subscribed' tab. // In all these cases we redirect the user to 'subscribed' tab.
if (!sub || (page_params.is_guest && !stream_data.is_subscribed(stream_id))) { if (!sub || (current_user.is_guest && !stream_data.is_subscribed(stream_id))) {
toggler.goto("subscribed"); toggler.goto("subscribed");
stream_edit.empty_right_panel(); stream_edit.empty_right_panel();
} else { } else {

View File

@ -11,6 +11,7 @@ import {page_params} from "./page_params";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_edit_toggler from "./stream_edit_toggler"; import * as stream_edit_toggler from "./stream_edit_toggler";
import * as stream_settings_containers from "./stream_settings_containers"; import * as stream_settings_containers from "./stream_settings_containers";
@ -231,7 +232,7 @@ export function update_default_stream_and_stream_privacy_state($container) {
// In the stream creation UI, if the user is a non-admin hide the // In the stream creation UI, if the user is a non-admin hide the
// "Default stream for new users" widget // "Default stream for new users" widget
if (is_stream_creation && !page_params.is_admin) { if (is_stream_creation && !current_user.is_admin) {
$default_stream.hide(); $default_stream.hide();
return; return;
} }
@ -271,7 +272,7 @@ export function enable_or_disable_permission_settings_in_edit_panel(sub) {
update_default_stream_and_stream_privacy_state($stream_settings); update_default_stream_and_stream_privacy_state($stream_settings);
const disable_message_retention_setting = const disable_message_retention_setting =
!page_params.zulip_plan_is_not_limited || !page_params.is_owner; !page_params.zulip_plan_is_not_limited || !current_user.is_owner;
$stream_settings $stream_settings
.find(".stream_message_retention_setting") .find(".stream_message_retention_setting")
.prop("disabled", disable_message_retention_setting); .prop("disabled", disable_message_retention_setting);
@ -347,7 +348,7 @@ export function update_stream_row_in_settings_tab(sub) {
const $sub_row = row_for_stream_id(sub.stream_id); const $sub_row = row_for_stream_id(sub.stream_id);
if (sub.subscribed) { if (sub.subscribed) {
$sub_row.removeClass("notdisplayed"); $sub_row.removeClass("notdisplayed");
} else if (sub.invite_only || page_params.is_guest) { } else if (sub.invite_only || current_user.is_guest) {
$sub_row.addClass("notdisplayed"); $sub_row.addClass("notdisplayed");
} }
} }
@ -361,7 +362,7 @@ export function update_add_subscriptions_elements(sub) {
// We are only concerned with the Subscribers tab for editing streams. // We are only concerned with the Subscribers tab for editing streams.
const $add_subscribers_container = $(".edit_subscribers_for_stream .subscriber_list_settings"); const $add_subscribers_container = $(".edit_subscribers_for_stream .subscriber_list_settings");
if (page_params.is_guest || page_params.realm_is_zephyr_mirror_realm) { if (current_user.is_guest || page_params.realm_is_zephyr_mirror_realm) {
// For guest users, we just hide the add_subscribers feature. // For guest users, we just hide the add_subscribers feature.
$add_subscribers_container.hide(); $add_subscribers_container.hide();
return; return;

View File

@ -2,12 +2,12 @@ import * as Sentry from "@sentry/browser";
import * as blueslip from "./blueslip"; import * as blueslip from "./blueslip";
import * as channel from "./channel"; import * as channel from "./channel";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as reload from "./reload"; import * as reload from "./reload";
import * as reload_state from "./reload_state"; import * as reload_state from "./reload_state";
import * as sent_messages from "./sent_messages"; import * as sent_messages from "./sent_messages";
import * as server_events from "./server_events"; import * as server_events from "./server_events";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
export function send_message(request, on_success, error) { export function send_message(request, on_success, error) {
@ -108,7 +108,7 @@ export function reply_message(opts) {
const local_id = sent_messages.get_new_local_id(); const local_id = sent_messages.get_new_local_id();
const reply = { const reply = {
sender_id: page_params.user_id, sender_id: current_user.user_id,
queue_id: server_events.queue_id, queue_id: server_events.queue_id,
local_id, local_id,
}; };

View File

@ -6,6 +6,7 @@ import render_typing_notifications from "../templates/typing_notifications.hbs";
import * as narrow_state from "./narrow_state"; import * as narrow_state from "./narrow_state";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import {current_user} from "./state_data";
import * as typing_data from "./typing_data"; import * as typing_data from "./typing_data";
// See docs/subsystems/typing-indicators.md for details on typing indicators. // See docs/subsystems/typing-indicators.md for details on typing indicators.
@ -77,7 +78,7 @@ function get_users_typing_for_narrow(): number[] {
const narrow_user_ids = narrow_user_ids_string const narrow_user_ids = narrow_user_ids_string
.split(",") .split(",")
.map((user_id_string) => Number.parseInt(user_id_string, 10)); .map((user_id_string) => Number.parseInt(user_id_string, 10));
const group = [...narrow_user_ids, page_params.user_id]; const group = [...narrow_user_ids, current_user.user_id];
return typing_data.get_group_typists(group); return typing_data.get_group_typists(group);
} }
// Get all users typing (in all direct message conversations with current user) // Get all users typing (in all direct message conversations with current user)

View File

@ -114,6 +114,7 @@ import * as sidebar_ui from "./sidebar_ui";
import * as spoilers from "./spoilers"; import * as spoilers from "./spoilers";
import * as starred_messages from "./starred_messages"; import * as starred_messages from "./starred_messages";
import * as starred_messages_ui from "./starred_messages_ui"; import * as starred_messages_ui from "./starred_messages_ui";
import {current_user, set_current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_edit from "./stream_edit"; import * as stream_edit from "./stream_edit";
import * as stream_edit_subscribers from "./stream_edit_subscribers"; import * as stream_edit_subscribers from "./stream_edit_subscribers";
@ -162,7 +163,7 @@ function initialize_bottom_whitespace() {
function initialize_navbar() { function initialize_navbar() {
const rendered_navbar = render_navbar({ const rendered_navbar = render_navbar({
embedded: page_params.narrow_stream !== undefined, embedded: page_params.narrow_stream !== undefined,
user_avatar: page_params.avatar_url_medium, user_avatar: current_user.avatar_url_medium,
}); });
$("#header-container").html(rendered_navbar); $("#header-container").html(rendered_navbar);
@ -490,6 +491,31 @@ export function initialize_everything() {
); );
const local_message_params = pop_fields("max_message_id"); const local_message_params = pop_fields("max_message_id");
const current_user_params = pop_fields(
"avatar_source",
"avatar_url",
"avatar_url_medium",
"can_create_private_streams",
"can_create_public_streams",
"can_create_streams",
"can_create_web_public_streams",
"can_invite_others_to_realm",
"can_subscribe_other_users",
"delivery_email",
"email",
"full_name",
"has_zoom_token",
"is_admin",
"is_billing_admin",
"is_guest",
"is_moderator",
"is_owner",
"onboarding_steps",
"user_id",
);
set_current_user(current_user_params);
/* To store theme data for spectators, we need to initialize /* To store theme data for spectators, we need to initialize
user_settings before setting the theme. */ user_settings before setting the theme. */
initialize_user_settings(user_settings_params); initialize_user_settings(user_settings_params);
@ -521,12 +547,12 @@ export function initialize_everything() {
scheduled_messages_popover.initialize(); scheduled_messages_popover.initialize();
realm_user_settings_defaults.initialize(realm_settings_defaults_params); realm_user_settings_defaults.initialize(realm_settings_defaults_params);
people.initialize(page_params.user_id, people_params); people.initialize(current_user.user_id, people_params);
starred_messages.initialize(starred_messages_params); starred_messages.initialize(starred_messages_params);
let date_joined; let date_joined;
if (!page_params.is_spectator) { if (!page_params.is_spectator) {
const user = people.get_by_user_id(page_params.user_id); const user = people.get_by_user_id(current_user.user_id);
date_joined = user.date_joined; date_joined = user.date_joined;
} else { } else {
// Spectators don't have an account, so we just prevent their // Spectators don't have an account, so we just prevent their

View File

@ -32,6 +32,7 @@ import {hide_all} from "./popovers";
import * as rows from "./rows"; import * as rows from "./rows";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as sidebar_ui from "./sidebar_ui"; import * as sidebar_ui from "./sidebar_ui";
import {current_user} from "./state_data";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
@ -479,7 +480,7 @@ function toggle_user_card_popover_manage_menu(element, user) {
const args = { const args = {
can_mute: muting_allowed && !is_muted, can_mute: muting_allowed && !is_muted,
can_manage_user: page_params.is_admin && !is_me && !is_system_bot, can_manage_user: current_user.is_admin && !is_me && !is_system_bot,
can_unmute: muting_allowed && is_muted, can_unmute: muting_allowed && is_muted,
is_active: people.is_active_user_for_popover(user.user_id), is_active: people.is_active_user_for_popover(user.user_id),
is_bot: user.is_bot, is_bot: user.is_bot,

View File

@ -10,7 +10,6 @@ import {buddy_list} from "./buddy_list";
import * as compose_state from "./compose_state"; import * as compose_state from "./compose_state";
import * as message_live_update from "./message_live_update"; import * as message_live_update from "./message_live_update";
import * as narrow_state from "./narrow_state"; import * as narrow_state from "./narrow_state";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as pm_list from "./pm_list"; import * as pm_list from "./pm_list";
import * as settings from "./settings"; import * as settings from "./settings";
@ -22,6 +21,7 @@ import * as settings_profile_fields from "./settings_profile_fields";
import * as settings_realm_user_settings_defaults from "./settings_realm_user_settings_defaults"; import * as settings_realm_user_settings_defaults from "./settings_realm_user_settings_defaults";
import * as settings_streams from "./settings_streams"; import * as settings_streams from "./settings_streams";
import * as settings_users from "./settings_users"; import * as settings_users from "./settings_users";
import {current_user} from "./state_data";
import * as stream_events from "./stream_events"; import * as stream_events from "./stream_events";
export const update_person = function update(person) { export const update_person = function update(person) {
@ -40,7 +40,7 @@ export const update_person = function update(person) {
compose_state.update_email(user_id, new_email); compose_state.update_email(user_id, new_email);
if (people.is_my_user_id(person.user_id)) { if (people.is_my_user_id(person.user_id)) {
page_params.email = new_email; current_user.email = new_email;
} }
people.update_email(user_id, new_email); people.update_email(user_id, new_email);
@ -51,7 +51,7 @@ export const update_person = function update(person) {
person_obj.delivery_email = delivery_email; person_obj.delivery_email = delivery_email;
if (people.is_my_user_id(person.user_id)) { if (people.is_my_user_id(person.user_id)) {
settings_account.update_email(delivery_email); settings_account.update_email(delivery_email);
page_params.delivery_email = delivery_email; current_user.delivery_email = delivery_email;
settings_account.hide_confirm_email_banner(); settings_account.hide_confirm_email_banner();
} }
} }
@ -64,7 +64,7 @@ export const update_person = function update(person) {
message_live_update.update_user_full_name(person.user_id, person.full_name); message_live_update.update_user_full_name(person.user_id, person.full_name);
pm_list.update_private_messages(); pm_list.update_private_messages();
if (people.is_my_user_id(person.user_id)) { if (people.is_my_user_id(person.user_id)) {
page_params.full_name = person.full_name; current_user.full_name = person.full_name;
settings_account.update_full_name(person.full_name); settings_account.update_full_name(person.full_name);
} }
} }
@ -78,14 +78,14 @@ export const update_person = function update(person) {
person_obj.is_moderator = person.role === settings_config.user_role_values.moderator.code; person_obj.is_moderator = person.role === settings_config.user_role_values.moderator.code;
settings_users.update_user_data(person.user_id, person); settings_users.update_user_data(person.user_id, person);
if (people.is_my_user_id(person.user_id) && page_params.is_owner !== person_obj.is_owner) { if (people.is_my_user_id(person.user_id) && current_user.is_owner !== person_obj.is_owner) {
page_params.is_owner = person_obj.is_owner; current_user.is_owner = person_obj.is_owner;
settings_org.maybe_disable_widgets(); settings_org.maybe_disable_widgets();
settings.update_lock_icon_in_sidebar(); settings.update_lock_icon_in_sidebar();
} }
if (people.is_my_user_id(person.user_id) && page_params.is_admin !== person_obj.is_admin) { if (people.is_my_user_id(person.user_id) && current_user.is_admin !== person_obj.is_admin) {
page_params.is_admin = person_obj.is_admin; current_user.is_admin = person_obj.is_admin;
settings_linkifiers.maybe_disable_widgets(); settings_linkifiers.maybe_disable_widgets();
settings_org.maybe_disable_widgets(); settings_org.maybe_disable_widgets();
settings_profile_fields.maybe_disable_widgets(); settings_profile_fields.maybe_disable_widgets();
@ -97,16 +97,16 @@ export const update_person = function update(person) {
if ( if (
people.is_my_user_id(person.user_id) && people.is_my_user_id(person.user_id) &&
page_params.is_moderator !== person_obj.is_moderator current_user.is_moderator !== person_obj.is_moderator
) { ) {
page_params.is_moderator = person_obj.is_moderator; current_user.is_moderator = person_obj.is_moderator;
} }
} }
if (Object.hasOwn(person, "is_billing_admin")) { if (Object.hasOwn(person, "is_billing_admin")) {
person_obj.is_billing_admin = person.is_billing_admin; person_obj.is_billing_admin = person.is_billing_admin;
if (people.is_my_user_id(person.user_id)) { if (people.is_my_user_id(person.user_id)) {
page_params.is_billing_admin = person_obj.is_billing_admin; current_user.is_billing_admin = person_obj.is_billing_admin;
} }
} }
@ -116,9 +116,9 @@ export const update_person = function update(person) {
person_obj.avatar_version = person.avatar_version; person_obj.avatar_version = person.avatar_version;
if (people.is_my_user_id(person.user_id)) { if (people.is_my_user_id(person.user_id)) {
page_params.avatar_source = person.avatar_source; current_user.avatar_source = person.avatar_source;
page_params.avatar_url = url; current_user.avatar_url = url;
page_params.avatar_url_medium = person.avatar_url_medium; current_user.avatar_url_medium = person.avatar_url_medium;
$("#user-avatar-upload-widget .image-block").attr("src", person.avatar_url_medium); $("#user-avatar-upload-widget .image-block").attr("src", person.avatar_url_medium);
$("#personal-menu .header-button-avatar").attr("src", `${person.avatar_url_medium}`); $("#personal-menu .header-button-avatar").attr("src", `${person.avatar_url_medium}`);
} }

View File

@ -5,8 +5,8 @@ import render_new_user_group_users from "../templates/user_group_settings/new_us
import * as add_subscribers_pill from "./add_subscribers_pill"; import * as add_subscribers_pill from "./add_subscribers_pill";
import * as ListWidget from "./list_widget"; import * as ListWidget from "./list_widget";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import {current_user} from "./state_data";
import * as user_group_create_members_data from "./user_group_create_members_data"; import * as user_group_create_members_data from "./user_group_create_members_data";
import * as user_sort from "./user_sort"; import * as user_sort from "./user_sort";
@ -88,7 +88,7 @@ export function build_widgets() {
build_pill_widget({$parent_container: $add_people_container}); build_pill_widget({$parent_container: $add_people_container});
user_group_create_members_data.initialize_with_current_user(); user_group_create_members_data.initialize_with_current_user();
const current_user_id = page_params.user_id; const current_user_id = current_user.user_id;
all_users_list_widget = ListWidget.create($("#create_user_group_members"), [current_user_id], { all_users_list_widget = ListWidget.create($("#create_user_group_members"), [current_user_id], {
name: "new_user_group_add_users", name: "new_user_group_add_users",

View File

@ -1,11 +1,11 @@
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import type {User} from "./people"; import type {User} from "./people";
import {current_user} from "./state_data";
let user_id_set: Set<number>; let user_id_set: Set<number>;
export function initialize_with_current_user(): void { export function initialize_with_current_user(): void {
user_id_set = new Set([page_params.user_id]); user_id_set = new Set([current_user.user_id]);
} }
export function sorted_user_ids(): number[] { export function sorted_user_ids(): number[] {

View File

@ -23,6 +23,7 @@ import * as scroll_util from "./scroll_util";
import * as settings_components from "./settings_components"; import * as settings_components from "./settings_components";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
import {current_user} from "./state_data";
import * as stream_ui_updates from "./stream_ui_updates"; import * as stream_ui_updates from "./stream_ui_updates";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as user_group_components from "./user_group_components"; import * as user_group_components from "./user_group_components";
@ -79,7 +80,7 @@ function update_add_members_elements(group) {
// We are only concerned with the Members tab for editing groups. // We are only concerned with the Members tab for editing groups.
const $add_members_container = $(".edit_members_for_user_group .add_members_container"); const $add_members_container = $(".edit_members_for_user_group .add_members_container");
if (page_params.is_guest || page_params.realm_is_zephyr_mirror_realm) { if (current_user.is_guest || page_params.realm_is_zephyr_mirror_realm) {
// For guest users, we just hide the add_members feature. // For guest users, we just hide the add_members feature.
$add_members_container.hide(); $add_members_container.hide();
return; return;

View File

@ -11,10 +11,10 @@ import * as channel from "./channel";
import * as confirm_dialog from "./confirm_dialog"; import * as confirm_dialog from "./confirm_dialog";
import {$t, $t_html} from "./i18n"; import {$t, $t_html} from "./i18n";
import * as ListWidget from "./list_widget"; import * as ListWidget from "./list_widget";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
import * as user_sort from "./user_sort"; import * as user_sort from "./user_sort";
@ -53,7 +53,7 @@ function format_member_list_elem(person) {
return render_user_group_member_list_entry({ return render_user_group_member_list_entry({
name: person.full_name, name: person.full_name,
user_id: person.user_id, user_id: person.user_id,
is_current_user: person.user_id === page_params.user_id, is_current_user: person.user_id === current_user.user_id,
email: person.delivery_email, email: person.delivery_email,
can_remove_subscribers: settings_data.can_edit_user_group(current_group_id), can_remove_subscribers: settings_data.can_edit_user_group(current_group_id),
for_user_group_members: true, for_user_group_members: true,
@ -181,13 +181,13 @@ function add_new_members({pill_user_ids}) {
const user_id_set = new Set(active_user_ids); const user_id_set = new Set(active_user_ids);
if ( if (
user_id_set.has(page_params.user_id) && user_id_set.has(current_user.user_id) &&
user_groups.is_user_in_group(group.id, page_params.user_id) user_groups.is_user_in_group(group.id, current_user.user_id)
) { ) {
// We don't want to send a request to add ourselves if we // We don't want to send a request to add ourselves if we
// are already added to this group. This case occurs // are already added to this group. This case occurs
// when creating user pills from a stream or user group. // when creating user pills from a stream or user group.
user_id_set.delete(page_params.user_id); user_id_set.delete(current_user.user_id);
} }
let ignored_deactivated_users; let ignored_deactivated_users;
@ -286,7 +286,7 @@ function remove_member({group_id, target_user_id, $list_entry}) {
}); });
} }
if (people.is_my_user_id(target_user_id) && !page_params.is_admin) { if (people.is_my_user_id(target_user_id) && !current_user.is_admin) {
const html_body = render_leave_user_group_modal({ const html_body = render_leave_user_group_modal({
message: $t({ message: $t({
defaultMessage: "Once you leave this group, you will not be able to rejoin.", defaultMessage: "Once you leave this group, you will not be able to rejoin.",

View File

@ -8,11 +8,11 @@ import * as blueslip from "./blueslip";
import * as buddy_data from "./buddy_data"; import * as buddy_data from "./buddy_data";
import * as hash_util from "./hash_util"; import * as hash_util from "./hash_util";
import * as message_lists from "./message_lists"; import * as message_lists from "./message_lists";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import type {User} from "./people"; import type {User} from "./people";
import * as popover_menus from "./popover_menus"; import * as popover_menus from "./popover_menus";
import * as rows from "./rows"; import * as rows from "./rows";
import {current_user} from "./state_data";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
import * as util from "./util"; import * as util from "./util";
@ -97,7 +97,7 @@ export function toggle_user_group_info_popover(
group_description: group.description, group_description: group.description,
members: sort_group_members(fetch_group_members([...group.members])), members: sort_group_members(fetch_group_members([...group.members])),
group_edit_url: hash_util.group_edit_url(group), group_edit_url: hash_util.group_edit_url(group),
is_guest: page_params.is_guest, is_guest: current_user.is_guest,
}; };
instance.setContent(ui_util.parse_html(render_user_group_info_popover(args))); instance.setContent(ui_util.parse_html(render_user_group_info_popover(args)));
}, },

View File

@ -1,8 +1,8 @@
import * as blueslip from "./blueslip"; import * as blueslip from "./blueslip";
import {FoldDict} from "./fold_dict"; import {FoldDict} from "./fold_dict";
import * as group_permission_settings from "./group_permission_settings"; import * as group_permission_settings from "./group_permission_settings";
import {page_params} from "./page_params";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import {current_user} from "./state_data";
import type {UserOrMention} from "./typeahead_helper"; import type {UserOrMention} from "./typeahead_helper";
import type {UserGroupUpdateEvent} from "./types"; import type {UserGroupUpdateEvent} from "./types";
@ -100,7 +100,7 @@ export function get_user_groups_allowed_to_mention(): UserGroup[] {
const user_groups = get_realm_user_groups(); const user_groups = get_realm_user_groups();
return user_groups.filter((group) => { return user_groups.filter((group) => {
const can_mention_group_id = group.can_mention_group; const can_mention_group_id = group.can_mention_group;
return is_user_in_group(can_mention_group_id, page_params.user_id); return is_user_in_group(can_mention_group_id, current_user.user_id);
}); });
} }

View File

@ -31,6 +31,7 @@ import * as people from "./people";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as settings_profile_fields from "./settings_profile_fields"; import * as settings_profile_fields from "./settings_profile_fields";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_ui_updates from "./stream_ui_updates"; import * as stream_ui_updates from "./stream_ui_updates";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
@ -361,7 +362,7 @@ export function show_user_profile(user, default_tab_key = "profile-tab") {
// We currently have the main UI for editing your own profile in // We currently have the main UI for editing your own profile in
// settings, so can_manage_profile is artificially false for those. // settings, so can_manage_profile is artificially false for those.
const can_manage_profile = const can_manage_profile =
(people.can_admin_user(user) || page_params.is_admin) && (people.can_admin_user(user) || current_user.is_admin) &&
!user.is_system_bot && !user.is_system_bot &&
!people.is_my_user_id(user.user_id); !people.is_my_user_id(user.user_id);
const args = { const args = {
@ -498,7 +499,7 @@ export function show_edit_bot_info_modal(user_id, $container) {
email: bot.email, email: bot.email,
full_name: bot.full_name, full_name: bot.full_name,
user_role_values: settings_config.user_role_values, user_role_values: settings_config.user_role_values,
disable_role_dropdown: !page_params.is_admin || (bot.is_owner && !page_params.is_owner), disable_role_dropdown: !current_user.is_admin || (bot.is_owner && !current_user.is_owner),
bot_avatar_url: bot.avatar_url, bot_avatar_url: bot.avatar_url,
owner_full_name, owner_full_name,
current_bot_owner: bot.bot_owner_id, current_bot_owner: bot.bot_owner_id,
@ -606,7 +607,7 @@ export function show_edit_bot_info_modal(user_id, $container) {
bot_owner_dropdown_widget.setup(); bot_owner_dropdown_widget.setup();
$("#bot-role-select").val(bot.role); $("#bot-role-select").val(bot.role);
if (!page_params.is_owner) { if (!current_user.is_owner) {
$("#bot-role-select") $("#bot-role-select")
.find(`option[value="${CSS.escape(settings_config.user_role_values.owner.code)}"]`) .find(`option[value="${CSS.escape(settings_config.user_role_values.owner.code)}"]`)
.hide(); .hide();
@ -722,7 +723,7 @@ export function show_edit_user_info_modal(user_id, $container) {
email: person.delivery_email, email: person.delivery_email,
full_name: person.full_name, full_name: person.full_name,
user_role_values: settings_config.user_role_values, user_role_values: settings_config.user_role_values,
disable_role_dropdown: person.is_owner && !page_params.is_owner, disable_role_dropdown: person.is_owner && !current_user.is_owner,
owner_is_only_user_in_organization: people.get_active_human_count() === 1, owner_is_only_user_in_organization: people.get_active_human_count() === 1,
is_active, is_active,
}); });
@ -730,7 +731,7 @@ export function show_edit_user_info_modal(user_id, $container) {
$container.append(html_body); $container.append(html_body);
// Set role dropdown and fields user pills // Set role dropdown and fields user pills
$("#user-role-select").val(person.role); $("#user-role-select").val(person.role);
if (!page_params.is_owner) { if (!current_user.is_owner) {
$("#user-role-select") $("#user-role-select")
.find(`option[value="${CSS.escape(settings_config.user_role_values.owner.code)}"]`) .find(`option[value="${CSS.escape(settings_config.user_role_values.owner.code)}"]`)
.hide(); .hide();

View File

@ -12,4 +12,5 @@ export {cancel as cancel_compose} from "./compose_actions";
export {page_params, page_params_parse_time} from "./page_params"; export {page_params, page_params_parse_time} from "./page_params";
export {initiate as initiate_reload} from "./reload"; export {initiate as initiate_reload} from "./reload";
export {page_load_time} from "./setup"; export {page_load_time} from "./setup";
export {current_user} from "./state_data";
export {add_user_id_to_new_stream} from "./stream_create_subscribers"; export {add_user_id_to_new_stream} from "./stream_create_subscribers";

View File

@ -11,7 +11,7 @@
<label class="inline-block title">{{t "Email" }}</label> <label class="inline-block title">{{t "Email" }}</label>
<div id="change_email_button_container" class="inline-block {{#unless user_can_change_email}}disabled_setting_tooltip{{/unless}}"> <div id="change_email_button_container" class="inline-block {{#unless user_can_change_email}}disabled_setting_tooltip{{/unless}}">
<button id="change_email_button" type="button" class="button btn-link small rounded inline-block" {{#unless user_can_change_email}}disabled="disabled"{{/unless}}> <button id="change_email_button" type="button" class="button btn-link small rounded inline-block" {{#unless user_can_change_email}}disabled="disabled"{{/unless}}>
{{page_params.delivery_email}} {{current_user.delivery_email}}
<i class="fa fa-pencil"></i> <i class="fa fa-pencil"></i>
</button> </button>
</div> </div>

View File

@ -1,6 +1,6 @@
<div id="bot-settings" class="settings-section" data-name="your-bots"> <div id="bot-settings" class="settings-section" data-name="your-bots">
<div class="bot-settings-form"> <div class="bot-settings-form">
{{#unless page_params.is_guest}} {{#unless current_user.is_guest}}
<div class="tip"> <div class="tip">
{{#tr}} {{#tr}}
Looking for our <z-integrations>integrations</z-integrations> or <z-api>API</z-api> documentation? Looking for our <z-integrations>integrations</z-integrations> or <z-api>API</z-api> documentation?

View File

@ -9,7 +9,7 @@
<label for="full_name" class="title inline-block">{{t "Full name" }}</label> <label for="full_name" class="title inline-block">{{t "Full name" }}</label>
<div class="alert-notification full-name-status"></div> <div class="alert-notification full-name-status"></div>
<div id="full_name_input_container" {{#unless user_can_change_name}}class="disabled_setting_tooltip"{{/unless}}> <div id="full_name_input_container" {{#unless user_can_change_name}}class="disabled_setting_tooltip"{{/unless}}>
<input id="full_name" name="full_name" class="settings_text_input" type="text" value="{{ page_params.full_name }}" {{#unless user_can_change_name}}disabled="disabled"{{/unless}} maxlength="60" /> <input id="full_name" name="full_name" class="settings_text_input" type="text" value="{{ current_user.full_name }}" {{#unless user_can_change_name}}disabled="disabled"{{/unless}} maxlength="60" />
</div> </div>
</div> </div>
</div> </div>
@ -45,7 +45,7 @@
delete_text = (t "Delete profile picture") delete_text = (t "Delete profile picture")
disabled_text = (t "Avatar changes are disabled in this organization") disabled_text = (t "Avatar changes are disabled in this organization")
is_editable_by_current_user = user_can_change_avatar is_editable_by_current_user = user_can_change_avatar
image = page_params.avatar_url_medium}} image = current_user.avatar_url_medium}}
<div id="user-avatar-source"> <div id="user-avatar-source">
<a href="https://en.gravatar.com/" target="_blank" rel="noopener noreferrer">{{t "Avatar from Gravatar" }}</a> <a href="https://en.gravatar.com/" target="_blank" rel="noopener noreferrer">{{t "Avatar from Gravatar" }}</a>
</div> </div>

View File

@ -6,7 +6,7 @@ const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespac
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
const $window_stub = $.create("window-stub"); const $window_stub = $.create("window-stub");
set_global("to_$", () => $window_stub); set_global("to_$", () => $window_stub);
@ -138,17 +138,17 @@ run_test("reload_defaults", () => {
test("get_status", () => { test("get_status", () => {
page_params.realm_users = []; page_params.realm_users = [];
page_params.user_id = 999; current_user.user_id = 999;
assert.equal(presence.get_status(page_params.user_id), "active"); assert.equal(presence.get_status(current_user.user_id), "active");
assert.equal(presence.get_status(alice.user_id), "active"); assert.equal(presence.get_status(alice.user_id), "active");
assert.equal(presence.get_status(mark.user_id), "idle"); assert.equal(presence.get_status(mark.user_id), "idle");
assert.equal(presence.get_status(fred.user_id), "active"); assert.equal(presence.get_status(fred.user_id), "active");
user_settings.presence_enabled = false; user_settings.presence_enabled = false;
assert.equal(presence.get_status(page_params.user_id), "offline"); assert.equal(presence.get_status(current_user.user_id), "offline");
user_settings.presence_enabled = true; user_settings.presence_enabled = true;
assert.equal(presence.get_status(page_params.user_id), "active"); assert.equal(presence.get_status(current_user.user_id), "active");
presence.presence_info.delete(zoe.user_id); presence.presence_info.delete(zoe.user_id);
assert.equal(presence.get_status(zoe.user_id), "offline"); assert.equal(presence.get_status(zoe.user_id), "offline");

View File

@ -7,7 +7,7 @@ const _ = require("lodash");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
const timerender = mock_esm("../src/timerender"); const timerender = mock_esm("../src/timerender");
@ -316,7 +316,7 @@ test("title_data", () => {
third_line: "translated: Active now", third_line: "translated: Active now",
show_you: true, show_you: true,
}; };
page_params.user_id = me.user_id; current_user.user_id = me.user_id;
assert.deepEqual(buddy_data.get_title_data(me.user_id, is_group), expected_data); assert.deepEqual(buddy_data.get_title_data(me.user_id, is_group), expected_data);
expected_data = { expected_data = {

View File

@ -10,7 +10,7 @@ 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 $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
const settings_config = zrequire("settings_config"); const settings_config = zrequire("settings_config");
@ -231,7 +231,7 @@ test_ui("send_message", ({override, override_rewire, mock_template}) => {
stub_state = initialize_state_stub_dict(); stub_state = initialize_state_stub_dict();
compose_state.topic(""); compose_state.topic("");
compose_state.set_message_type("private"); compose_state.set_message_type("private");
page_params.user_id = new_user.user_id; current_user.user_id = new_user.user_id;
override(compose_pm_pill, "get_emails", () => "alice@example.com"); override(compose_pm_pill, "get_emails", () => "alice@example.com");
const server_message_id = 127; const server_message_id = 127;
@ -367,7 +367,7 @@ test_ui("enter_with_preview_open", ({override, override_rewire}) => {
show_button_spinner_called = true; show_button_spinner_called = true;
}); });
page_params.user_id = new_user.user_id; current_user.user_id = new_user.user_id;
// Test sending a message with content. // Test sending a message with content.
compose_state.set_message_type("stream"); compose_state.set_message_type("stream");

View File

@ -8,7 +8,7 @@ const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
const channel = mock_esm("../src/channel"); const channel = mock_esm("../src/channel");
const compose_banner = zrequire("compose_banner"); const compose_banner = zrequire("compose_banner");
@ -318,21 +318,21 @@ test_ui("get_invalid_recipient_emails", ({override_rewire}) => {
full_name: "Welcome Bot", full_name: "Welcome Bot",
}; };
page_params.user_id = me.user_id; current_user.user_id = me.user_id;
const params = {}; const params = {};
params.realm_users = []; params.realm_users = [];
params.realm_non_active_users = []; params.realm_non_active_users = [];
params.cross_realm_bots = [welcome_bot]; params.cross_realm_bots = [welcome_bot];
people.initialize(page_params.user_id, params); people.initialize(current_user.user_id, params);
override_rewire(compose_state, "private_message_recipient", () => "welcome-bot@example.com"); override_rewire(compose_state, "private_message_recipient", () => "welcome-bot@example.com");
assert.deepEqual(compose_validate.get_invalid_recipient_emails(), []); assert.deepEqual(compose_validate.get_invalid_recipient_emails(), []);
}); });
test_ui("test_stream_wildcard_mention_allowed", ({override_rewire}) => { test_ui("test_stream_wildcard_mention_allowed", ({override_rewire}) => {
page_params.user_id = me.user_id; current_user.user_id = me.user_id;
// First, check for large streams (>15 subscribers) where the wildcard mention // First, check for large streams (>15 subscribers) where the wildcard mention
// policy matters. // policy matters.
@ -340,50 +340,50 @@ test_ui("test_stream_wildcard_mention_allowed", ({override_rewire}) => {
page_params.realm_wildcard_mention_policy = page_params.realm_wildcard_mention_policy =
settings_config.wildcard_mention_policy_values.by_everyone.code; settings_config.wildcard_mention_policy_values.by_everyone.code;
page_params.is_guest = true; current_user.is_guest = true;
page_params.is_admin = false; current_user.is_admin = false;
assert.ok(compose_validate.stream_wildcard_mention_allowed()); assert.ok(compose_validate.stream_wildcard_mention_allowed());
page_params.realm_wildcard_mention_policy = page_params.realm_wildcard_mention_policy =
settings_config.wildcard_mention_policy_values.nobody.code; settings_config.wildcard_mention_policy_values.nobody.code;
page_params.is_admin = true; current_user.is_admin = true;
assert.ok(!compose_validate.stream_wildcard_mention_allowed()); assert.ok(!compose_validate.stream_wildcard_mention_allowed());
page_params.realm_wildcard_mention_policy = page_params.realm_wildcard_mention_policy =
settings_config.wildcard_mention_policy_values.by_members.code; settings_config.wildcard_mention_policy_values.by_members.code;
page_params.is_guest = true; current_user.is_guest = true;
page_params.is_admin = false; current_user.is_admin = false;
assert.ok(!compose_validate.stream_wildcard_mention_allowed()); assert.ok(!compose_validate.stream_wildcard_mention_allowed());
page_params.is_guest = false; current_user.is_guest = false;
assert.ok(compose_validate.stream_wildcard_mention_allowed()); assert.ok(compose_validate.stream_wildcard_mention_allowed());
page_params.realm_wildcard_mention_policy = page_params.realm_wildcard_mention_policy =
settings_config.wildcard_mention_policy_values.by_moderators_only.code; settings_config.wildcard_mention_policy_values.by_moderators_only.code;
page_params.is_moderator = false; current_user.is_moderator = false;
assert.ok(!compose_validate.stream_wildcard_mention_allowed()); assert.ok(!compose_validate.stream_wildcard_mention_allowed());
page_params.is_moderator = true; current_user.is_moderator = true;
assert.ok(compose_validate.stream_wildcard_mention_allowed()); assert.ok(compose_validate.stream_wildcard_mention_allowed());
page_params.realm_wildcard_mention_policy = page_params.realm_wildcard_mention_policy =
settings_config.wildcard_mention_policy_values.by_admins_only.code; settings_config.wildcard_mention_policy_values.by_admins_only.code;
page_params.is_admin = false; current_user.is_admin = false;
assert.ok(!compose_validate.stream_wildcard_mention_allowed()); assert.ok(!compose_validate.stream_wildcard_mention_allowed());
// TODO: Add a by_admins_only case when we implement stream-level administrators. // TODO: Add a by_admins_only case when we implement stream-level administrators.
page_params.is_admin = true; current_user.is_admin = true;
assert.ok(compose_validate.stream_wildcard_mention_allowed()); assert.ok(compose_validate.stream_wildcard_mention_allowed());
page_params.realm_wildcard_mention_policy = page_params.realm_wildcard_mention_policy =
settings_config.wildcard_mention_policy_values.by_full_members.code; settings_config.wildcard_mention_policy_values.by_full_members.code;
const person = people.get_by_user_id(page_params.user_id); const person = people.get_by_user_id(current_user.user_id);
person.date_joined = new Date(Date.now()); person.date_joined = new Date(Date.now());
page_params.realm_waiting_period_threshold = 10; page_params.realm_waiting_period_threshold = 10;
assert.ok(compose_validate.stream_wildcard_mention_allowed()); assert.ok(compose_validate.stream_wildcard_mention_allowed());
page_params.is_admin = false; current_user.is_admin = false;
assert.ok(!compose_validate.stream_wildcard_mention_allowed()); assert.ok(!compose_validate.stream_wildcard_mention_allowed());
// Now, check for small streams (<=15 subscribers) where the wildcard mention // Now, check for small streams (<=15 subscribers) where the wildcard mention
@ -391,8 +391,8 @@ test_ui("test_stream_wildcard_mention_allowed", ({override_rewire}) => {
override_rewire(peer_data, "get_subscriber_count", () => 14); override_rewire(peer_data, "get_subscriber_count", () => 14);
page_params.realm_wildcard_mention_policy = page_params.realm_wildcard_mention_policy =
settings_config.wildcard_mention_policy_values.by_admins_only.code; settings_config.wildcard_mention_policy_values.by_admins_only.code;
page_params.is_admin = false; current_user.is_admin = false;
page_params.is_guest = true; current_user.is_guest = true;
assert.ok(compose_validate.stream_wildcard_mention_allowed()); assert.ok(compose_validate.stream_wildcard_mention_allowed());
}); });
@ -402,7 +402,7 @@ test_ui("validate_stream_message", ({override_rewire, mock_template}) => {
// we are separating it up in different test. Though their relative position // we are separating it up in different test. Though their relative position
// of execution should not be changed. // of execution should not be changed.
mock_banners(); mock_banners();
page_params.user_id = me.user_id; current_user.user_id = me.user_id;
page_params.realm_mandatory_topics = false; page_params.realm_mandatory_topics = false;
const special_sub = { const special_sub = {
@ -452,7 +452,7 @@ test_ui("test_validate_stream_message_post_policy_admin_only", ({mock_template})
// Although the position with respect to test_validate_stream_message does not matter // Although the position with respect to test_validate_stream_message does not matter
// as different stream is used for this test. // as different stream is used for this test.
mock_banners(); mock_banners();
page_params.is_admin = false; current_user.is_admin = false;
const sub_stream_102 = { const sub_stream_102 = {
stream_id: 102, stream_id: 102,
name: "stream102", name: "stream102",
@ -482,8 +482,8 @@ test_ui("test_validate_stream_message_post_policy_admin_only", ({mock_template})
// Reset error message. // Reset error message.
compose_state.set_stream_id(social_sub.stream_id); compose_state.set_stream_id(social_sub.stream_id);
page_params.is_admin = false; current_user.is_admin = false;
page_params.is_guest = true; current_user.is_guest = true;
compose_state.topic("topic102"); compose_state.topic("topic102");
compose_state.set_stream_id(sub_stream_102.stream_id); compose_state.set_stream_id(sub_stream_102.stream_id);
@ -495,9 +495,9 @@ test_ui("test_validate_stream_message_post_policy_admin_only", ({mock_template})
test_ui("test_validate_stream_message_post_policy_moderators_only", ({mock_template}) => { test_ui("test_validate_stream_message_post_policy_moderators_only", ({mock_template}) => {
mock_banners(); mock_banners();
page_params.is_admin = false; current_user.is_admin = false;
page_params.is_moderator = false; current_user.is_moderator = false;
page_params.is_guest = false; current_user.is_guest = false;
const sub = { const sub = {
stream_id: 104, stream_id: 104,
@ -526,15 +526,15 @@ test_ui("test_validate_stream_message_post_policy_moderators_only", ({mock_templ
// Reset error message. // Reset error message.
compose_state.set_stream_id(social_sub.stream_id); compose_state.set_stream_id(social_sub.stream_id);
page_params.is_guest = true; current_user.is_guest = true;
assert.ok(!compose_validate.validate()); assert.ok(!compose_validate.validate());
assert.ok(banner_rendered); assert.ok(banner_rendered);
}); });
test_ui("test_validate_stream_message_post_policy_full_members_only", ({mock_template}) => { test_ui("test_validate_stream_message_post_policy_full_members_only", ({mock_template}) => {
mock_banners(); mock_banners();
page_params.is_admin = false; current_user.is_admin = false;
page_params.is_guest = true; current_user.is_guest = true;
const sub = { const sub = {
stream_id: 103, stream_id: 103,
name: "stream103", name: "stream103",

View File

@ -6,7 +6,7 @@ const events = require("./lib/events");
const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespace"); const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
const channel = mock_esm("../src/channel"); const channel = mock_esm("../src/channel");
const compose_closed_ui = mock_esm("../src/compose_closed_ui"); const compose_closed_ui = mock_esm("../src/compose_closed_ui");
@ -171,7 +171,7 @@ test("videos", ({override}) => {
}); });
page_params.realm_video_chat_provider = realm_available_video_chat_providers.zoom.id; page_params.realm_video_chat_provider = realm_available_video_chat_providers.zoom.id;
page_params.has_zoom_token = false; current_user.has_zoom_token = false;
window.open = (url) => { window.open = (url) => {
assert.ok(url.endsWith("/calls/zoom/register")); assert.ok(url.endsWith("/calls/zoom/register"));

View File

@ -7,7 +7,7 @@ const {mock_banners} = require("./lib/compose_banner");
const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespace"); const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
let autosize_called; let autosize_called;
@ -1609,7 +1609,7 @@ test("content_highlighter", ({override_rewire}) => {
test("filter_and_sort_mentions (normal)", () => { test("filter_and_sort_mentions (normal)", () => {
compose_state.set_message_type("stream"); compose_state.set_message_type("stream");
const is_silent = false; const is_silent = false;
page_params.user_id = 101; current_user.user_id = 101;
let suggestions = ct.filter_and_sort_mentions(is_silent, "al"); let suggestions = ct.filter_and_sort_mentions(is_silent, "al");
const mention_all = ct.broadcast_mentions()[0]; const mention_all = ct.broadcast_mentions()[0];
@ -1617,14 +1617,14 @@ test("filter_and_sort_mentions (normal)", () => {
// call_center group is shown in typeahead even when user is member of // call_center group is shown in typeahead even when user is member of
// one of the subgroups of can_mention_group. // one of the subgroups of can_mention_group.
page_params.user_id = 104; current_user.user_id = 104;
suggestions = ct.filter_and_sort_mentions(is_silent, "al"); suggestions = ct.filter_and_sort_mentions(is_silent, "al");
assert.deepEqual(suggestions, [mention_all, ali, alice, hal, call_center]); assert.deepEqual(suggestions, [mention_all, ali, alice, hal, call_center]);
// call_center group is not shown in typeahead when user is neither // call_center group is not shown in typeahead when user is neither
// a direct member of can_mention_group nor a member of any of its // a direct member of can_mention_group nor a member of any of its
// recursive subgroups. // recursive subgroups.
page_params.user_id = 102; current_user.user_id = 102;
suggestions = ct.filter_and_sort_mentions(is_silent, "al"); suggestions = ct.filter_and_sort_mentions(is_silent, "al");
assert.deepEqual(suggestions, [mention_all, ali, alice, hal]); assert.deepEqual(suggestions, [mention_all, ali, alice, hal]);
}); });
@ -1639,7 +1639,7 @@ test("filter_and_sort_mentions (silent)", () => {
// call_center group is shown in typeahead irrespective of whether // call_center group is shown in typeahead irrespective of whether
// user is member of can_mention_group or its subgroups for a // user is member of can_mention_group or its subgroups for a
// silent mention. // silent mention.
page_params.user_id = 102; current_user.user_id = 102;
suggestions = ct.filter_and_sort_mentions(is_silent, "al"); suggestions = ct.filter_and_sort_mentions(is_silent, "al");
assert.deepEqual(suggestions, [ali, alice, hal, call_center]); assert.deepEqual(suggestions, [ali, alice, hal, call_center]);
}); });
@ -1750,7 +1750,7 @@ test("typeahead_results", () => {
// Earlier user group and stream mentions were autocompleted by their // Earlier user group and stream mentions were autocompleted by their
// description too. This is now removed as it often led to unexpected // description too. This is now removed as it often led to unexpected
// behaviour, and did not have any great discoverability advantage. // behaviour, and did not have any great discoverability advantage.
page_params.user_id = 101; current_user.user_id = 101;
// Autocomplete user group mentions by group name. // Autocomplete user group mentions by group name.
assert_mentions_matches("hamletchar", [hamletcharacters]); assert_mentions_matches("hamletchar", [hamletcharacters]);

View File

@ -8,7 +8,12 @@ const {make_stub} = require("./lib/stub");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params, realm_user_settings_defaults, user_settings} = require("./lib/zpage_params"); const {
current_user,
page_params,
realm_user_settings_defaults,
user_settings,
} = require("./lib/zpage_params");
const event_fixtures = events.fixtures; const event_fixtures = events.fixtures;
const test_message = events.test_message; const test_message = events.test_message;
@ -108,7 +113,7 @@ message_lists.all_rendered_message_lists = () => [message_lists.home, message_li
// page_params is highly coupled to dispatching now // page_params is highly coupled to dispatching now
page_params.test_suite = false; page_params.test_suite = false;
page_params.is_admin = true; current_user.is_admin = true;
page_params.realm_description = "already set description"; page_params.realm_description = "already set description";
// For data-oriented modules, just use them, don't stub them. // For data-oriented modules, just use them, don't stub them.
@ -303,11 +308,11 @@ run_test("default_streams", ({override}) => {
}); });
run_test("onboarding_steps", ({override}) => { run_test("onboarding_steps", ({override}) => {
page_params.onboarding_steps = []; current_user.onboarding_steps = [];
const event = event_fixtures.onboarding_steps; const event = event_fixtures.onboarding_steps;
override(hotspots, "load_new", noop); override(hotspots, "load_new", noop);
dispatch(event); dispatch(event);
assert_same(page_params.onboarding_steps, event.onboarding_steps); assert_same(current_user.onboarding_steps, event.onboarding_steps);
}); });
run_test("invites_changed", ({override}) => { run_test("invites_changed", ({override}) => {
@ -414,7 +419,7 @@ run_test("scheduled_messages", ({override}) => {
}); });
run_test("realm settings", ({override}) => { run_test("realm settings", ({override}) => {
page_params.is_admin = true; current_user.is_admin = true;
page_params.realm_date_created = new Date("2023-01-01Z"); page_params.realm_date_created = new Date("2023-01-01Z");
override(settings_org, "sync_realm_settings", noop); override(settings_org, "sync_realm_settings", noop);
@ -772,7 +777,7 @@ run_test("submessage", ({override}) => {
run_test("typing", ({override}) => { run_test("typing", ({override}) => {
// Simulate that we are not typing. // Simulate that we are not typing.
page_params.user_id = typing_person1.user_id + 1; current_user.user_id = typing_person1.user_id + 1;
let event = event_fixtures.typing__start; let event = event_fixtures.typing__start;
{ {
@ -795,10 +800,10 @@ run_test("typing", ({override}) => {
} }
// Get line coverage--we ignore our own typing events. // Get line coverage--we ignore our own typing events.
page_params.user_id = typing_person1.user_id; current_user.user_id = typing_person1.user_id;
event = event_fixtures.typing__start; event = event_fixtures.typing__start;
dispatch(event); dispatch(event);
page_params.user_id = undefined; // above change shouldn't effect stream_typing tests below current_user.user_id = undefined; // above change shouldn't effect stream_typing tests below
}); });
run_test("stream_typing", ({override}) => { run_test("stream_typing", ({override}) => {

View File

@ -7,7 +7,7 @@ const MockDate = require("mockdate");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {make_stub} = require("./lib/stub"); const {make_stub} = require("./lib/stub");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const {page_params} = require("./lib/zpage_params"); const {current_user} = require("./lib/zpage_params");
const compose_notifications = mock_esm("../src/compose_notifications"); const compose_notifications = mock_esm("../src/compose_notifications");
const markdown = mock_esm("../src/markdown"); const markdown = mock_esm("../src/markdown");
@ -124,7 +124,7 @@ run_test("process_from_server for differently rendered messages", ({override}) =
}); });
run_test("build_display_recipient", () => { run_test("build_display_recipient", () => {
page_params.user_id = 123; current_user.user_id = 123;
const params = {}; const params = {};
params.realm_users = [ params.realm_users = [
@ -141,7 +141,7 @@ run_test("build_display_recipient", () => {
]; ];
params.realm_non_active_users = []; params.realm_non_active_users = [];
params.cross_realm_bots = []; params.cross_realm_bots = [];
people.initialize(page_params.user_id, params); people.initialize(current_user.user_id, params);
let message = { let message = {
type: "stream", type: "stream",
@ -260,7 +260,7 @@ run_test("insert_local_message streams", ({override}) => {
run_test("insert_local_message direct message", ({override}) => { run_test("insert_local_message direct message", ({override}) => {
const local_id_float = 102.01; const local_id_float = 102.01;
page_params.user_id = 123; current_user.user_id = 123;
const params = {}; const params = {};
params.realm_users = [ params.realm_users = [
@ -272,7 +272,7 @@ run_test("insert_local_message direct message", ({override}) => {
]; ];
params.realm_non_active_users = []; params.realm_non_active_users = [];
params.cross_realm_bots = []; params.cross_realm_bots = [];
people.initialize(page_params.user_id, params); people.initialize(current_user.user_id, params);
let render_called = false; let render_called = false;
let insert_message_called = false; let insert_message_called = false;

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); const {current_user} = require("./lib/zpage_params");
mock_esm("../src/settings_data", { mock_esm("../src/settings_data", {
user_can_access_all_other_users: () => true, user_can_access_all_other_users: () => true,
@ -78,7 +78,7 @@ run_test("typing_events.render_notifications_for_narrow", ({override, mock_templ
const $typing_notifications = $("#typing_notifications"); const $typing_notifications = $("#typing_notifications");
// Narrow to a group direct message with four users. // Narrow to a group direct message with four users.
override(page_params, "user_id", anna.user_id); override(current_user, "user_id", anna.user_id);
const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id]; const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
const conversation_key = typing_data.get_direct_message_conversation_key(group); const conversation_key = typing_data.get_direct_message_conversation_key(group);
const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`; const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;

View File

@ -93,10 +93,11 @@ run_test("tr_tag", ({mock_template}) => {
settings: {}, settings: {},
}, },
notification_settings: {}, notification_settings: {},
page_params: { current_user: {
full_name: "John Doe", full_name: "John Doe",
delivery_email: "john@zulip.com", delivery_email: "john@zulip.com",
}, },
page_params: {},
settings_object: {}, settings_object: {},
settings_label: { settings_label: {
desktop_icon_count_display: desktop_icon_count_display:

View File

@ -122,6 +122,8 @@ test.set_verbose(files.length === 1);
require("../../src/billing/page_params"); require("../../src/billing/page_params");
namespace.mock_esm("../../src/page_params", zpage_params); namespace.mock_esm("../../src/page_params", zpage_params);
require("../../src/page_params"); require("../../src/page_params");
namespace.mock_esm("../../src/state_data", zpage_params);
require("../../src/state_data");
namespace.mock_esm("../../src/user_settings", zpage_params); namespace.mock_esm("../../src/user_settings", zpage_params);
require("../../src/user_settings"); require("../../src/user_settings");
namespace.mock_esm("../../src/realm_user_settings_defaults", zpage_params); namespace.mock_esm("../../src/realm_user_settings_defaults", zpage_params);

View File

@ -1,10 +1,16 @@
"use strict"; "use strict";
exports.current_user = {};
exports.page_params = {}; exports.page_params = {};
exports.realm_user_settings_defaults = {}; exports.realm_user_settings_defaults = {};
exports.user_settings = {}; exports.user_settings = {};
exports.reset = () => { exports.reset = () => {
for (const field in exports.current_user) {
if (Object.hasOwn(exports.current_user, field)) {
delete exports.current_user[field];
}
}
for (const field in exports.page_params) { for (const field in exports.page_params) {
if (Object.hasOwn(exports.page_params, field)) { if (Object.hasOwn(exports.page_params, field)) {
delete exports.page_params[field]; delete exports.page_params[field];

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
page_params.realm_move_messages_within_stream_limit_seconds = 259200; page_params.realm_move_messages_within_stream_limit_seconds = 259200;
@ -92,7 +92,7 @@ run_test("is_topic_editable", ({override}) => {
}; };
page_params.realm_allow_message_editing = true; page_params.realm_allow_message_editing = true;
override(settings_data, "user_can_move_messages_to_another_topic", () => true); override(settings_data, "user_can_move_messages_to_another_topic", () => true);
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(message_edit.is_topic_editable(message), false); assert.equal(message_edit.is_topic_editable(message), false);
@ -109,7 +109,7 @@ run_test("is_topic_editable", ({override}) => {
override(settings_data, "user_can_move_messages_to_another_topic", () => false); override(settings_data, "user_can_move_messages_to_another_topic", () => false);
assert.equal(message_edit.is_topic_editable(message), false); assert.equal(message_edit.is_topic_editable(message), false);
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(message_edit.is_topic_editable(message), false); assert.equal(message_edit.is_topic_editable(message), false);
message.topic = "translated: (no topic)"; message.topic = "translated: (no topic)";
@ -128,7 +128,7 @@ run_test("is_topic_editable", ({override}) => {
message.timestamp = current_timestamp - 600000; message.timestamp = current_timestamp - 600000;
assert.equal(message_edit.is_topic_editable(message), false); assert.equal(message_edit.is_topic_editable(message), false);
page_params.is_moderator = true; current_user.is_moderator = true;
assert.equal(message_edit.is_topic_editable(message), true); assert.equal(message_edit.is_topic_editable(message), true);
page_params.realm_allow_message_editing = false; page_params.realm_allow_message_editing = false;
@ -146,7 +146,7 @@ run_test("is_stream_editable", ({override}) => {
}; };
page_params.realm_allow_message_editing = true; page_params.realm_allow_message_editing = true;
override(settings_data, "user_can_move_messages_between_streams", () => true); override(settings_data, "user_can_move_messages_between_streams", () => true);
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(message_edit.is_stream_editable(message), false); assert.equal(message_edit.is_stream_editable(message), false);
@ -163,7 +163,7 @@ run_test("is_stream_editable", ({override}) => {
override(settings_data, "user_can_move_messages_between_streams", () => false); override(settings_data, "user_can_move_messages_between_streams", () => false);
assert.equal(message_edit.is_stream_editable(message), false); assert.equal(message_edit.is_stream_editable(message), false);
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(message_edit.is_stream_editable(message), false); assert.equal(message_edit.is_stream_editable(message), false);
page_params.realm_move_messages_between_streams_limit_seconds = 259200; page_params.realm_move_messages_between_streams_limit_seconds = 259200;
@ -175,12 +175,12 @@ run_test("is_stream_editable", ({override}) => {
message.timestamp = current_timestamp - 600000; message.timestamp = current_timestamp - 600000;
assert.equal(message_edit.is_stream_editable(message), false); assert.equal(message_edit.is_stream_editable(message), false);
page_params.is_moderator = true; current_user.is_moderator = true;
assert.equal(message_edit.is_stream_editable(message), true); assert.equal(message_edit.is_stream_editable(message), true);
}); });
run_test("get_deletability", ({override}) => { run_test("get_deletability", ({override}) => {
page_params.is_admin = true; current_user.is_admin = true;
override(settings_data, "user_can_delete_own_message", () => false); override(settings_data, "user_can_delete_own_message", () => false);
page_params.realm_message_content_delete_limit_seconds = null; page_params.realm_message_content_delete_limit_seconds = null;
const test_user = { const test_user = {
@ -208,7 +208,7 @@ run_test("get_deletability", ({override}) => {
assert.equal(message_edit.get_deletability(message), true); assert.equal(message_edit.get_deletability(message), true);
// Non-admin can't delete message sent by others // Non-admin can't delete message sent by others
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(message_edit.get_deletability(message), false); assert.equal(message_edit.get_deletability(message), false);
// Locally echoed messages are not deletable // Locally echoed messages are not deletable

View File

@ -7,7 +7,7 @@ const {make_stub} = require("./lib/stub");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); const {current_user} = require("./lib/zpage_params");
// These unit tests for web/src/message_list.js emphasize the model-ish // These unit tests for web/src/message_list.js emphasize the model-ish
// aspects of the MessageList class. We have to stub out a few functions // aspects of the MessageList class. We have to stub out a few functions
@ -245,7 +245,7 @@ run_test("last_sent_by_me", () => {
]; ];
list.append(items); list.append(items);
page_params.user_id = 3; current_user.user_id = 3;
// Look for the last message where user_id == 3 (our ID) // Look for the last message where user_id == 3 (our ID)
assert.equal(list.get_last_message_sent_by_me().id, 2); assert.equal(list.get_last_message_sent_by_me().id, 2);
}); });

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
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 blueslip = require("./lib/zblueslip");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
mock_esm("../src/stream_topic_history", { mock_esm("../src/stream_topic_history", {
add_message: noop, add_message: noop,
@ -18,7 +18,7 @@ mock_esm("../src/recent_senders", {
set_global("document", "document-stub"); set_global("document", "document-stub");
page_params.realm_allow_message_editing = true; page_params.realm_allow_message_editing = true;
page_params.is_admin = true; current_user.is_admin = true;
const util = zrequire("util"); const util = zrequire("util");
const people = zrequire("people"); const people = zrequire("people");

View File

@ -6,7 +6,7 @@ const {addDays} = require("date-fns");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
page_params.is_spectator = false; page_params.is_spectator = false;
@ -68,16 +68,16 @@ test("profile_incomplete_alert", ({override}) => {
override(timerender, "should_display_profile_incomplete_alert", () => true); override(timerender, "should_display_profile_incomplete_alert", () => true);
// Show alert. // Show alert.
page_params.is_admin = true; current_user.is_admin = true;
page_params.realm_description = "Organization imported from Slack!"; page_params.realm_description = "Organization imported from Slack!";
assert.equal(navbar_alerts.check_profile_incomplete(), true); assert.equal(navbar_alerts.check_profile_incomplete(), true);
// Avoid showing if the user is not admin. // Avoid showing if the user is not admin.
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(navbar_alerts.check_profile_incomplete(), false); assert.equal(navbar_alerts.check_profile_incomplete(), false);
// Avoid showing if the realm description is already updated. // Avoid showing if the realm description is already updated.
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(navbar_alerts.check_profile_incomplete(), true); assert.equal(navbar_alerts.check_profile_incomplete(), true);
page_params.realm_description = "Organization description already set!"; page_params.realm_description = "Organization description already set!";
assert.equal(navbar_alerts.check_profile_incomplete(), false); assert.equal(navbar_alerts.check_profile_incomplete(), false);

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
mock_esm("../src/spoilers", {hide_spoilers_in_notification() {}}); mock_esm("../src/spoilers", {hide_spoilers_in_notification() {}});
@ -50,7 +50,7 @@ user_topics.update_user_topics(
function test(label, f) { function test(label, f) {
run_test(label, (helpers) => { run_test(label, (helpers) => {
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_users = []; page_params.realm_users = [];
user_settings.enable_followed_topic_desktop_notifications = true; user_settings.enable_followed_topic_desktop_notifications = true;
user_settings.enable_followed_topic_audible_notifications = true; user_settings.enable_followed_topic_audible_notifications = true;

View File

@ -11,15 +11,15 @@ const {strict: assert} = require("assert");
const {zrequire} = require("./lib/namespace"); const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
const peer_data = zrequire("peer_data"); const peer_data = zrequire("peer_data");
const people = zrequire("people"); const people = zrequire("people");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_users = []; page_params.realm_users = [];
page_params.is_guest = false; current_user.is_guest = false;
const me = { const me = {
email: "me@zulip.com", email: "me@zulip.com",

View File

@ -10,7 +10,7 @@ const {$t} = require("./lib/i18n");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
const message_user_ids = mock_esm("../src/message_user_ids"); const message_user_ids = mock_esm("../src/message_user_ids");
const settings_data = mock_esm("../src/settings_data", { const settings_data = mock_esm("../src/settings_data", {
@ -698,11 +698,11 @@ test_people("set_custom_profile_field_data", () => {
test_people("is_current_user_only_owner", () => { test_people("is_current_user_only_owner", () => {
const person = people.get_by_email(me.email); const person = people.get_by_email(me.email);
person.is_owner = false; person.is_owner = false;
page_params.is_owner = false; current_user.is_owner = false;
assert.ok(!people.is_current_user_only_owner()); assert.ok(!people.is_current_user_only_owner());
person.is_owner = true; person.is_owner = true;
page_params.is_owner = true; current_user.is_owner = true;
assert.ok(people.is_current_user_only_owner()); assert.ok(people.is_current_user_only_owner());
people.add_active_user(realm_owner); people.add_active_user(realm_owner);
@ -1237,7 +1237,7 @@ test_people("filter_for_user_settings_search", () => {
so that is where we do more thorough testing. so that is where we do more thorough testing.
This test is just a sanity check for now. This test is just a sanity check for now.
*/ */
page_params.is_admin = false; current_user.is_admin = false;
const fred_smith = {full_name: "Fred Smith"}; const fred_smith = {full_name: "Fred Smith"};
const alice_lee = {full_name: "Alice Lee"}; const alice_lee = {full_name: "Alice Lee"};
@ -1256,12 +1256,12 @@ test_people("filter_for_user_settings_search", () => {
test_people("matches_user_settings_search", () => { test_people("matches_user_settings_search", () => {
const match = people.matches_user_settings_search; const match = people.matches_user_settings_search;
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(match({email: "fred@example.com"}, "fred"), false); assert.equal(match({email: "fred@example.com"}, "fred"), false);
assert.equal(match({full_name: "Fred Smith"}, "fr"), true); assert.equal(match({full_name: "Fred Smith"}, "fr"), true);
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(match({delivery_email: "fred@example.com"}, "fr"), true); assert.equal(match({delivery_email: "fred@example.com"}, "fr"), true);
assert.equal( assert.equal(

View File

@ -7,7 +7,7 @@ const {make_stub} = require("./lib/stub");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
const alice_user_id = 5; const alice_user_id = 5;
@ -108,7 +108,7 @@ people.add_active_user(alexus);
function test(label, f) { function test(label, f) {
run_test(label, (helpers) => { run_test(label, (helpers) => {
page_params.user_id = alice_user_id; current_user.user_id = alice_user_id;
f(helpers); f(helpers);
}); });
} }

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
const narrow_state = mock_esm("../src/narrow_state"); const narrow_state = mock_esm("../src/narrow_state");
const stream_topic_history_util = mock_esm("../src/stream_topic_history_util"); const stream_topic_history_util = mock_esm("../src/stream_topic_history_util");
@ -52,7 +52,7 @@ const jeff = {
const example_avatar_url = "http://example.com/example.png"; const example_avatar_url = "http://example.com/example.png";
function init() { function init() {
page_params.is_admin = true; current_user.is_admin = true;
people.init(); people.init();
people.add_active_user(bob); people.add_active_user(bob);

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const {zrequire} = require("./lib/namespace"); const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
const bot_data_params = { const bot_data_params = {
realm_bots: [ realm_bots: [
@ -92,10 +92,10 @@ test("generate_botserverrc_content", () => {
}); });
test("can_create_new_bots", () => { test("can_create_new_bots", () => {
page_params.is_admin = true; current_user.is_admin = true;
assert.ok(settings_bots.can_create_new_bots()); assert.ok(settings_bots.can_create_new_bots());
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_bot_creation_policy = 1; page_params.realm_bot_creation_policy = 1;
assert.ok(settings_bots.can_create_new_bots()); assert.ok(settings_bots.can_create_new_bots());

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const {zrequire} = require("./lib/namespace"); const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
const settings_data = zrequire("settings_data"); const settings_data = zrequire("settings_data");
const settings_config = zrequire("settings_config"); const settings_config = zrequire("settings_config");
@ -27,10 +27,10 @@ const isaac = {
run_test("user_can_change_email", () => { run_test("user_can_change_email", () => {
const can_change_email = settings_data.user_can_change_email; const can_change_email = settings_data.user_can_change_email;
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(can_change_email(), true); assert.equal(can_change_email(), true);
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_email_changes_disabled = true; page_params.realm_email_changes_disabled = true;
assert.equal(can_change_email(), false); assert.equal(can_change_email(), false);
@ -41,10 +41,10 @@ run_test("user_can_change_email", () => {
run_test("user_can_change_name", () => { run_test("user_can_change_name", () => {
const can_change_name = settings_data.user_can_change_name; const can_change_name = settings_data.user_can_change_name;
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(can_change_name(), true); assert.equal(can_change_name(), true);
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_name_changes_disabled = true; page_params.realm_name_changes_disabled = true;
page_params.server_name_changes_disabled = false; page_params.server_name_changes_disabled = false;
assert.equal(can_change_name(), false); assert.equal(can_change_name(), false);
@ -61,10 +61,10 @@ run_test("user_can_change_name", () => {
run_test("user_can_change_avatar", () => { run_test("user_can_change_avatar", () => {
const can_change_avatar = settings_data.user_can_change_avatar; const can_change_avatar = settings_data.user_can_change_avatar;
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(can_change_avatar(), true); assert.equal(can_change_avatar(), true);
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_avatar_changes_disabled = true; page_params.realm_avatar_changes_disabled = true;
page_params.server_avatar_changes_disabled = false; page_params.server_avatar_changes_disabled = false;
assert.equal(can_change_avatar(), false); assert.equal(can_change_avatar(), false);
@ -81,44 +81,44 @@ run_test("user_can_change_avatar", () => {
run_test("user_can_change_logo", () => { run_test("user_can_change_logo", () => {
const can_change_logo = settings_data.user_can_change_logo; const can_change_logo = settings_data.user_can_change_logo;
page_params.is_admin = true; current_user.is_admin = true;
page_params.zulip_plan_is_not_limited = true; page_params.zulip_plan_is_not_limited = true;
assert.equal(can_change_logo(), true); assert.equal(can_change_logo(), true);
page_params.is_admin = false; current_user.is_admin = false;
page_params.zulip_plan_is_not_limited = false; page_params.zulip_plan_is_not_limited = false;
assert.equal(can_change_logo(), false); assert.equal(can_change_logo(), false);
page_params.is_admin = true; current_user.is_admin = true;
page_params.zulip_plan_is_not_limited = false; page_params.zulip_plan_is_not_limited = false;
assert.equal(can_change_logo(), false); assert.equal(can_change_logo(), false);
page_params.is_admin = false; current_user.is_admin = false;
page_params.zulip_plan_is_not_limited = true; page_params.zulip_plan_is_not_limited = true;
assert.equal(can_change_logo(), false); assert.equal(can_change_logo(), false);
}); });
function test_policy(label, policy, validation_func) { function test_policy(label, policy, validation_func) {
run_test(label, () => { run_test(label, () => {
page_params.is_admin = true; current_user.is_admin = true;
page_params[policy] = settings_config.common_policy_values.by_admins_only.code; page_params[policy] = settings_config.common_policy_values.by_admins_only.code;
assert.equal(validation_func(), true); assert.equal(validation_func(), true);
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(validation_func(), false); assert.equal(validation_func(), false);
page_params.is_moderator = true; current_user.is_moderator = true;
page_params[policy] = settings_config.common_policy_values.by_moderators_only.code; page_params[policy] = settings_config.common_policy_values.by_moderators_only.code;
assert.equal(validation_func(), true); assert.equal(validation_func(), true);
page_params.is_moderator = false; current_user.is_moderator = false;
assert.equal(validation_func(), false); assert.equal(validation_func(), false);
page_params.is_guest = true; current_user.is_guest = true;
page_params[policy] = settings_config.common_policy_values.by_members.code; page_params[policy] = settings_config.common_policy_values.by_members.code;
assert.equal(validation_func(), false); assert.equal(validation_func(), false);
page_params.is_guest = false; current_user.is_guest = false;
assert.equal(validation_func(), true); assert.equal(validation_func(), true);
page_params.is_spectator = true; page_params.is_spectator = true;
@ -129,7 +129,7 @@ function test_policy(label, policy, validation_func) {
assert.equal(validation_func(), true); assert.equal(validation_func(), true);
page_params[policy] = settings_config.common_policy_values.by_full_members.code; page_params[policy] = settings_config.common_policy_values.by_full_members.code;
page_params.user_id = 30; current_user.user_id = 30;
isaac.date_joined = new Date(Date.now()); isaac.date_joined = new Date(Date.now());
settings_data.initialize(isaac.date_joined); settings_data.initialize(isaac.date_joined);
page_params.realm_waiting_period_threshold = 10; page_params.realm_waiting_period_threshold = 10;
@ -179,32 +179,32 @@ test_policy(
function test_message_policy(label, policy, validation_func) { function test_message_policy(label, policy, validation_func) {
run_test(label, () => { run_test(label, () => {
page_params.is_admin = true; current_user.is_admin = true;
page_params[policy] = settings_config.common_message_policy_values.by_admins_only.code; page_params[policy] = settings_config.common_message_policy_values.by_admins_only.code;
assert.equal(validation_func(), true); assert.equal(validation_func(), true);
page_params.is_admin = false; current_user.is_admin = false;
page_params.is_moderator = true; current_user.is_moderator = true;
assert.equal(validation_func(), false); assert.equal(validation_func(), false);
page_params[policy] = settings_config.common_message_policy_values.by_moderators_only.code; page_params[policy] = settings_config.common_message_policy_values.by_moderators_only.code;
assert.equal(validation_func(), true); assert.equal(validation_func(), true);
page_params.is_moderator = false; current_user.is_moderator = false;
assert.equal(validation_func(), false); assert.equal(validation_func(), false);
page_params.is_guest = true; current_user.is_guest = true;
page_params[policy] = settings_config.common_message_policy_values.by_everyone.code; page_params[policy] = settings_config.common_message_policy_values.by_everyone.code;
assert.equal(validation_func(), true); assert.equal(validation_func(), true);
page_params[policy] = settings_config.common_message_policy_values.by_members.code; page_params[policy] = settings_config.common_message_policy_values.by_members.code;
assert.equal(validation_func(), false); assert.equal(validation_func(), false);
page_params.is_guest = false; current_user.is_guest = false;
assert.equal(validation_func(), true); assert.equal(validation_func(), true);
page_params[policy] = settings_config.common_message_policy_values.by_full_members.code; page_params[policy] = settings_config.common_message_policy_values.by_full_members.code;
page_params.user_id = 30; current_user.user_id = 30;
isaac.date_joined = new Date(Date.now()); isaac.date_joined = new Date(Date.now());
page_params.realm_waiting_period_threshold = 10; page_params.realm_waiting_period_threshold = 10;
settings_data.initialize(isaac.date_joined); settings_data.initialize(isaac.date_joined);
@ -223,15 +223,15 @@ test_message_policy(
); );
run_test("user_can_move_messages_to_another_topic_nobody_case", () => { run_test("user_can_move_messages_to_another_topic_nobody_case", () => {
page_params.is_admin = true; current_user.is_admin = true;
page_params.is_guest = false; current_user.is_guest = false;
page_params.realm_edit_topic_policy = settings_config.edit_topic_policy_values.nobody.code; page_params.realm_edit_topic_policy = settings_config.edit_topic_policy_values.nobody.code;
assert.equal(settings_data.user_can_move_messages_to_another_topic(), false); assert.equal(settings_data.user_can_move_messages_to_another_topic(), false);
}); });
run_test("user_can_move_messages_between_streams_nobody_case", () => { run_test("user_can_move_messages_between_streams_nobody_case", () => {
page_params.is_admin = true; current_user.is_admin = true;
page_params.is_guest = false; current_user.is_guest = false;
page_params.realm_move_messages_between_streams_policy = page_params.realm_move_messages_between_streams_policy =
settings_config.move_messages_between_streams_policy_values.nobody.code; settings_config.move_messages_between_streams_policy_values.nobody.code;
assert.equal(settings_data.user_can_move_messages_between_streams(), false); assert.equal(settings_data.user_can_move_messages_between_streams(), false);
@ -266,15 +266,15 @@ run_test("using_dark_theme", () => {
}); });
run_test("user_can_invite_others_to_realm_nobody_case", () => { run_test("user_can_invite_others_to_realm_nobody_case", () => {
page_params.is_admin = true; current_user.is_admin = true;
page_params.is_guest = false; current_user.is_guest = false;
page_params.realm_invite_to_realm_policy = page_params.realm_invite_to_realm_policy =
settings_config.email_invite_to_realm_policy_values.nobody.code; settings_config.email_invite_to_realm_policy_values.nobody.code;
assert.equal(settings_data.user_can_invite_users_by_email(), false); assert.equal(settings_data.user_can_invite_users_by_email(), false);
}); });
run_test("user_can_create_web_public_streams", () => { run_test("user_can_create_web_public_streams", () => {
page_params.is_owner = true; current_user.is_owner = true;
page_params.server_web_public_streams_enabled = true; page_params.server_web_public_streams_enabled = true;
page_params.realm_enable_spectator_access = true; page_params.realm_enable_spectator_access = true;
page_params.realm_create_web_public_stream_policy = page_params.realm_create_web_public_stream_policy =
@ -299,37 +299,37 @@ run_test("user_can_create_web_public_streams", () => {
page_params.realm_enable_spectator_access = true; page_params.realm_enable_spectator_access = true;
page_params.server_web_public_streams_enabled = true; page_params.server_web_public_streams_enabled = true;
page_params.is_owner = false; current_user.is_owner = false;
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(settings_data.user_can_create_web_public_streams(), false); assert.equal(settings_data.user_can_create_web_public_streams(), false);
page_params.realm_create_web_public_stream_policy = page_params.realm_create_web_public_stream_policy =
settings_config.create_web_public_stream_policy_values.by_admins_only.code; settings_config.create_web_public_stream_policy_values.by_admins_only.code;
assert.equal(settings_data.user_can_create_web_public_streams(), true); assert.equal(settings_data.user_can_create_web_public_streams(), true);
page_params.is_admin = false; current_user.is_admin = false;
page_params.is_moderator = true; current_user.is_moderator = true;
assert.equal(settings_data.user_can_create_web_public_streams(), false); assert.equal(settings_data.user_can_create_web_public_streams(), false);
page_params.realm_create_web_public_stream_policy = page_params.realm_create_web_public_stream_policy =
settings_config.create_web_public_stream_policy_values.by_moderators_only.code; settings_config.create_web_public_stream_policy_values.by_moderators_only.code;
assert.equal(settings_data.user_can_create_web_public_streams(), true); assert.equal(settings_data.user_can_create_web_public_streams(), true);
page_params.is_moderator = false; current_user.is_moderator = false;
assert.equal(settings_data.user_can_create_web_public_streams(), false); assert.equal(settings_data.user_can_create_web_public_streams(), false);
}); });
run_test("user_email_not_configured", () => { run_test("user_email_not_configured", () => {
const user_email_not_configured = settings_data.user_email_not_configured; const user_email_not_configured = settings_data.user_email_not_configured;
page_params.is_owner = false; current_user.is_owner = false;
assert.equal(user_email_not_configured(), false); assert.equal(user_email_not_configured(), false);
page_params.is_owner = true; current_user.is_owner = true;
page_params.delivery_email = ""; current_user.delivery_email = "";
assert.equal(user_email_not_configured(), true); assert.equal(user_email_not_configured(), true);
page_params.delivery_email = "name@example.com"; current_user.delivery_email = "name@example.com";
assert.equal(user_email_not_configured(), false); assert.equal(user_email_not_configured(), false);
}); });
@ -358,17 +358,17 @@ run_test("user_can_create_multiuse_invite", () => {
assert.equal(settings_data.user_can_create_multiuse_invite(), false); assert.equal(settings_data.user_can_create_multiuse_invite(), false);
page_params.realm_create_multiuse_invite_group = 1; page_params.realm_create_multiuse_invite_group = 1;
page_params.user_id = admin_user_id; current_user.user_id = admin_user_id;
assert.equal(settings_data.user_can_create_multiuse_invite(), true); assert.equal(settings_data.user_can_create_multiuse_invite(), true);
page_params.user_id = moderator_user_id; current_user.user_id = moderator_user_id;
assert.equal(settings_data.user_can_create_multiuse_invite(), false); assert.equal(settings_data.user_can_create_multiuse_invite(), false);
page_params.realm_create_multiuse_invite_group = 2; page_params.realm_create_multiuse_invite_group = 2;
page_params.user_id = moderator_user_id; current_user.user_id = moderator_user_id;
assert.equal(settings_data.user_can_create_multiuse_invite(), true); assert.equal(settings_data.user_can_create_multiuse_invite(), true);
page_params.user_id = member_user_id; current_user.user_id = member_user_id;
assert.equal(settings_data.user_can_create_multiuse_invite(), false); assert.equal(settings_data.user_can_create_multiuse_invite(), false);
}); });
@ -386,21 +386,21 @@ run_test("can_edit_user_group", () => {
realm_user_groups: [students], realm_user_groups: [students],
}); });
delete page_params.user_id; delete current_user.user_id;
assert.ok(!settings_data.can_edit_user_group(students.id)); assert.ok(!settings_data.can_edit_user_group(students.id));
page_params.user_id = 3; current_user.user_id = 3;
page_params.is_guest = true; current_user.is_guest = true;
assert.ok(!settings_data.can_edit_user_group(students.id)); assert.ok(!settings_data.can_edit_user_group(students.id));
page_params.is_guest = false; current_user.is_guest = false;
page_params.is_moderator = true; current_user.is_moderator = true;
assert.ok(settings_data.can_edit_user_group(students.id)); assert.ok(settings_data.can_edit_user_group(students.id));
page_params.is_moderator = false; current_user.is_moderator = false;
assert.ok(!settings_data.can_edit_user_group(students.id)); assert.ok(!settings_data.can_edit_user_group(students.id));
page_params.user_id = 2; current_user.user_id = 2;
page_params.realm_waiting_period_threshold = 0; page_params.realm_waiting_period_threshold = 0;
assert.ok(settings_data.can_edit_user_group(students.id)); assert.ok(settings_data.can_edit_user_group(students.id));
}); });
@ -447,13 +447,13 @@ run_test("user_can_access_all_other_users", () => {
page_params.realm_can_access_all_users_group = members.id; page_params.realm_can_access_all_users_group = members.id;
// Test spectators case. // Test spectators case.
page_params.user_id = undefined; current_user.user_id = undefined;
assert.ok(settings_data.user_can_access_all_other_users()); assert.ok(settings_data.user_can_access_all_other_users());
page_params.user_id = member_user_id; current_user.user_id = member_user_id;
assert.ok(settings_data.user_can_access_all_other_users()); assert.ok(settings_data.user_can_access_all_other_users());
page_params.user_id = guest_user_id; current_user.user_id = guest_user_id;
assert.ok(!settings_data.user_can_access_all_other_users()); assert.ok(!settings_data.user_can_access_all_other_users());
page_params.realm_can_access_all_users_group = everyone.id; page_params.realm_can_access_all_users_group = everyone.id;

View File

@ -7,7 +7,7 @@ const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
const realm_icon = mock_esm("../src/realm_icon"); const realm_icon = mock_esm("../src/realm_icon");
@ -29,7 +29,7 @@ const dropdown_widget = zrequire("dropdown_widget");
function test(label, f) { function test(label, f) {
run_test(label, (helpers) => { run_test(label, (helpers) => {
$("#realm-icon-upload-widget .upload-spinner-background").css = noop; $("#realm-icon-upload-widget .upload-spinner-background").css = noop;
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_domains = [ page_params.realm_domains = [
{domain: "example.com", allow_subdomains: true}, {domain: "example.com", allow_subdomains: true},
{domain: "example.org", allow_subdomains: false}, {domain: "example.org", allow_subdomains: false},
@ -634,7 +634,7 @@ test("set_up", ({override, override_rewire}) => {
// TEST set_up() here, but this mostly just allows us to // TEST set_up() here, but this mostly just allows us to
// get access to the click handlers. // get access to the click handlers.
override(page_params, "is_owner", true); override(current_user, "is_owner", true);
settings_org.set_up(); settings_org.set_up();
test_submit_settings_form( test_submit_settings_form(
@ -770,7 +770,7 @@ test("test get_sorted_options_list", () => {
}); });
test("misc", () => { test("misc", () => {
page_params.is_admin = false; current_user.is_admin = false;
$("#user-avatar-upload-widget").length = 1; $("#user-avatar-upload-widget").length = 1;
$("#user_details_section").length = 1; $("#user_details_section").length = 1;
@ -824,7 +824,7 @@ test("misc", () => {
assert.ok($("#user-avatar-upload-widget .image_upload_button").hasClass("hide")); assert.ok($("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
// If organization admin, these UI elements are never disabled. // If organization admin, these UI elements are never disabled.
page_params.is_admin = true; current_user.is_admin = true;
settings_account.update_name_change_display(); settings_account.update_name_change_display();
assert.ok(!$("#full_name").prop("disabled")); assert.ok(!$("#full_name").prop("disabled"));
assert.ok(!$("#full_name_input_container").hasClass("disabled_setting_tooltip")); assert.ok(!$("#full_name_input_container").hasClass("disabled_setting_tooltip"));

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); const {current_user, page_params} = require("./lib/zpage_params");
const loading = mock_esm("../src/loading"); const loading = mock_esm("../src/loading");
@ -53,7 +53,7 @@ function test_populate(opts, template_data) {
const fields_data = opts.fields_data; const fields_data = opts.fields_data;
page_params.custom_profile_field_types = custom_profile_field_types; page_params.custom_profile_field_types = custom_profile_field_types;
page_params.is_admin = opts.is_admin; current_user.is_admin = opts.is_admin;
const $table = $("#admin_profile_fields_table"); const $table = $("#admin_profile_fields_table");
const $rows = $.create("rows"); const $rows = $.create("rows");
const $form = $.create("forms"); const $form = $.create("forms");

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const {zrequire} = require("./lib/namespace"); const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const {page_params} = require("./lib/zpage_params"); const {current_user} = require("./lib/zpage_params");
const people = zrequire("people"); const people = zrequire("people");
const stream_create_subscribers_data = zrequire("stream_create_subscribers_data"); const stream_create_subscribers_data = zrequire("stream_create_subscribers_data");
@ -35,13 +35,13 @@ const test_user103 = {
function test(label, f) { function test(label, f) {
run_test(label, (helpers) => { run_test(label, (helpers) => {
page_params.is_admin = false; current_user.is_admin = false;
people.init(); people.init();
people.add_active_user(me); people.add_active_user(me);
people.add_active_user(test_user101); people.add_active_user(test_user101);
people.add_active_user(test_user102); people.add_active_user(test_user102);
people.add_active_user(test_user103); people.add_active_user(test_user103);
page_params.user_id = me.user_id; current_user.user_id = me.user_id;
people.initialize_current_user(me.user_id); people.initialize_current_user(me.user_id);
f(helpers); f(helpers);
}); });
@ -71,10 +71,10 @@ test("basics", () => {
}); });
test("must_be_subscribed", () => { test("must_be_subscribed", () => {
page_params.is_admin = false; current_user.is_admin = false;
assert.ok(stream_create_subscribers_data.must_be_subscribed(me.user_id)); assert.ok(stream_create_subscribers_data.must_be_subscribed(me.user_id));
assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id)); assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
page_params.is_admin = true; current_user.is_admin = true;
assert.ok(!stream_create_subscribers_data.must_be_subscribed(me.user_id)); assert.ok(!stream_create_subscribers_data.must_be_subscribed(me.user_id));
assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id)); assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
}); });

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {zrequire} = require("./lib/namespace"); const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
// TODO: Remove after we enable support for // TODO: Remove after we enable support for
// web_public_streams in production. // web_public_streams in production.
@ -51,9 +51,9 @@ const moderators_group = {
function test(label, f) { function test(label, f) {
run_test(label, (helpers) => { run_test(label, (helpers) => {
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_users = []; page_params.realm_users = [];
page_params.is_guest = false; current_user.is_guest = false;
people.init(); people.init();
people.add_active_user(me); people.add_active_user(me);
people.initialize_current_user(me.user_id); people.initialize_current_user(me.user_id);
@ -273,12 +273,12 @@ test("get_streams_for_user", () => {
]); ]);
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, []); assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, []);
// Verify can subscribe if we're an administrator. // Verify can subscribe if we're an administrator.
page_params.is_admin = true; current_user.is_admin = true;
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, [ assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, [
world, world,
errors, errors,
]); ]);
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_invite_to_stream_policy = page_params.realm_invite_to_stream_policy =
settings_config.common_policy_values.by_members.code; settings_config.common_policy_values.by_members.code;
@ -341,7 +341,7 @@ test("admin_options", () => {
} }
// non-admins can't do anything // non-admins can't do anything
page_params.is_admin = false; current_user.is_admin = false;
let sub = make_sub(); let sub = make_sub();
assert.ok(!is_realm_admin(sub)); assert.ok(!is_realm_admin(sub));
assert.ok(!can_change_stream_permissions(sub)); assert.ok(!can_change_stream_permissions(sub));
@ -350,7 +350,7 @@ test("admin_options", () => {
assert.equal(sub.color, "blue"); assert.equal(sub.color, "blue");
// the remaining cases are for admin users // the remaining cases are for admin users
page_params.is_admin = true; current_user.is_admin = true;
// admins can make public streams become private // admins can make public streams become private
sub = make_sub(); sub = make_sub();
@ -443,7 +443,7 @@ test("stream_settings", () => {
// For guest user only retrieve subscribed streams // For guest user only retrieve subscribed streams
sub_rows = stream_settings_data.get_updated_unsorted_subs(); sub_rows = stream_settings_data.get_updated_unsorted_subs();
assert.equal(sub_rows.length, 3); assert.equal(sub_rows.length, 3);
page_params.is_guest = true; current_user.is_guest = true;
sub_rows = stream_settings_data.get_updated_unsorted_subs(); sub_rows = stream_settings_data.get_updated_unsorted_subs();
assert.equal(sub_rows[0].name, "c"); assert.equal(sub_rows[0].name, "c");
assert.equal(sub_rows[1].name, "a"); assert.equal(sub_rows[1].name, "a");
@ -935,23 +935,23 @@ test("can_post_messages_in_stream", () => {
history_public_to_subscribers: false, history_public_to_subscribers: false,
stream_post_policy: settings_config.stream_post_policy_values.admins.code, stream_post_policy: settings_config.stream_post_policy_values.admins.code,
}; };
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(stream_data.can_post_messages_in_stream(social), false); assert.equal(stream_data.can_post_messages_in_stream(social), false);
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(stream_data.can_post_messages_in_stream(social), true); assert.equal(stream_data.can_post_messages_in_stream(social), true);
social.stream_post_policy = settings_config.stream_post_policy_values.moderators.code; social.stream_post_policy = settings_config.stream_post_policy_values.moderators.code;
page_params.is_moderator = false; current_user.is_moderator = false;
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(stream_data.can_post_messages_in_stream(social), false); assert.equal(stream_data.can_post_messages_in_stream(social), false);
page_params.is_moderator = true; current_user.is_moderator = true;
assert.equal(stream_data.can_post_messages_in_stream(social), true); assert.equal(stream_data.can_post_messages_in_stream(social), true);
social.stream_post_policy = settings_config.stream_post_policy_values.non_new_members.code; social.stream_post_policy = settings_config.stream_post_policy_values.non_new_members.code;
page_params.is_moderator = false; current_user.is_moderator = false;
me.date_joined = new Date(Date.now()); me.date_joined = new Date(Date.now());
page_params.realm_waiting_period_threshold = 10; page_params.realm_waiting_period_threshold = 10;
assert.equal(stream_data.can_post_messages_in_stream(social), false); assert.equal(stream_data.can_post_messages_in_stream(social), false);
@ -959,7 +959,7 @@ test("can_post_messages_in_stream", () => {
me.date_joined = new Date(Date.now() - 20 * 86400000); me.date_joined = new Date(Date.now() - 20 * 86400000);
assert.equal(stream_data.can_post_messages_in_stream(social), true); assert.equal(stream_data.can_post_messages_in_stream(social), true);
page_params.is_guest = true; current_user.is_guest = true;
assert.equal(stream_data.can_post_messages_in_stream(social), false); assert.equal(stream_data.can_post_messages_in_stream(social), false);
social.stream_post_policy = settings_config.stream_post_policy_values.everyone.code; social.stream_post_policy = settings_config.stream_post_policy_values.everyone.code;
@ -1037,17 +1037,17 @@ test("can_unsubscribe_others", () => {
// Even with the nobody system group, admins can still unsubscribe others. // Even with the nobody system group, admins can still unsubscribe others.
sub.can_remove_subscribers_group = nobody.id; sub.can_remove_subscribers_group = nobody.id;
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(stream_data.can_unsubscribe_others(sub), true); assert.equal(stream_data.can_unsubscribe_others(sub), true);
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(stream_data.can_unsubscribe_others(sub), false); assert.equal(stream_data.can_unsubscribe_others(sub), false);
// This isn't a real state, but we want coverage on !can_view_subscribers. // This isn't a real state, but we want coverage on !can_view_subscribers.
sub.subscribed = false; sub.subscribed = false;
sub.invite_only = true; sub.invite_only = true;
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(stream_data.can_unsubscribe_others(sub), true); assert.equal(stream_data.can_unsubscribe_others(sub), true);
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(stream_data.can_unsubscribe_others(sub), false); assert.equal(stream_data.can_unsubscribe_others(sub), false);
}); });
@ -1161,10 +1161,10 @@ test("can_access_stream_email", () => {
invite_only: true, invite_only: true,
history_public_to_subscribers: false, history_public_to_subscribers: false,
}; };
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(stream_data.can_access_stream_email(social), true); assert.equal(stream_data.can_access_stream_email(social), true);
page_params.is_admin = true; current_user.is_admin = true;
assert.equal(stream_data.can_access_stream_email(social), true); assert.equal(stream_data.can_access_stream_email(social), true);
social.subscribed = false; social.subscribed = false;
@ -1173,10 +1173,10 @@ test("can_access_stream_email", () => {
social.invite_only = false; social.invite_only = false;
assert.equal(stream_data.can_access_stream_email(social), true); assert.equal(stream_data.can_access_stream_email(social), true);
page_params.is_admin = false; current_user.is_admin = false;
assert.equal(stream_data.can_access_stream_email(social), true); assert.equal(stream_data.can_access_stream_email(social), true);
page_params.is_guest = true; current_user.is_guest = true;
assert.equal(stream_data.can_access_stream_email(social), false); assert.equal(stream_data.can_access_stream_email(social), false);
social.subscribed = true; social.subscribed = true;

View File

@ -5,11 +5,11 @@ const {strict: assert} = require("assert");
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 $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
set_global("document", "document-stub"); set_global("document", "document-stub");
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_users = []; page_params.realm_users = [];
// We use this with override. // We use this with override.

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const {page_params} = require("./lib/zpage_params"); const {current_user} = require("./lib/zpage_params");
const channel = mock_esm("../src/channel"); const channel = mock_esm("../src/channel");
const reload = mock_esm("../src/reload"); const reload = mock_esm("../src/reload");
@ -150,7 +150,7 @@ run_test("reply_message_stream", ({override}) => {
send_message_args = data; send_message_args = data;
}); });
page_params.user_id = 44; current_user.user_id = 44;
server_events.queue_id = 66; server_events.queue_id = 66;
sent_messages.get_new_local_id = () => "99"; sent_messages.get_new_local_id = () => "99";
@ -191,7 +191,7 @@ run_test("reply_message_private", ({override}) => {
send_message_args = data; send_message_args = data;
}); });
page_params.user_id = 155; current_user.user_id = 155;
server_events.queue_id = 177; server_events.queue_id = 177;
sent_messages.get_new_local_id = () => "199"; sent_messages.get_new_local_id = () => "199";

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const {page_params, user_settings} = require("./lib/zpage_params"); const {current_user, page_params, user_settings} = require("./lib/zpage_params");
const stream_topic_history = mock_esm("../src/stream_topic_history"); const stream_topic_history = mock_esm("../src/stream_topic_history");
@ -116,7 +116,7 @@ function test(label, f) {
recent_senders.clear_for_testing(); recent_senders.clear_for_testing();
peer_data.clear_for_testing(); peer_data.clear_for_testing();
people.clear_recipient_counts_for_testing(); people.clear_recipient_counts_for_testing();
page_params.is_admin = false; current_user.is_admin = false;
page_params.realm_is_zephyr_mirror_realm = false; page_params.realm_is_zephyr_mirror_realm = false;
f(helpers); f(helpers);

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); const {current_user} = require("./lib/zpage_params");
const settings_data = mock_esm("../src/settings_data"); const settings_data = mock_esm("../src/settings_data");
@ -45,7 +45,7 @@ people.add_active_user(levin);
people.add_active_user(kitty); people.add_active_user(kitty);
run_test("render_notifications_for_narrow", ({override, mock_template}) => { run_test("render_notifications_for_narrow", ({override, mock_template}) => {
override(page_params, "user_id", anna.user_id); override(current_user, "user_id", anna.user_id);
override(settings_data, "user_can_access_all_other_users", () => true); override(settings_data, "user_can_access_all_other_users", () => true);
const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id]; const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
const conversation_key = typing_data.get_direct_message_conversation_key(group); const conversation_key = typing_data.get_direct_message_conversation_key(group);

View File

@ -6,7 +6,7 @@ const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test"); const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip"); const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); const {current_user} = require("./lib/zpage_params");
const message_live_update = mock_esm("../src/message_live_update"); const message_live_update = mock_esm("../src/message_live_update");
const settings_account = mock_esm("../src/settings_account", { const settings_account = mock_esm("../src/settings_account", {
@ -49,7 +49,7 @@ mock_esm("../src/settings_streams", {
maybe_disable_widgets() {}, maybe_disable_widgets() {},
}); });
page_params.is_admin = true; current_user.is_admin = true;
const people = zrequire("people"); const people = zrequire("people");
const settings_config = zrequire("settings_config"); const settings_config = zrequire("settings_config");
@ -127,21 +127,21 @@ run_test("updates", () => {
person = people.get_by_email(me.email); person = people.get_by_email(me.email);
assert.ok(person.is_billing_admin); assert.ok(person.is_billing_admin);
assert.equal(person.role, settings_config.user_role_values.member.code); assert.equal(person.role, settings_config.user_role_values.member.code);
assert.ok(page_params.is_billing_admin); assert.ok(current_user.is_billing_admin);
user_events.update_person({user_id: me.user_id, is_billing_admin: false}); user_events.update_person({user_id: me.user_id, is_billing_admin: false});
person = people.get_by_email(me.email); person = people.get_by_email(me.email);
assert.equal(person.user_id, me.user_id); assert.equal(person.user_id, me.user_id);
assert.ok(!person.is_billing_admin); assert.ok(!person.is_billing_admin);
assert.equal(person.role, settings_config.user_role_values.member.code); assert.equal(person.role, settings_config.user_role_values.member.code);
assert.ok(!page_params.is_billing_admin); assert.ok(!current_user.is_billing_admin);
user_events.update_person({user_id: isaac.user_id, is_billing_admin: false}); user_events.update_person({user_id: isaac.user_id, is_billing_admin: false});
person = people.get_by_email(isaac.email); person = people.get_by_email(isaac.email);
assert.equal(person.user_id, isaac.user_id); assert.equal(person.user_id, isaac.user_id);
assert.ok(!person.is_billing_admin); assert.ok(!person.is_billing_admin);
assert.equal(person.role, settings_config.user_role_values.owner.code); assert.equal(person.role, settings_config.user_role_values.owner.code);
assert.ok(!page_params.is_billing_admin); assert.ok(!current_user.is_billing_admin);
let user_id; let user_id;
let full_name; let full_name;
@ -161,7 +161,7 @@ run_test("updates", () => {
user_id: me.user_id, user_id: me.user_id,
role: settings_config.user_role_values.member.code, role: settings_config.user_role_values.member.code,
}); });
assert.ok(!page_params.is_admin); assert.ok(!current_user.is_admin);
user_events.update_person({user_id: me.user_id, full_name: "Me V2"}); user_events.update_person({user_id: me.user_id, full_name: "Me V2"});
assert.equal(people.my_full_name(), "Me V2"); assert.equal(people.my_full_name(), "Me V2");