Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
admin: Convert module to TypeScript.
Anders Kaseorg0048dfabd007
diff --git a/docs/tutorials/new-feature-tutorial.md b/docs/tutorials/new-feature-tutorial.mdindex 75ce9d38260..39d118a2e4d 100644--- a/docs/tutorials/new-feature-tutorial.md+++ b/docs/tutorials/new-feature-tutorial.md@@ -540,10 +540,10 @@ If you're adding a non-checkbox field, you'll need to specify the typeof the field via the `data-setting-widget-type` attribute in the HTMLtemplate.-Then add the new form control in `web/src/admin.js`.+Then add the new form control in `web/src/admin.ts`.```diff- // web/src/admin.js+ // web/src/admin.tsexport function build_page() {const options = {diff --git a/docs/tutorials/writing-views.md b/docs/tutorials/writing-views.mdindex 72cc82d8464..e0927149724 100644--- a/docs/tutorials/writing-views.md+++ b/docs/tutorials/writing-views.md@@ -340,7 +340,7 @@ users in the Zulip realm), once the current transaction completes.You should always use `channel.<method>` to make an `HTTP <method>` callto the Zulip JSON API. As an example, in-[web/src/admin.js](https://github.com/zulip/zulip/blob/main/web/src/admin.js)+[web/src/admin.ts](https://github.com/zulip/zulip/blob/main/web/src/admin.ts)```jsvar url = "/json/realm";diff --git a/tools/test-js-with-node b/tools/test-js-with-nodeindex 9edf1ceed04..65ec37ebd3c 100755--- a/tools/test-js-with-node+++ b/tools/test-js-with-node@@ -49,7 +49,7 @@ EXEMPT_FILES = make_set("web/src/add_group_members_pill.ts","web/src/add_stream_options_popover.ts","web/src/add_subscribers_pill.ts",- "web/src/admin.js",+ "web/src/admin.ts","web/src/alert_popup.ts","web/src/alert_words_ui.ts","web/src/assets.d.ts",diff --git a/web/src/admin.js b/web/src/admin.tssimilarity index 91%rename from web/src/admin.jsrename to web/src/admin.tsindex 9546ae5f766..35fbba9c5bd 100644--- a/web/src/admin.js+++ b/web/src/admin.ts@@ -13,6 +13,7 @@ import {realm_user_settings_defaults} from "./realm_user_settings_defaults.ts";import * as settings from "./settings.ts";import * as settings_bots from "./settings_bots.ts";import * as settings_components from "./settings_components.ts";+import type {AllNotifications} from "./settings_config.ts";import * as settings_config from "./settings_config.ts";import * as settings_data from "./settings_data.ts";import * as settings_invites from "./settings_invites.ts";@@ -22,6 +23,7 @@ import * as settings_sections from "./settings_sections.ts";import * as settings_toggle from "./settings_toggle.ts";import * as settings_users from "./settings_users.ts";import {current_user, realm} from "./state_data.ts";+import {the} from "./util.ts";const admin_settings_label = {// Organization profile@@ -73,7 +75,7 @@ const admin_settings_label = {}),};-function insert_tip_box() {+function insert_tip_box(): void {if (current_user.is_admin) {return;}@@ -90,7 +92,11 @@ function insert_tip_box() {.prepend($(tip_box_html));}-function get_realm_level_notification_settings(options) {+function get_realm_level_notification_settings(): {+ general_settings: AllNotifications["general_settings"];+ notification_settings: AllNotifications["settings"];+ disabled_notification_settings: AllNotifications["disabled_notification_settings"];+} {const all_notifications_settings = settings_config.all_notifications(realm_user_settings_defaults,);@@ -100,13 +106,27 @@ function get_realm_level_notification_settings(options) {// realm-level defaults for these setting.all_notifications_settings.settings.other_email_settings = ["enable_digest_emails"];- options.general_settings = all_notifications_settings.general_settings;- options.notification_settings = all_notifications_settings.settings;- options.disabled_notification_settings =- all_notifications_settings.disabled_notification_settings;+ return {+ general_settings: all_notifications_settings.general_settings,+ notification_settings: all_notifications_settings.settings,+ disabled_notification_settings: all_notifications_settings.disabled_notification_settings,+ };}-export function build_page() {+export function build_page(): void {+ let realm_night_logo_url = realm.realm_night_logo_url;+ if (realm.realm_logo_source !== "D" && realm.realm_night_logo_source === "D") {+ // If no dark theme logo is specified but a light theme one is,+ // use the light theme one. See also similar code in realm_logo.js.+ realm_night_logo_url = realm.realm_logo_url;+ }++ let giphy_help_link = "/help/animated-gifs-from-giphy";+ if (realm.giphy_api_key === "") {+ giphy_help_link =+ "https://zulip.readthedocs.io/en/latest/production/giphy-gif-integration.html";+ }+const options = {custom_profile_field_types: realm.custom_profile_field_types,full_name: current_user.full_name,@@ -157,7 +177,7 @@ export function build_page() {realm_logo_source: realm.realm_logo_source,realm_logo_url: realm.realm_logo_url,realm_night_logo_source: realm.realm_night_logo_source,- realm_night_logo_url: realm.realm_night_logo_url,+ realm_night_logo_url,realm_mandatory_topics: realm.realm_mandatory_topics,realm_send_welcome_emails: realm.realm_send_welcome_emails,realm_message_content_allowed_in_email_notifications:@@ -230,22 +250,10 @@ export function build_page() {active_user_list_dropdown_widget_name: settings_users.active_user_list_dropdown_widget_name,deactivated_user_list_dropdown_widget_name:settings_users.deactivated_user_list_dropdown_widget_name,+ giphy_help_link,+ ...get_realm_level_notification_settings(),};- if (options.realm_logo_source !== "D" && options.realm_night_logo_source === "D") {- // If no dark theme logo is specified but a light theme one is,- // use the light theme one. See also similar code in realm_logo.js.- options.realm_night_logo_url = options.realm_logo_url;- }-- options.giphy_help_link = "/help/animated-gifs-from-giphy";- if (options.giphy_api_key_empty) {- options.giphy_help_link =- "https://zulip.readthedocs.io/en/latest/production/giphy-gif-integration.html";- }-- get_realm_level_notification_settings(options);-const rendered_admin_tab = render_admin_tab(options);$("#settings_content .organization-box").html(rendered_admin_tab);$("#settings_content .alert").removeClass("show");@@ -261,7 +269,7 @@ export function build_page() {$("#id_realm_bot_creation_policy").val(realm.realm_bot_creation_policy);- $("#id_realm_digest_weekday").val(options.realm_digest_weekday);+ $("#id_realm_digest_weekday").val(realm.realm_digest_weekday);const is_plan_plus = realm.realm_plan_type === 10;const is_plan_self_hosted = realm.realm_plan_type === 1;@@ -273,11 +281,11 @@ export function build_page() {}),};- tippy.default($("#realm_can_access_all_users_group_widget_container")[0], opts);+ tippy.default(the($("#realm_can_access_all_users_group_widget_container")), opts);}}-export function launch(section, user_settings_tab) {+export function launch(section: string, user_settings_tab: string): void {settings_sections.reset_sections();settings.open_settings_overlay();diff --git a/web/src/hashchange.js b/web/src/hashchange.jsindex 2a2b35080a8..7e4c335d22a 100644--- a/web/src/hashchange.js+++ b/web/src/hashchange.js@@ -1,7 +1,7 @@import $ from "jquery";import * as about_zulip from "./about_zulip.ts";-import * as admin from "./admin.js";+import * as admin from "./admin.ts";import * as blueslip from "./blueslip.ts";import * as browser_history from "./browser_history.ts";import * as drafts_overlay_ui from "./drafts_overlay_ui.js";diff --git a/web/src/people.ts b/web/src/people.tsindex dddd81f4999..dab24b4ebe4 100644--- a/web/src/people.ts+++ b/web/src/people.ts@@ -14,7 +14,7 @@ import {page_params} from "./page_params.ts";import * as reload_state from "./reload_state.ts";import * as settings_config from "./settings_config.ts";import * as settings_data from "./settings_data.ts";-import type {StateData, profile_datum_schema, user_schema} from "./state_data.ts";+import type {CurrentUser, StateData, profile_datum_schema, user_schema} from "./state_data.ts";import {current_user, realm} from "./state_data.ts";import * as timerender from "./timerender.ts";import {is_user_in_setting_group} from "./user_groups.ts";@@ -817,7 +817,7 @@ export function gravatar_url_for_email(email: string): string {return "https://secure.gravatar.com/avatar/" + hash + "?d=identicon";}-export function small_avatar_url_for_person(person: User): string {+export function small_avatar_url_for_person(person: User | CurrentUser): string {if (person.avatar_url) {return person.avatar_url;}diff --git a/web/src/realm_logo.ts b/web/src/realm_logo.tsindex acd3634c4cb..26899fb4bd4 100644--- a/web/src/realm_logo.ts+++ b/web/src/realm_logo.ts@@ -80,7 +80,7 @@ export function render(): void {// If no dark theme logo is uploaded but a light theme one// is, use the light theme one; this handles the common case// of transparent background logos that look good on both- // dark and light themes. See also similar code in admin.js.+ // dark and light themes. See also similar code in admin.ts.$("#realm-night-logo-upload-widget .image-block").attr("src", realm.realm_logo_url);} else {diff --git a/zerver/models/realms.py b/zerver/models/realms.pyindex fc2a2fc1ac8..097f0365f9d 100644--- a/zerver/models/realms.py+++ b/zerver/models/realms.py@@ -351,7 +351,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stubwaiting_period_threshold = models.PositiveIntegerField(default=0)DEFAULT_MESSAGE_CONTENT_DELETE_LIMIT_SECONDS = (- 600 # if changed, also change in admin.js, setting_org.js+ 600 # if changed, also change in admin.ts, settings_org.ts)MESSAGE_TIME_LIMIT_SETTING_SPECIAL_VALUES_MAP = {"unlimited": None,@@ -362,7 +362,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stuballow_message_editing = models.BooleanField(default=True)DEFAULT_MESSAGE_CONTENT_EDIT_LIMIT_SECONDS = (- 600 # if changed, also change in admin.js, setting_org.js+ 600 # if changed, also change in admin.ts, settings_org.ts)message_content_edit_limit_seconds = models.PositiveIntegerField(default=DEFAULT_MESSAGE_CONTENT_EDIT_LIMIT_SECONDS, null=True