A platform for community discussion. Free, open, simple.
DEV: Convert admin dashboard, plugin, backup and screening models to TypeScript (#45208)
Sérgio Saquetim375bc3bec2a9
diff --git a/frontend/discourse/admin/models/admin-dashboard.js b/frontend/discourse/admin/models/admin-dashboard.jsdeleted file mode 100644index 9c95c8a141e..00000000000--- a/frontend/discourse/admin/models/admin-dashboard.js+++ /dev/null@@ -1,34 +0,0 @@-import EmberObject from "@ember/object";-import { ajax } from "discourse/lib/ajax";--export default class AdminDashboard extends EmberObject {- static async fetch({ startDate, endDate } = {}) {- const data = {};- if (startDate) {- data.start_date = moment(startDate).format("YYYY-MM-DD");- }- if (endDate) {- data.end_date = moment(endDate).format("YYYY-MM-DD");- }-- const json = await ajax("/admin/dashboard.json", { data });- const model = AdminDashboard.create();-- model.setProperties({- sections: json.sections,- configuration: json.configuration,- problems: json.problems,- });-- return model;- }-- static async fetchProblems() {- const json = await ajax("/admin/dashboard/problems.json", { type: "POST" });- const model = AdminDashboard.create(json);-- model.set("loaded", true);-- return model;- }-}diff --git a/frontend/discourse/admin/models/admin-dashboard.ts b/frontend/discourse/admin/models/admin-dashboard.tsnew file mode 100644index 00000000000..1264e011eb3--- /dev/null+++ b/frontend/discourse/admin/models/admin-dashboard.ts@@ -0,0 +1,71 @@+import EmberObject from "@ember/object";+import { ajax } from "discourse/lib/ajax";++/** A dashboard section; plugin loaders supply arbitrary `data`, and a failed section sends `error`. */+export interface AdminDashboardSection {+ id: string;+ data?: unknown;+ error?: boolean;+}++export interface AdminDashboardProblem {+ id: number;+ priority: "low" | "high";+ message: string;+ identifier: string;+}++/** Each loader populates a different subset. */+export interface AdminDashboardFields {+ sections?: AdminDashboardSection[];+ configuration?: { sections: { id: string; visible: boolean }[] };+ problems?: AdminDashboardProblem[];+ loaded?: boolean;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface AdminDashboard extends AdminDashboardFields {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class AdminDashboard extends EmberObject {+ static async fetch({+ startDate,+ endDate,+ }: { startDate?: Date; endDate?: Date } = {}): Promise<AdminDashboard> {+ const data: { start_date?: string; end_date?: string } = {};+ if (startDate) {+ data.start_date = moment(startDate).format("YYYY-MM-DD");+ }+ if (endDate) {+ data.end_date = moment(endDate).format("YYYY-MM-DD");+ }++ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.+ const json = (await ajax("/admin/dashboard.json", {+ data,+ })) as AdminDashboardFields;+ const model = AdminDashboard.create();++ model.setProperties({+ sections: json.sections,+ configuration: json.configuration,+ problems: json.problems,+ });++ return model;+ }++ static async fetchProblems(): Promise<AdminDashboard> {+ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.+ const json = (await ajax("/admin/dashboard/problems.json", {+ type: "POST",+ })) as { problems: AdminDashboardProblem[] };+ const model = AdminDashboard.create(json);++ model.set("loaded", true);++ return model;+ }+}++declare const moment: typeof import("moment");diff --git a/frontend/discourse/admin/models/admin-plugin.js b/frontend/discourse/admin/models/admin-plugin.jsdeleted file mode 100644index 4be7fb8a1d6..00000000000--- a/frontend/discourse/admin/models/admin-plugin.js+++ /dev/null@@ -1,75 +0,0 @@-import { cached, tracked } from "@glimmer/tracking";-import { dasherize } from "@ember/string";-import { snakeCaseToCamelCase } from "discourse/lib/case-converter";-import { stripDiscoursePrefix } from "discourse/lib/utilities";-import I18n, { i18n } from "discourse-i18n";--export default class AdminPlugin {- static create(args = {}) {- return new AdminPlugin(args);- }-- @tracked enabled;-- constructor(args = {}) {- Object.keys(args).forEach((key) => {- this[snakeCaseToCamelCase(key)] = args[key];- });- }-- get useNewShowRoute() {- return this.adminRoute?.use_new_show_route;- }-- get snakeCaseName() {- return this.name.replaceAll("-", "_");- }-- get dasherizedName() {- return dasherize(this.name);- }-- get translatedCategoryName() {- // We do this because the site setting list is grouped by category,- // with plugins that have their root site setting key defined as `plugins:`- // being grouped under the generic "plugins" category.- //- // If a site setting has defined a proper root key and translated category name,- // we can use that instead to go directly to the setting category.- //- // Over time, no plugins should be missing this data.- return I18n.lookup(`admin.site_settings.categories.${this.snakeCaseName}`);- }-- get settingCategoryName() {- if (this.translatedCategoryName) {- return this.snakeCaseName;- }-- return "plugins";- }-- @cached- get nameTitleized() {- return stripDiscoursePrefix(- this.translatedCategoryName || this.humanizedName- );- }-- @cached- get nameTitleizedLower() {- return this.nameTitleized.toLowerCase();- }-- get author() {- if (this.isOfficial || this.isDiscourseOwned) {- return i18n("admin.plugins.author", { author: "Discourse" });- }-- return i18n("admin.plugins.author", { author: this.authors });- }-- get linkUrl() {- return this.metaUrl || this.url;- }-}diff --git a/frontend/discourse/admin/models/admin-plugin.ts b/frontend/discourse/admin/models/admin-plugin.tsnew file mode 100644index 00000000000..d04bb266cd9--- /dev/null+++ b/frontend/discourse/admin/models/admin-plugin.ts@@ -0,0 +1,149 @@+import { cached, tracked } from "@glimmer/tracking";+import { dasherize } from "@ember/string";+import { snakeCaseToCamelCase } from "discourse/lib/case-converter";+import { stripDiscoursePrefix } from "discourse/lib/utilities";+import I18n, { i18n } from "discourse-i18n";++export interface AdminPluginRoute {+ location: string;+ label: string;+ use_new_show_route: boolean;+ auto_generated?: boolean;+ full_location: string;+ plugin_id?: string;+}++/**+ * `/admin/plugins` record; metadata is null when the plugin does not declare it.+ * Blank `url`, `admin_route` and `enabled_setting` are omitted, and `label` is+ * sent only for Discourse-owned plugins.+ */+export interface AdminPluginPayload {+ id: string;+ name: string;+ about: string | null;+ version: string | null;+ url?: string;+ admin_route?: AdminPluginRoute | null;+ enabled: boolean;+ enabled_setting?: string;+ has_settings: boolean;+ has_only_enabled_setting: boolean;+ humanized_name: string;+ is_official: boolean;+ is_discourse_owned: boolean;+ label?: string | null;+ commit_hash: string | null;+ commit_url: string | null;+ meta_url: string | null;+ authors: string | null;+ /** Plugin-owned data, sent only when a plugin registers some. */+ extras?: Record<string, unknown>;+}++/** The constructor copies each key, camelCased; client-built records can be sparse. */+export interface AdminPluginFields {+ id: string;+ name: string;+ about?: string | null;+ version?: string | null;+ url?: string;+ adminRoute?: AdminPluginRoute | null;+ enabledSetting?: string;+ hasSettings?: boolean;+ hasOnlyEnabledSetting?: boolean;+ humanizedName?: string;+ isOfficial?: boolean;+ isDiscourseOwned?: boolean;+ label?: string | null;+ commitHash?: string | null;+ commitUrl?: string | null;+ metaUrl?: string | null;+ authors?: string | null;+ extras?: Record<string, unknown>;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface AdminPlugin extends AdminPluginFields {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class AdminPlugin {+ static create(args: Partial<AdminPluginPayload> = {}): AdminPlugin {+ return new AdminPlugin(args);+ }++ @tracked enabled: boolean | undefined;++ constructor(args: Partial<AdminPluginPayload> = {}) {+ Object.keys(args).forEach((key) => {+ (this as unknown as Record<string, unknown>)[snakeCaseToCamelCase(key)] =+ args[key as keyof AdminPluginPayload];+ });+ }++ get useNewShowRoute(): boolean | undefined {+ return this.adminRoute?.use_new_show_route;+ }++ get snakeCaseName(): string {+ return this.name.replaceAll("-", "_");+ }++ get dasherizedName(): string {+ return dasherize(this.name);+ }++ get translatedCategoryName(): string | undefined {+ // We do this because the site setting list is grouped by category,+ // with plugins that have their root site setting key defined as `plugins:`+ // being grouped under the generic "plugins" category.+ //+ // If a site setting has defined a proper root key and translated category name,+ // we can use that instead to go directly to the setting category.+ //+ // Over time, no plugins should be missing this data.+ return I18n.lookup(`admin.site_settings.categories.${this.snakeCaseName}`);+ }++ get settingCategoryName(): string {+ if (this.translatedCategoryName) {+ return this.snakeCaseName;+ }++ return "plugins";+ }++ @cached+ get nameTitleized(): string {+ return stripDiscoursePrefix(+ this.translatedCategoryName || this.humanizedName+ );+ }++ @cached+ get nameTitleizedLower(): string {+ return this.nameTitleized.toLowerCase();+ }++ get author(): string {+ if (this.isOfficial || this.isDiscourseOwned) {+ return i18n("admin.plugins.author", { author: "Discourse" });+ }++ return i18n("admin.plugins.author", { author: this.authors });+ }++ get linkUrl(): string | undefined {+ return this.metaUrl || this.url;+ }+}++declare module "discourse/services/store" {+ interface ModelRegistry {+ "admin-plugin": AdminPlugin;+ }++ interface ModelCreateAttrsRegistry {+ "admin-plugin": Partial<AdminPluginPayload>;+ }+}diff --git a/frontend/discourse/admin/models/backup-status.js b/frontend/discourse/admin/models/backup-status.jsdeleted file mode 100644index 51581de41ee..00000000000--- a/frontend/discourse/admin/models/backup-status.js+++ /dev/null@@ -1,13 +0,0 @@-import EmberObject, { computed } from "@ember/object";--export default class BackupStatus extends EmberObject {- @computed("restoreEnabled")- get restoreDisabled() {- return !this.restoreEnabled;- }-- @computed("allowRestore", "isOperationRunning")- get restoreEnabled() {- return this.allowRestore && !this.isOperationRunning;- }-}diff --git a/frontend/discourse/admin/models/backup-status.ts b/frontend/discourse/admin/models/backup-status.tsnew file mode 100644index 00000000000..73a9199b4b5--- /dev/null+++ b/frontend/discourse/admin/models/backup-status.ts@@ -0,0 +1,24 @@+import EmberObject, { computed } from "@ember/object";++/** Built from the backup operations status, camelCased by the backups route. */+export interface BackupStatusFields {+ isOperationRunning: boolean;+ canRollback: boolean;+ allowRestore: boolean;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface BackupStatus extends BackupStatusFields {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class BackupStatus extends EmberObject {+ @computed("restoreEnabled")+ get restoreDisabled(): boolean {+ return !this.restoreEnabled;+ }++ @computed("allowRestore", "isOperationRunning")+ get restoreEnabled(): boolean {+ return this.allowRestore && !this.isOperationRunning;+ }+}diff --git a/frontend/discourse/admin/models/backup.js b/frontend/discourse/admin/models/backup.jsdeleted file mode 100644index a624b7fa427..00000000000--- a/frontend/discourse/admin/models/backup.js+++ /dev/null@@ -1,44 +0,0 @@-import EmberObject from "@ember/object";-import { ajax } from "discourse/lib/ajax";--export default class Backup extends EmberObject {- static find() {- return ajax("/admin/backups.json");- }-- static start(withUploads) {- if (withUploads === undefined) {- withUploads = true;- }- return ajax("/admin/backups", {- type: "POST",- data: {- with_uploads: withUploads,- client_id: window.MessageBus.clientId,- },- });- }-- static cancel() {- return ajax("/admin/backups/cancel.json", {- type: "DELETE",- });- }-- static rollback() {- return ajax("/admin/backups/rollback.json", {- type: "POST",- });- }-- destroy() {- return ajax("/admin/backups/" + this.filename, { type: "DELETE" });- }-- restore() {- return ajax("/admin/backups/" + this.filename + "/restore", {- type: "POST",- data: { client_id: window.MessageBus.clientId },- });- }-}diff --git a/frontend/discourse/admin/models/backup.ts b/frontend/discourse/admin/models/backup.tsnew file mode 100644index 00000000000..cf227c38c91--- /dev/null+++ b/frontend/discourse/admin/models/backup.ts@@ -0,0 +1,72 @@+import EmberObject from "@ember/object";+import { ajax } from "discourse/lib/ajax";++type MessageBusWindow = { MessageBus: { clientId: string } };++/** `/admin/backups` record. */+export interface BackupFields {+ filename: string;+ size: number;+ last_modified: string;+}++/** Operation endpoints answer `success_json`; failures reject. */+export interface BackupOperationResult {+ success?: string;+ failed?: string;+ message?: string;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface Backup extends BackupFields {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class Backup extends EmberObject {+ /** Resolves the plain records, not model instances. */+ static find(): Promise<BackupFields[]> {+ return ajax("/admin/backups.json");+ }++ static start(withUploads?: boolean): Promise<BackupOperationResult> {+ if (withUploads === undefined) {+ withUploads = true;+ }+ return ajax("/admin/backups", {+ type: "POST",+ data: {+ with_uploads: withUploads,+ // TODO(typescript-pending): the MessageBus global is untyped; remove this assertion when it is typed.+ client_id: (window as unknown as MessageBusWindow).MessageBus.clientId,+ },+ });+ }++ static cancel(): Promise<BackupOperationResult> {+ return ajax("/admin/backups/cancel.json", {+ type: "DELETE",+ });+ }++ static rollback(): Promise<BackupOperationResult> {+ return ajax("/admin/backups/rollback.json", {+ type: "POST",+ });+ }++ /** Deletes the backup file on the server, unlike EmberObject's `destroy`. */+ destroy(this: never): never;+ destroy(): Promise<unknown>;+ destroy(): Promise<unknown> {+ return ajax("/admin/backups/" + this.filename, { type: "DELETE" });+ }++ restore(): Promise<BackupOperationResult> {+ return ajax("/admin/backups/" + this.filename + "/restore", {+ type: "POST",+ // TODO(typescript-pending): the MessageBus global is untyped; remove this assertion when it is typed.+ data: {+ client_id: (window as unknown as MessageBusWindow).MessageBus.clientId,+ },+ });+ }+}diff --git a/frontend/discourse/admin/models/screened-email.js b/frontend/discourse/admin/models/screened-email.jsdeleted file mode 100644index 56622c3e284..00000000000--- a/frontend/discourse/admin/models/screened-email.js+++ /dev/null@@ -1,26 +0,0 @@-import EmberObject, { computed } from "@ember/object";-import { ajax } from "discourse/lib/ajax";-import { i18n } from "discourse-i18n";--export default class ScreenedEmail extends EmberObject {- static findAll() {- return ajax("/admin/logs/screened_emails.json").then(- function (screened_emails) {- return screened_emails.map(function (b) {- return ScreenedEmail.create(b);- });- }- );- }-- @computed("action")- get actionName() {- return i18n("admin.logs.screened_actions." + this.action);- }-- clearBlock() {- return ajax("/admin/logs/screened_emails/" + this.id, {- type: "DELETE",- });- }-}diff --git a/frontend/discourse/admin/models/screened-email.ts b/frontend/discourse/admin/models/screened-email.tsnew file mode 100644index 00000000000..4dc7d64cc76--- /dev/null+++ b/frontend/discourse/admin/models/screened-email.ts@@ -0,0 +1,43 @@+import EmberObject, { computed } from "@ember/object";+import { ajax } from "discourse/lib/ajax";+import { i18n } from "discourse-i18n";++export type ScreeningAction = "block" | "do_nothing" | "allow_admin";++/** `/admin/logs/screened_emails` record; `ip_address` is sent only to viewers who may see IPs. */+export interface ScreenedEmailFields {+ id: number;+ email: string;+ action: ScreeningAction;+ match_count: number;+ last_match_at: string | null;+ created_at: string;+ ip_address?: string | null;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface ScreenedEmail extends ScreenedEmailFields {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class ScreenedEmail extends EmberObject {+ static findAll(): Promise<ScreenedEmail[]> {+ return ajax("/admin/logs/screened_emails.json").then(function (+ screened_emails: ScreenedEmailFields[]+ ) {+ return screened_emails.map(function (b) {+ return ScreenedEmail.create(b);+ });+ });+ }++ @computed("action")+ get actionName(): string {+ return i18n("admin.logs.screened_actions." + this.action);+ }++ clearBlock(): Promise<{ success: string }> {+ return ajax("/admin/logs/screened_emails/" + this.id, {+ type: "DELETE",+ });+ }+}diff --git a/frontend/discourse/admin/models/screened-ip-address.js b/frontend/discourse/admin/models/screened-ip-address.jsdeleted file mode 100644index 33feae15fab..00000000000--- a/frontend/discourse/admin/models/screened-ip-address.js+++ /dev/null@@ -1,53 +0,0 @@-import { tracked } from "@glimmer/tracking";-import EmberObject, { computed } from "@ember/object";-import { dependentKeyCompat } from "@ember/object/compat";-import { ajax } from "discourse/lib/ajax";-import { i18n } from "discourse-i18n";--export default class ScreenedIpAddress extends EmberObject {- static findAll(filter) {- return ajax("/admin/logs/screened_ip_addresses.json", {- data: { filter },- }).then((screened_ips) =>- screened_ips.map((b) => ScreenedIpAddress.create(b))- );- }-- @tracked action_name;-- @dependentKeyCompat- get isBlocked() {- return this.action_name === "block";- }-- @computed("action_name")- get actionName() {- return i18n(`admin.logs.screened_ips.actions.${this.action_name}`);- }-- @computed("ip_address")- get isRange() {- return this.ip_address.indexOf("/") > 0;- }-- save() {- return ajax(- "/admin/logs/screened_ip_addresses" +- (this.id ? "/" + this.id : "") +- ".json",- {- type: this.id ? "PUT" : "POST",- data: {- ip_address: this.ip_address,- action_name: this.action_name,- },- }- );- }-- destroy() {- return ajax("/admin/logs/screened_ip_addresses/" + this.id + ".json", {- type: "DELETE",- });- }-}diff --git a/frontend/discourse/admin/models/screened-ip-address.ts b/frontend/discourse/admin/models/screened-ip-address.tsnew file mode 100644index 00000000000..0522459c8b5--- /dev/null+++ b/frontend/discourse/admin/models/screened-ip-address.ts@@ -0,0 +1,81 @@+import { tracked } from "@glimmer/tracking";+import EmberObject, { computed } from "@ember/object";+import { dependentKeyCompat } from "@ember/object/compat";+import type { ScreeningAction } from "discourse/admin/models/screened-email";+import { ajax } from "discourse/lib/ajax";+import { i18n } from "discourse-i18n";++/** `/admin/logs/screened_ip_addresses` record. */+export interface ScreenedIpAddressPayload {+ id: number;+ ip_address: string;+ action_name: ScreeningAction;+ match_count: number;+ last_match_at: string | null;+ created_at: string;+}++/** The add form builds records with only an address and action. */+export interface ScreenedIpAddressFields {+ id?: number;+ ip_address: string;+ match_count: number;+ last_match_at: string | null;+ created_at: string;+ editing?: boolean;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface ScreenedIpAddress extends ScreenedIpAddressFields {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class ScreenedIpAddress extends EmberObject {+ static findAll(filter?: string | null): Promise<ScreenedIpAddress[]> {+ return ajax("/admin/logs/screened_ip_addresses.json", {+ data: { filter },+ }).then((screened_ips: ScreenedIpAddressPayload[]) =>+ screened_ips.map((b) => ScreenedIpAddress.create(b))+ );+ }++ @tracked action_name!: ScreeningAction;++ @dependentKeyCompat+ get isBlocked(): boolean {+ return this.action_name === "block";+ }++ @computed("action_name")+ get actionName(): string {+ return i18n(`admin.logs.screened_ips.actions.${this.action_name}`);+ }++ @computed("ip_address")+ get isRange(): boolean {+ return this.ip_address.indexOf("/") > 0;+ }++ save(): Promise<{ screened_ip_address: ScreenedIpAddressPayload }> {+ return ajax(+ "/admin/logs/screened_ip_addresses" ++ (this.id ? "/" + this.id : "") ++ ".json",+ {+ type: this.id ? "PUT" : "POST",+ data: {+ ip_address: this.ip_address,+ action_name: this.action_name,+ },+ }+ );+ }++ /** Deletes the record on the server, unlike EmberObject's `destroy`. */+ destroy(this: never): never;+ destroy(): Promise<{ success: string }>;+ destroy(): Promise<{ success: string }> {+ return ajax("/admin/logs/screened_ip_addresses/" + this.id + ".json", {+ type: "DELETE",+ });+ }+}diff --git a/frontend/discourse/admin/models/screened-url.js b/frontend/discourse/admin/models/screened-url.jsdeleted file mode 100644index 64ce51b796c..00000000000--- a/frontend/discourse/admin/models/screened-url.js+++ /dev/null@@ -1,20 +0,0 @@-import EmberObject, { computed } from "@ember/object";-import { ajax } from "discourse/lib/ajax";-import { i18n } from "discourse-i18n";--export default class ScreenedUrl extends EmberObject {- static findAll() {- return ajax("/admin/logs/screened_urls.json").then(- function (screened_urls) {- return screened_urls.map(function (b) {- return ScreenedUrl.create(b);- });- }- );- }-- @computed("action")- get actionName() {- return i18n("admin.logs.screened_actions." + this.action);- }-}diff --git a/frontend/discourse/admin/models/screened-url.ts b/frontend/discourse/admin/models/screened-url.tsnew file mode 100644index 00000000000..f6124113e3e--- /dev/null+++ b/frontend/discourse/admin/models/screened-url.ts@@ -0,0 +1,33 @@+import EmberObject, { computed } from "@ember/object";+import { ajax } from "discourse/lib/ajax";+import { i18n } from "discourse-i18n";++/** `/admin/logs/screened_urls` row, grouped by domain; the grouped query always reports `do_nothing`. */+export interface ScreenedUrlFields {+ domain: string;+ action: "do_nothing";+ match_count: number;+ last_match_at: string | null;+ created_at: string;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface ScreenedUrl extends ScreenedUrlFields {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class ScreenedUrl extends EmberObject {+ static findAll(): Promise<ScreenedUrl[]> {+ return ajax("/admin/logs/screened_urls.json").then(function (+ screened_urls: ScreenedUrlFields[]+ ) {+ return screened_urls.map(function (b) {+ return ScreenedUrl.create(b);+ });+ });+ }++ @computed("action")+ get actionName(): string {+ return i18n("admin.logs.screened_actions." + this.action);+ }+}diff --git a/frontend/discourse/admin/models/user-export.js b/frontend/discourse/admin/models/user-export.jsdeleted file mode 100644index 57782e6b326..00000000000--- a/frontend/discourse/admin/models/user-export.js+++ /dev/null@@ -1,13 +0,0 @@-import { ajax } from "discourse/lib/ajax";-import RestModel from "discourse/models/rest";--export default class UserExport extends RestModel {- static async findLatest(user_id) {- const result = await ajax(- `/export_csv/latest_user_archive/${user_id}.json`- );- if (result !== null) {- return UserExport.create(result.user_export);- }- }-}diff --git a/frontend/discourse/admin/models/user-export.ts b/frontend/discourse/admin/models/user-export.tsnew file mode 100644index 00000000000..49d5645a6eb--- /dev/null+++ b/frontend/discourse/admin/models/user-export.ts@@ -0,0 +1,31 @@+import { ajax } from "discourse/lib/ajax";+import RestModel, { type RestPayload } from "discourse/models/rest";++/** Latest user archive; the serializer sends an empty record until the upload is attached. */+export interface UserExportFields {+ id?: number;+ filename?: string;+ uri?: string;+ filesize?: number;+ extension?: string | null;+ retain_hours?: number;+ human_filesize?: string;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface UserExport extends UserExportFields {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class UserExport extends RestModel {+ static async findLatest(+ user_id: number | string+ ): Promise<UserExport | undefined> {+ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.+ const result = (await ajax(+ `/export_csv/latest_user_archive/${user_id}.json`+ )) as { user_export: UserExportFields & RestPayload } | null;+ if (result !== null) {+ return UserExport.create(result.user_export);+ }+ }+}diff --git a/frontend/discourse/admin/models/version-check.js b/frontend/discourse/admin/models/version-check.jsdeleted file mode 100644index b4e66633ad4..00000000000--- a/frontend/discourse/admin/models/version-check.js+++ /dev/null@@ -1,83 +0,0 @@-import { ajax } from "discourse/lib/ajax";--export default class VersionCheck {- static async find() {- return new VersionCheck(await ajax("/admin/version_check"));- }-- constructor(json = {}) {- Object.assign(this, json);- }-- get noCheckPerformed() {- return this.updated_at === null;- }-- get upToDate() {- return (- this.missing_versions_count === 0 || this.missing_versions_count === null- );- }-- get behindByOneVersion() {- return this.missing_versions_count === 1;- }-- get gitLink() {- return commitLink(this.installed_sha);- }-- get shortSha() {- return truncateSha(this.installed_sha);- }-- get latestGitLink() {- return commitLink(this.latest_sha);- }-- get latestShortSha() {- return truncateSha(this.latest_sha);- }-- get changelogLink() {- if (this.installed_sha && this.latest_sha) {- const start = this.installed_sha.slice(0, 8);- const end = this.latest_sha.slice(0, 8);- return `https://releases.discourse.org/changelog/custom?start=${start}&end=${end}`;- }- }-- get installedCommitsAhead() {- return commitsAhead(this.installed_describe);- }-- get latestCommitsAhead() {- return commitsAhead(this.latest_pretty_version);- }-- get newerCommitsAvailable() {- return this.newChangesCount > 0;- }-- get newChangesCount() {- if (this.latestCommitsAhead === undefined) {- return 0;- }- return this.latestCommitsAhead - (this.installedCommitsAhead ?? 0);- }-}--function commitLink(sha) {- if (sha) {- return `https://github.com/discourse/discourse/commits/${sha}`;- }-}--function truncateSha(sha) {- return sha?.slice(0, 10);-}--function commitsAhead(prettyVersion) {- const extra = prettyVersion?.split(" +")[1];- return extra ? parseInt(extra, 10) : undefined;-}diff --git a/frontend/discourse/admin/models/version-check.ts b/frontend/discourse/admin/models/version-check.tsnew file mode 100644index 00000000000..8e334fa858a--- /dev/null+++ b/frontend/discourse/admin/models/version-check.ts@@ -0,0 +1,107 @@+import { ajax } from "discourse/lib/ajax";++/** `/admin/version_check` record; the dashboard's copy can omit the latest-version fields. */+export interface VersionCheckPayload {+ installed_version: string;+ installed_sha: string | null;+ installed_describe: string;+ git_branch?: string;+ latest_version?: string | null;+ latest_pretty_version?: string | null;+ latest_sha?: string | null;+ missing_versions_count?: number | null;+ updated_at: string | null;+ version_check_pending?: boolean;+ stale_data?: boolean;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface VersionCheck extends VersionCheckPayload {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class VersionCheck {+ static async find(): Promise<VersionCheck> {+ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.+ return new VersionCheck(+ (await ajax("/admin/version_check")) as VersionCheckPayload+ );+ }++ constructor(json: VersionCheckPayload = {} as VersionCheckPayload) {+ Object.assign(this, json);+ }++ get noCheckPerformed(): boolean {+ return this.updated_at === null;+ }++ get upToDate(): boolean {+ return (+ this.missing_versions_count === 0 || this.missing_versions_count === null+ );+ }++ get behindByOneVersion(): boolean {+ return this.missing_versions_count === 1;+ }++ get gitLink(): string | undefined {+ return commitLink(this.installed_sha);+ }++ get shortSha(): string | undefined {+ return truncateSha(this.installed_sha);+ }++ get latestGitLink(): string | undefined {+ return commitLink(this.latest_sha);+ }++ get latestShortSha(): string | undefined {+ return truncateSha(this.latest_sha);+ }++ get changelogLink(): string | undefined {+ if (this.installed_sha && this.latest_sha) {+ const start = this.installed_sha.slice(0, 8);+ const end = this.latest_sha.slice(0, 8);+ return `https://releases.discourse.org/changelog/custom?start=${start}&end=${end}`;+ }+ }++ get installedCommitsAhead(): number | undefined {+ return commitsAhead(this.installed_describe);+ }++ get latestCommitsAhead(): number | undefined {+ return commitsAhead(this.latest_pretty_version);+ }++ get newerCommitsAvailable(): boolean {+ return this.newChangesCount > 0;+ }++ get newChangesCount(): number {+ if (this.latestCommitsAhead === undefined) {+ return 0;+ }+ return this.latestCommitsAhead - (this.installedCommitsAhead ?? 0);+ }+}++function commitLink(sha: string | null | undefined): string | undefined {+ if (sha) {+ return `https://github.com/discourse/discourse/commits/${sha}`;+ }+}++function truncateSha(sha: string | null | undefined): string | undefined {+ return sha?.slice(0, 10);+}++function commitsAhead(+ prettyVersion: string | null | undefined+): number | undefined {+ const extra = prettyVersion?.split(" +")[1];+ return extra ? parseInt(extra, 10) : undefined;+}diff --git a/frontend/discourse/admin/models/watched-word.js b/frontend/discourse/admin/models/watched-word.jsdeleted file mode 100644index 39c487853bb..00000000000--- a/frontend/discourse/admin/models/watched-word.js+++ /dev/null@@ -1,56 +0,0 @@-import EmberObject from "@ember/object";-import { trackedArray } from "@ember/reactive/collections";-import { ajax } from "discourse/lib/ajax";-import { i18n } from "discourse-i18n";--export default class WatchedWord extends EmberObject {- static async findAll() {- const list = await ajax("/admin/customize/watched_words.json");- const actions = {};-- list.actions.forEach((action) => {- actions[action] = [];- });-- list.words.forEach((watchedWord) => {- actions[watchedWord.action].push(WatchedWord.create(watchedWord));- });-- return Object.keys(actions).map((nameKey) => {- return EmberObject.create({- nameKey,- name: i18n("admin.watched_words.actions." + nameKey),- words: trackedArray(actions[nameKey]),- compiledRegularExpression: list.compiled_regular_expressions[nameKey],- });- });- }-- save() {- const data = {- words: this.words,- replacement: this.replacement,- action_key: this.action,- case_sensitive: this.isCaseSensitive,- html: this.isHtml,- replacement_tags: this.replacementTags,- };-- return ajax(- "/admin/customize/watched_words" +- (this.id ? "/" + this.id : "") +- ".json",- {- type: this.id ? "PUT" : "POST",- data,- dataType: "json",- }- );- }-- destroy() {- return ajax("/admin/customize/watched_words/" + this.id + ".json", {- type: "DELETE",- });- }-}diff --git a/frontend/discourse/admin/models/watched-word.ts b/frontend/discourse/admin/models/watched-word.tsnew file mode 100644index 00000000000..2bc160e28e5--- /dev/null+++ b/frontend/discourse/admin/models/watched-word.ts@@ -0,0 +1,122 @@+import EmberObject from "@ember/object";+import { trackedArray } from "@ember/reactive/collections";+import { ajax } from "discourse/lib/ajax";+import { i18n } from "discourse-i18n";++/** `tag` is listed only while tagging is enabled. */+export type WatchedWordAction =+ | "block"+ | "censor"+ | "require_approval"+ | "flag"+ | "link"+ | "replace"+ | "tag"+ | "silence";++/** Each entry maps one compiled pattern to its case sensitivity. */+export type WatchedWordRegularExpressions = Record<+ string,+ { case_sensitive: boolean }+>[];++/** `/admin/customize/watched_words` word; `replacement` and `html` are sent only when set. */+export interface WatchedWordPayload {+ id: number;+ word: string;+ regexp: string;+ replacement?: string | null;+ action: WatchedWordAction;+ case_sensitive: boolean;+ watched_word_group_id: number | null;+ html?: true;+}++/** The index and save responses. */+export interface WatchedWordListPayload {+ actions: WatchedWordAction[];+ words: WatchedWordPayload[];+ compiled_regular_expressions: Partial<+ Record<WatchedWordAction, WatchedWordRegularExpressions>+ >;+}++/** The add form builds unsaved records from camelCase form fields. */+export interface WatchedWordFields extends Omit<WatchedWordPayload, "id"> {+ id?: number;+ words?: string[];+ isCaseSensitive?: boolean;+ isHtml?: boolean;+ replacementTags?: { id?: number; name: string }[] | null;+}++/** One action's group, as `findAll` builds it. */+export interface WatchedWordGroup extends EmberObject {+ nameKey: WatchedWordAction;+ name: string;+ words: WatchedWord[];+ compiledRegularExpression: WatchedWordRegularExpressions;+}++// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging+export default interface WatchedWord extends WatchedWordFields {}++// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging+export default class WatchedWord extends EmberObject {+ static async findAll(): Promise<WatchedWordGroup[]> {+ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.+ const list = (await ajax(+ "/admin/customize/watched_words.json"+ )) as WatchedWordListPayload;+ const actions = {} as Record<WatchedWordAction, WatchedWord[]>;++ list.actions.forEach((action) => {+ actions[action] = [];+ });++ list.words.forEach((watchedWord) => {+ actions[watchedWord.action].push(WatchedWord.create(watchedWord));+ });++ return (Object.keys(actions) as WatchedWordAction[]).map((nameKey) => {+ // EmberObject.create's inferred keys exclude these group properties.+ return EmberObject.create({+ nameKey,+ name: i18n("admin.watched_words.actions." + nameKey),+ words: trackedArray(actions[nameKey]),+ compiledRegularExpression: list.compiled_regular_expressions[nameKey],+ } as object) as WatchedWordGroup;+ });+ }++ save(): Promise<WatchedWordListPayload> {+ const data = {+ words: this.words,+ replacement: this.replacement,+ action_key: this.action,+ case_sensitive: this.isCaseSensitive,+ html: this.isHtml,+ replacement_tags: this.replacementTags,+ };++ return ajax(+ "/admin/customize/watched_words" ++ (this.id ? "/" + this.id : "") ++ ".json",+ {+ type: this.id ? "PUT" : "POST",+ data,+ dataType: "json",+ }+ );+ }++ /** Deletes the word on the server, unlike EmberObject's `destroy`. */+ destroy(this: never): never;+ destroy(): Promise<{ success: string }>;+ destroy(): Promise<{ success: string }> {+ return ajax("/admin/customize/watched_words/" + this.id + ".json", {+ type: "DELETE",+ });+ }+}diff --git a/frontend/discourse/type-tests/models/admin-ops-test.ts b/frontend/discourse/type-tests/models/admin-ops-test.tsnew file mode 100644index 00000000000..a051a61fd8b--- /dev/null+++ b/frontend/discourse/type-tests/models/admin-ops-test.ts@@ -0,0 +1,587 @@+import type EmberObject from "@ember/object";+import { expectTypeOf } from "expect-type";+import AdminDashboard from "discourse/admin/models/admin-dashboard";+import AdminPlugin, {+ type AdminPluginPayload,+} from "discourse/admin/models/admin-plugin";+import Backup from "discourse/admin/models/backup";+import BackupStatus from "discourse/admin/models/backup-status";+import ScreenedEmail from "discourse/admin/models/screened-email";+import ScreenedIpAddress from "discourse/admin/models/screened-ip-address";+import ScreenedUrl from "discourse/admin/models/screened-url";+import UserExport from "discourse/admin/models/user-export";+import VersionCheck from "discourse/admin/models/version-check";+import WatchedWord from "discourse/admin/models/watched-word";+import type LegacyArrayLikeObject from "discourse/lib/legacy-array-like-object";+import type RestModel from "discourse/models/rest";+import type {+ default as StoreService,+ ModelFor,+} from "discourse/services/store";++type ScreeningAction = "block" | "do_nothing" | "allow_admin";+type WordAction =+ | "block"+ | "censor"+ | "require_approval"+ | "flag"+ | "link"+ | "replace"+ | "tag"+ | "silence";+type BackupFile = { filename: string; size: number; last_modified: string };+type OperationResult = {+ success?: string;+ failed?: string;+ message?: string;+};++declare const store: StoreService;++// The plugins index wraps raw `plugin` records in this separate model.+expectTypeOf<ModelFor<"admin-plugin">>().toEqualTypeOf<AdminPlugin>();+expectTypeOf(+ store.createRecord("admin-plugin", {+ id: "discourse-test-plugin",+ name: "discourse-test-plugin",+ admin_route: {+ location: "discourse-test-plugin",+ label: "admin.plugins.title",+ use_new_show_route: false,+ full_location: "admin",+ },+ has_settings: true,+ has_only_enabled_setting: false,+ })+).toEqualTypeOf<AdminPlugin>();++declare const dashboard: AdminDashboard;+expectTypeOf(dashboard).toExtend<EmberObject>();+expectTypeOf(dashboard).not.toExtend<RestModel>();+expectTypeOf(dashboard).not.toExtend<LegacyArrayLikeObject<unknown>>();+expectTypeOf(AdminDashboard.fetch()).resolves.toEqualTypeOf<AdminDashboard>();+AdminDashboard.fetch({+ startDate: new Date("2026-09-28"),+ endDate: new Date("2026-10-28"),+});+AdminDashboard.fetch({ startDate: new Date("2026-09-28") });+expectTypeOf(+ AdminDashboard.fetchProblems()+).resolves.toEqualTypeOf<AdminDashboard>();+// Fetch and problems populate different subsets of the same model.+expectTypeOf(dashboard.loaded).toEqualTypeOf<boolean | undefined>();+// The general tab and the version check in the index payload were removed with the old dashboard.+expectTypeOf(AdminDashboard).not.toHaveProperty("fetchGeneral");+expectTypeOf(dashboard).not.toHaveProperty("version_check");+expectTypeOf(dashboard.sections).toEqualTypeOf<+ { id: string; data?: unknown; error?: boolean }[] | undefined+>();+expectTypeOf(dashboard.configuration).toEqualTypeOf<+ { sections: { id: string; visible: boolean }[] } | undefined+>();+expectTypeOf(dashboard.problems).toEqualTypeOf<+ | {+ id: number;+ priority: "low" | "high";+ message: string;+ identifier: string;+ }[]+ | undefined+>();+AdminDashboard.create({+ sections: [+ { id: "highlights", data: { kpis: [{ value: null }] } },+ { id: "traffic", data: null, error: true },+ { id: "extension", data: { custom: [1, "two"] } },+ ],+ configuration: { sections: [{ id: "highlights", visible: true }] },+ problems: [],+});+AdminDashboard.create({+ problems: [+ { id: 55, priority: "low", message: "Test mode", identifier: "rails_env" },+ ],+});++declare const plugin: AdminPlugin;+expectTypeOf(plugin).not.toExtend<EmberObject>();+expectTypeOf(plugin).not.toExtend<RestModel>();+expectTypeOf(plugin).not.toExtend<LegacyArrayLikeObject<unknown>>();+expectTypeOf(AdminPlugin.create()).toEqualTypeOf<AdminPlugin>();+expectTypeOf(new AdminPlugin()).toEqualTypeOf<AdminPlugin>();+expectTypeOf(+ new AdminPlugin({ id: "discourse-test-plugin" })+).toEqualTypeOf<AdminPlugin>();+AdminPlugin.create({+ id: "discourse-adplugin",+ name: "discourse-adplugin",+ about: "Configure advertisements",+ version: "1.2.5",+ url: "https://github.com/discourse/discourse/tree/main/plugins/discourse-adplugin",+ admin_route: {+ location: "discourse-adplugin",+ label: "admin.adplugin.house_ads.title",+ use_new_show_route: true,+ auto_generated: false,+ full_location: "adminPlugins.show",+ },+ enabled: false,+ enabled_setting: "discourse_adplugin_enabled",+ has_settings: true,+ has_only_enabled_setting: false,+ humanized_name: "Ad Plugin",+ is_official: true,+ is_discourse_owned: true,+ label: null,+ commit_hash: "13d44d7b",+ commit_url: "https://github.com/discourse/discourse/commit/13d44d7b",+ meta_url: null,+ authors: null,+});+expectTypeOf(plugin.id).toEqualTypeOf<string>();+expectTypeOf(plugin.name).toEqualTypeOf<string>();+// Metadata can be absent on client-created records, or null on the wire.+expectTypeOf(plugin.about).toEqualTypeOf<string | null | undefined>();+expectTypeOf(plugin.version).toEqualTypeOf<string | null | undefined>();+expectTypeOf(plugin.authors).toEqualTypeOf<string | null | undefined>();+expectTypeOf(plugin.url).toEqualTypeOf<string | undefined>();+expectTypeOf(plugin.enabledSetting).toEqualTypeOf<string | undefined>();+expectTypeOf(plugin.humanizedName).toEqualTypeOf<string | undefined>();+expectTypeOf(plugin.enabled).toEqualTypeOf<boolean | undefined>();+expectTypeOf(plugin.hasSettings).toEqualTypeOf<boolean | undefined>();+expectTypeOf(plugin.hasOnlyEnabledSetting).toEqualTypeOf<boolean | undefined>();+expectTypeOf(plugin.isOfficial).toEqualTypeOf<boolean | undefined>();+expectTypeOf(plugin.isDiscourseOwned).toEqualTypeOf<boolean | undefined>();+expectTypeOf(plugin.label).toEqualTypeOf<string | null | undefined>();+expectTypeOf(plugin.commitHash).toEqualTypeOf<string | null | undefined>();+expectTypeOf(plugin.commitUrl).toEqualTypeOf<string | null | undefined>();+expectTypeOf(plugin.metaUrl).toEqualTypeOf<string | null | undefined>();+expectTypeOf(plugin.extras).toEqualTypeOf<+ Record<string, unknown> | undefined+>();+AdminPlugin.create({+ id: "discourse-test-plugin",+ name: "discourse-test-plugin",+ extras: {+ leaderboards: [],+ groups: [{ id: 1, name: "staff" }],+ scores_remaining: 1,+ },+});+expectTypeOf(plugin.adminRoute).toEqualTypeOf<+ | {+ location: string;+ label: string;+ use_new_show_route: boolean;+ auto_generated?: boolean;+ full_location: string;+ plugin_id?: string;+ }+ | null+ | undefined+>();+expectTypeOf(plugin.useNewShowRoute).toEqualTypeOf<boolean | undefined>();+expectTypeOf(plugin.snakeCaseName).toEqualTypeOf<string>();+expectTypeOf(plugin.dasherizedName).toEqualTypeOf<string>();+expectTypeOf(plugin.translatedCategoryName).toEqualTypeOf<string | undefined>();+expectTypeOf(plugin.settingCategoryName).toEqualTypeOf<string>();+expectTypeOf(plugin.nameTitleized).toEqualTypeOf<string>();+expectTypeOf(plugin.nameTitleizedLower).toEqualTypeOf<string>();+expectTypeOf(plugin.author).toEqualTypeOf<string>();+expectTypeOf(plugin.linkUrl).toEqualTypeOf<string | undefined>();+plugin.enabled = false;+plugin.hasSettings = false;+plugin.hasOnlyEnabledSetting = true;+plugin.adminRoute = null;++// Captured: the serializer omits a blank `url`; no plugin record carries `extras` here.+const localDates = {+ id: "discourse-local-dates",+ name: "discourse-local-dates",+ about: "Display a date in your local timezone",+ version: "0.1",+ admin_route: {+ location: "discourse-local-dates",+ label: "discourse_local_dates.title",+ use_new_show_route: true,+ auto_generated: true,+ full_location: "adminPlugins.show",+ },+ enabled: true,+ enabled_setting: "discourse_local_dates_enabled",+ has_settings: true,+ has_only_enabled_setting: false,+ humanized_name: "Local dates",+ is_official: true,+ is_discourse_owned: true,+ label: null,+ commit_hash: "13d44d7b11f30806e0c0b55bfd81abff60f32e95",+ commit_url:+ "https://github.com/discourse/discourse/commit/13d44d7b11f30806e0c0b55bfd81abff60f32e95",+ meta_url: null,+ authors: null,+};+expectTypeOf(localDates).toExtend<AdminPluginPayload>();++// Captured: a plugin with only its enabled setting has no admin route.+const checklist = {+ id: "checklist",+ name: "checklist",+ about: "Add checklist support to Discourse",+ version: "1.0",+ url: "https://github.com/discourse/discourse/tree/main/plugins/checklist",+ enabled: true,+ enabled_setting: "checklist_enabled",+ has_settings: true,+ has_only_enabled_setting: true,+ humanized_name: "Checklist",+ is_official: true,+ is_discourse_owned: true,+ label: null,+ commit_hash: "13d44d7b11f30806e0c0b55bfd81abff60f32e95",+ commit_url:+ "https://github.com/discourse/discourse/commit/13d44d7b11f30806e0c0b55bfd81abff60f32e95",+ meta_url: "https://meta.discourse.org/t/36362",+ authors: "Discourse Team",+};+expectTypeOf(checklist).toExtend<AdminPluginPayload>();++// A third-party plugin has no `label`, and one without a setting has no `enabled_setting`.+const thirdParty = {+ id: "my-plugin",+ name: "my-plugin",+ about: null,+ version: null,+ enabled: true,+ has_settings: false,+ has_only_enabled_setting: false,+ humanized_name: "My plugin",+ is_official: false,+ is_discourse_owned: false,+ commit_hash: null,+ commit_url: null,+ meta_url: null,+ authors: null,+};+expectTypeOf(thirdParty).toExtend<AdminPluginPayload>();++declare const backup: Backup;+// These legacy AJAX destroy methods override Ember's synchronous destroy.+expectTypeOf<Omit<Backup, "destroy">>().toExtend<+ Omit<EmberObject, "destroy">+>();+expectTypeOf(backup).not.toExtend<RestModel>();+expectTypeOf(backup).not.toExtend<LegacyArrayLikeObject<unknown>>();+expectTypeOf(Backup.find()).resolves.toEqualTypeOf<BackupFile[]>();+expectTypeOf(Backup.find()).resolves.not.toExtend<Backup[]>();+Backup.create({+ filename: "forum-2026-10-28-010000-v20261027000000.tar.gz",+ size: 12345,+ last_modified: "2026-10-28T01:00:00.000Z",+});+expectTypeOf(backup.filename).toEqualTypeOf<string>();+expectTypeOf(backup.size).toEqualTypeOf<number>();+expectTypeOf(backup.last_modified).toEqualTypeOf<string>();+expectTypeOf(Backup.start()).resolves.toEqualTypeOf<OperationResult>();+expectTypeOf(Backup.start(false)).resolves.toEqualTypeOf<OperationResult>();+Backup.start(true);+Backup.start(undefined);+expectTypeOf(Backup.cancel()).resolves.toEqualTypeOf<OperationResult>();+expectTypeOf(Backup.rollback()).resolves.toEqualTypeOf<OperationResult>();+expectTypeOf(backup.restore()).resolves.toEqualTypeOf<OperationResult>();+expectTypeOf(backup.destroy()).toExtend<Promise<unknown>>();+expectTypeOf(backup.destroy()).resolves.not.toBeAny();+// @ts-expect-error The uploads switch is a boolean, not a serialized form value.+Backup.start("false");++declare const status: BackupStatus;+expectTypeOf(status).toExtend<EmberObject>();+expectTypeOf(status).not.toExtend<RestModel>();+expectTypeOf(status).not.toExtend<LegacyArrayLikeObject<unknown>>();+BackupStatus.create({+ isOperationRunning: false,+ canRollback: false,+ allowRestore: false,+});+expectTypeOf(status.isOperationRunning).toEqualTypeOf<boolean>();+expectTypeOf(status.canRollback).toEqualTypeOf<boolean>();+expectTypeOf(status.allowRestore).toEqualTypeOf<boolean>();+expectTypeOf(status.restoreEnabled).toEqualTypeOf<boolean>();+expectTypeOf(status.restoreDisabled).toEqualTypeOf<boolean>();+status.set("isOperationRunning", true);++declare const email: ScreenedEmail;+expectTypeOf(email).toExtend<EmberObject>();+expectTypeOf(email).not.toExtend<RestModel>();+expectTypeOf(email).not.toExtend<LegacyArrayLikeObject<unknown>>();+expectTypeOf(ScreenedEmail.findAll()).resolves.toEqualTypeOf<ScreenedEmail[]>();+ScreenedEmail.create({+ id: 67,+ email: "[email protected]",+ action: "block",+ match_count: 0,+ last_match_at: null,+ created_at: "2026-10-28T01:04:05.393Z",+ ip_address: null,+});+expectTypeOf(email.id).toEqualTypeOf<number>();+expectTypeOf(email.email).toEqualTypeOf<string>();+expectTypeOf(email.action).toEqualTypeOf<ScreeningAction>();+expectTypeOf(email.match_count).toEqualTypeOf<number>();+expectTypeOf(email.last_match_at).toEqualTypeOf<string | null>();+expectTypeOf(email.created_at).toEqualTypeOf<string>();+expectTypeOf(email.ip_address).toEqualTypeOf<string | null | undefined>();+expectTypeOf(email.actionName).toEqualTypeOf<string>();+expectTypeOf(email.clearBlock()).resolves.toEqualTypeOf<{ success: string }>();++declare const ip: ScreenedIpAddress;+expectTypeOf<Omit<ScreenedIpAddress, "destroy">>().toExtend<+ Omit<EmberObject, "destroy">+>();+expectTypeOf(ip).not.toExtend<RestModel>();+expectTypeOf(ip).not.toExtend<LegacyArrayLikeObject<unknown>>();+expectTypeOf(ScreenedIpAddress.findAll(null)).resolves.toEqualTypeOf<+ ScreenedIpAddress[]+>();+ScreenedIpAddress.findAll("5.6.7.0/24");+ScreenedIpAddress.create({+ ip_address: "5.6.7.0/24",+ action_name: "allow_admin",+});+ScreenedIpAddress.create({+ id: 65,+ ip_address: "5.6.7.0/24",+ action_name: "allow_admin",+ match_count: 0,+ last_match_at: null,+ created_at: "2026-10-28T01:04:05.424Z",+});+expectTypeOf(ip.id).toEqualTypeOf<number | undefined>();+expectTypeOf(ip.ip_address).toEqualTypeOf<string>();+expectTypeOf(ip.action_name).toEqualTypeOf<ScreeningAction>();+expectTypeOf(ip.match_count).toEqualTypeOf<number>();+expectTypeOf(ip.last_match_at).toEqualTypeOf<string | null>();+expectTypeOf(ip.created_at).toEqualTypeOf<string>();+expectTypeOf(ip.editing).toEqualTypeOf<boolean | undefined>();+expectTypeOf(ip.isBlocked).toEqualTypeOf<boolean>();+expectTypeOf(ip.isRange).toEqualTypeOf<boolean>();+expectTypeOf(ip.actionName).toEqualTypeOf<string>();+ip.set("action_name", "do_nothing");+ip.action_name = "block";+ip.set("editing", true);+declare const savedIp: Awaited<ReturnType<ScreenedIpAddress["save"]>>;+expectTypeOf(savedIp).not.toBeAny();+expectTypeOf(savedIp.screened_ip_address.id).toEqualTypeOf<number>();+expectTypeOf(savedIp.screened_ip_address.ip_address).toEqualTypeOf<string>();+expectTypeOf(+ savedIp.screened_ip_address.action_name+).toEqualTypeOf<ScreeningAction>();+expectTypeOf(savedIp.screened_ip_address.match_count).toEqualTypeOf<number>();+expectTypeOf(savedIp.screened_ip_address.last_match_at).toEqualTypeOf<+ string | null+>();+expectTypeOf(savedIp.screened_ip_address.created_at).toEqualTypeOf<string>();+expectTypeOf(savedIp.screened_ip_address).not.toExtend<EmberObject>();+expectTypeOf(ip.save()).toExtend<Promise<typeof savedIp>>();+ScreenedIpAddress.create(savedIp.screened_ip_address);+expectTypeOf(ip.destroy()).resolves.toEqualTypeOf<{ success: string }>();+// @ts-expect-error The server rejects unknown screening actions.+ip.action_name = "allow_everyone";++declare const url: ScreenedUrl;+expectTypeOf(url).toExtend<EmberObject>();+expectTypeOf(url).not.toExtend<RestModel>();+expectTypeOf(url).not.toExtend<LegacyArrayLikeObject<unknown>>();+expectTypeOf(ScreenedUrl.findAll()).resolves.toEqualTypeOf<ScreenedUrl[]>();+// The index groups by domain; it does not send individual URL records or ids.+ScreenedUrl.create({+ domain: "spam.example.com",+ action: "do_nothing",+ match_count: 0,+ last_match_at: null,+ created_at: "2026-10-28T01:04:05.450Z",+});+expectTypeOf(url.domain).toEqualTypeOf<string>();+expectTypeOf(url.action).toEqualTypeOf<"do_nothing">();+expectTypeOf(url.match_count).toEqualTypeOf<number>();+expectTypeOf(url.last_match_at).toEqualTypeOf<string | null>();+expectTypeOf(url.created_at).toEqualTypeOf<string>();+expectTypeOf(url.actionName).toEqualTypeOf<string>();++declare const userExport: UserExport;+expectTypeOf(userExport).toExtend<RestModel>();+expectTypeOf(userExport).not.toExtend<LegacyArrayLikeObject<unknown>>();+expectTypeOf(UserExport.findLatest(1)).resolves.toEqualTypeOf<+ UserExport | undefined+>();+UserExport.findLatest("1");+// The serializer returns an empty object until the upload is attached.+UserExport.create({});+UserExport.create({+ id: 1,+ filename: "user-archive.zip",+ uri: "/uploads/short-url/archive.zip",+ filesize: 12345,+ extension: "zip",+ retain_hours: 47,+ human_filesize: "12.1 KB",+});+expectTypeOf(userExport.id).toEqualTypeOf<number | undefined>();+expectTypeOf(userExport.filename).toEqualTypeOf<string | undefined>();+expectTypeOf(userExport.uri).toEqualTypeOf<string | undefined>();+expectTypeOf(userExport.filesize).toEqualTypeOf<number | undefined>();+expectTypeOf(userExport.extension).toEqualTypeOf<string | null | undefined>();+expectTypeOf(userExport.retain_hours).toEqualTypeOf<number | undefined>();+expectTypeOf(userExport.human_filesize).toEqualTypeOf<string | undefined>();++declare const version: VersionCheck;+expectTypeOf(version).not.toExtend<EmberObject>();+expectTypeOf(version).not.toExtend<RestModel>();+expectTypeOf(version).not.toExtend<LegacyArrayLikeObject<unknown>>();+expectTypeOf(VersionCheck.find()).resolves.toEqualTypeOf<VersionCheck>();+expectTypeOf(new VersionCheck()).toEqualTypeOf<VersionCheck>();+expectTypeOf(+ new VersionCheck({+ installed_version: "2026.10.0-latest.1",+ installed_sha: "13d44d7b11f30806e0c0b55bfd81abff60f32e95",+ installed_describe: "v2026.10.0-latest.1 +6",+ git_branch: "main",+ updated_at: null,+ version_check_pending: true,+ stale_data: true,+ })+).toEqualTypeOf<VersionCheck>();+// The serializer emits null latest values; dashboard as_json can omit them.+expectTypeOf(+ new VersionCheck({+ installed_version: "2026.10.0-latest.1",+ installed_sha: null,+ installed_describe: "v2026.10.0-latest.1",+ latest_version: null,+ latest_pretty_version: null,+ latest_sha: null,+ missing_versions_count: null,+ updated_at: null,+ })+).toEqualTypeOf<VersionCheck>();+expectTypeOf(version.installed_version).toEqualTypeOf<string>();+expectTypeOf(version.installed_sha).toEqualTypeOf<string | null>();+expectTypeOf(version.installed_describe).toEqualTypeOf<string>();+expectTypeOf(version.git_branch).toEqualTypeOf<string | undefined>();+expectTypeOf(version.latest_version).toEqualTypeOf<string | null | undefined>();+expectTypeOf(version.latest_pretty_version).toEqualTypeOf<+ string | null | undefined+>();+expectTypeOf(version.latest_sha).toEqualTypeOf<string | null | undefined>();+expectTypeOf(version.missing_versions_count).toEqualTypeOf<+ number | null | undefined+>();+expectTypeOf(version.updated_at).toEqualTypeOf<string | null>();+expectTypeOf(version.version_check_pending).toEqualTypeOf<+ boolean | undefined+>();+expectTypeOf(version.stale_data).toEqualTypeOf<boolean | undefined>();+expectTypeOf(version.noCheckPerformed).toEqualTypeOf<boolean>();+expectTypeOf(version.upToDate).toEqualTypeOf<boolean>();+expectTypeOf(version.behindByOneVersion).toEqualTypeOf<boolean>();+expectTypeOf(version.gitLink).toEqualTypeOf<string | undefined>();+expectTypeOf(version.shortSha).toEqualTypeOf<string | undefined>();+expectTypeOf(version.latestGitLink).toEqualTypeOf<string | undefined>();+expectTypeOf(version.latestShortSha).toEqualTypeOf<string | undefined>();+expectTypeOf(version.changelogLink).toEqualTypeOf<string | undefined>();+expectTypeOf(version.installedCommitsAhead).toEqualTypeOf<number | undefined>();+expectTypeOf(version.latestCommitsAhead).toEqualTypeOf<number | undefined>();+expectTypeOf(version.newerCommitsAvailable).toEqualTypeOf<boolean>();+expectTypeOf(version.newChangesCount).toEqualTypeOf<number>();+// @ts-expect-error The abbreviated SHA is a getter, with no setter.+version.shortSha = "13d44d7b11";++declare const word: WatchedWord;+expectTypeOf<Omit<WatchedWord, "destroy">>().toExtend<+ Omit<EmberObject, "destroy">+>();+expectTypeOf(word).not.toExtend<RestModel>();+expectTypeOf(word).not.toExtend<LegacyArrayLikeObject<unknown>>();+WatchedWord.create({+ id: 1724,+ word: "bad",+ regexp: "(bad)",+ action: "block",+ case_sensitive: false,+ watched_word_group_id: null,+});+WatchedWord.create({+ id: 1725,+ word: "rep",+ regexp: "(rep)",+ replacement: "good",+ action: "replace",+ case_sensitive: false,+ watched_word_group_id: 10,+ html: true,+});+// Form-only camelCase fields are sent under different wire keys by save().+WatchedWord.create({+ words: ["first", "second"],+ replacement: null,+ replacementTags: [{ id: 1, name: "existing" }, { name: "new-tag" }],+ action: "tag",+ isCaseSensitive: false,+ isHtml: false,+}).save();+WatchedWord.create({+ words: ["replace"],+ replacement: "<b>replacement</b>",+ replacementTags: null,+ action: "replace",+ isCaseSensitive: true,+ isHtml: true,+});+expectTypeOf(word.id).toEqualTypeOf<number | undefined>();+expectTypeOf(word.word).toEqualTypeOf<string>();+expectTypeOf(word.regexp).toEqualTypeOf<string>();+expectTypeOf(word.action).toEqualTypeOf<WordAction>();+expectTypeOf(word.case_sensitive).toEqualTypeOf<boolean>();+expectTypeOf(word.watched_word_group_id).toEqualTypeOf<number | null>();+expectTypeOf(word.replacement).toEqualTypeOf<string | null | undefined>();+expectTypeOf(word.html).toEqualTypeOf<true | undefined>();+expectTypeOf(word.words).toEqualTypeOf<string[] | undefined>();+expectTypeOf(word.isCaseSensitive).toEqualTypeOf<boolean | undefined>();+expectTypeOf(word.isHtml).toEqualTypeOf<boolean | undefined>();+expectTypeOf(word.replacementTags).toEqualTypeOf<+ { id?: number; name: string }[] | null | undefined+>();+declare const groups: Awaited<ReturnType<typeof WatchedWord.findAll>>;+expectTypeOf(WatchedWord.findAll()).toExtend<Promise<typeof groups>>();+expectTypeOf(groups).not.toBeAny();+expectTypeOf(groups).toExtend<EmberObject[]>();+expectTypeOf(groups).not.toExtend<LegacyArrayLikeObject<unknown>>();+expectTypeOf(groups[0].nameKey).toEqualTypeOf<WordAction>();+expectTypeOf(groups[0].name).toEqualTypeOf<string>();+expectTypeOf(groups[0].words).toEqualTypeOf<WatchedWord[]>();+groups[0].words.push(word);+expectTypeOf(groups[0].compiledRegularExpression).toEqualTypeOf<+ Record<string, { case_sensitive: boolean }>[]+>();+declare const savedWords: Awaited<ReturnType<WatchedWord["save"]>>;+expectTypeOf(word.save()).toExtend<Promise<typeof savedWords>>();+expectTypeOf(savedWords).not.toBeAny();+expectTypeOf(savedWords.actions).toEqualTypeOf<WordAction[]>();+expectTypeOf(savedWords.compiled_regular_expressions).toEqualTypeOf<+ Partial<Record<WordAction, Record<string, { case_sensitive: boolean }>[]>>+>();+expectTypeOf(savedWords.words[0]).not.toExtend<EmberObject>();+expectTypeOf(savedWords.words[0].id).toEqualTypeOf<number>();+expectTypeOf(savedWords.words[0].word).toEqualTypeOf<string>();+expectTypeOf(savedWords.words[0].regexp).toEqualTypeOf<string>();+expectTypeOf(savedWords.words[0].replacement).toEqualTypeOf<+ string | null | undefined+>();+expectTypeOf(savedWords.words[0].action).toEqualTypeOf<WordAction>();+expectTypeOf(savedWords.words[0].case_sensitive).toEqualTypeOf<boolean>();+expectTypeOf(savedWords.words[0].watched_word_group_id).toEqualTypeOf<+ number | null+>();+expectTypeOf(savedWords.words[0].html).toEqualTypeOf<true | undefined>();+WatchedWord.create(savedWords.words[0]);+expectTypeOf(word.destroy()).resolves.toEqualTypeOf<{ success: string }>();