admin: Convert module to TypeScript.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-11-27 15:27:47 -08:00
committed by Tim Abbott
parent ff99302dfe
commit 0048dfabd0
8 changed files with 43 additions and 35 deletions

View File

@@ -540,10 +540,10 @@ If you're adding a non-checkbox field, you'll need to specify the type
of the field via the `data-setting-widget-type` attribute in the HTML
template.
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.ts
export function build_page() {
const options = {

View File

@@ -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>` call
to 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)
```js
var url = "/json/realm";

View File

@@ -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",

View File

@@ -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();

View File

@@ -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";

View File

@@ -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;
}

View File

@@ -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 {

View File

@@ -351,7 +351,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
waiting_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-stub
allow_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